Mercurial > vim
annotate src/ex_getln.c @ 17411:9c4ddc78df74 v8.1.1704
patch 8.1.1704: C-R C-W does not work after C-G when using 'incsearch'
commit https://github.com/vim/vim/commit/69a5b867940d25f68a782de5c1165d65b51fcafa
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jul 16 21:38:51 2019 +0200
patch 8.1.1704: C-R C-W does not work after C-G when using 'incsearch'
Problem: C-R C-W does not work after C-G when using 'incsearch'.
Solution: Put cursor at end of the match. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/4664)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 16 Jul 2019 21:45:05 +0200 |
parents | 81705f4d9e03 |
children | e43f0c0c491c |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
14548
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
16 #ifndef MAX |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
17 # define MAX(x,y) ((x) > (y) ? (x) : (y)) |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
18 #endif |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
19 |
7 | 20 /* |
21 * Variables shared between getcmdline(), redrawcmdline() and others. | |
22 * These need to be saved when using CTRL-R |, that's why they are in a | |
23 * structure. | |
24 */ | |
25 struct cmdline_info | |
26 { | |
27 char_u *cmdbuff; /* pointer to command line buffer */ | |
28 int cmdbufflen; /* length of cmdbuff */ | |
29 int cmdlen; /* number of chars in command line */ | |
30 int cmdpos; /* current cursor position */ | |
31 int cmdspos; /* cursor column on screen */ | |
3503 | 32 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 33 int cmdindent; /* number of spaces before cmdline */ |
34 char_u *cmdprompt; /* message in front of cmdline */ | |
35 int cmdattr; /* attributes for prompt */ | |
36 int overstrike; /* Typing mode on the command line. Shared by | |
37 getcmdline() and put_on_cmdline(). */ | |
1718 | 38 expand_T *xpc; /* struct being used for expansion, xp_pattern |
39 may point into cmdbuff */ | |
531 | 40 int xp_context; /* type of expansion */ |
41 # ifdef FEAT_EVAL | |
42 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 43 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 44 # endif |
7 | 45 }; |
46 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
47 // The current cmdline_info. It is initialized in getcmdline() and after that |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
48 // used by other functions. When invoking getcmdline() recursively it needs |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
49 // to be saved with save_cmdline() and restored with restore_cmdline(). |
1718 | 50 static struct cmdline_info ccline; |
7 | 51 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
52 static int cmd_showtail; /* Only show path tail in lists ? */ |
7 | 53 |
54 #ifdef FEAT_EVAL | |
55 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
56 #endif | |
57 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
58 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
59 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
60 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
61 |
7 | 62 #ifdef FEAT_CMDHIST |
63 typedef struct hist_entry | |
64 { | |
65 int hisnum; /* identifying number */ | |
4258 | 66 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 67 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
68 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 69 } histentry_T; |
70 | |
71 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
72 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
73 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
74 /* identifying (unique) number of newest history entry */ | |
75 static int hislen = 0; /* actual length of history tables */ | |
76 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
77 static int hist_char2type(int c); |
7 | 78 #endif |
79 | |
80 #ifdef FEAT_RIGHTLEFT | |
81 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
82 #endif | |
83 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
84 static char_u *getcmdline_int(int firstc, long count, int indent, int init_ccline); |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
85 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
86 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
87 static void set_cmdspos_cursor(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
88 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
|
89 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
90 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 95 #ifdef FEAT_WILDMENU |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
97 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 static int expand_showtail(expand_T *xp); |
7 | 107 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
108 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
|
109 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
|
110 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 111 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 113 # endif |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16287
diff
changeset
|
114 # if defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 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
|
116 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 117 # endif |
118 #endif | |
4265 | 119 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
120 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 121 #endif |
7 | 122 |
123 #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
|
124 static int open_cmdwin(void); |
7 | 125 #endif |
126 | |
3164 | 127 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
16606
7e733046db1d
patch 8.1.1306: Borland support is outdated and doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
16411
diff
changeset
|
128 static int sort_func_compare(const void *s1, const void *s2); |
3164 | 129 #endif |
130 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
131 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
132 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
|
133 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
|
134 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
135 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
|
136 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
141 |
7 | 142 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
143 * 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
|
144 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
145 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
|
146 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
|
147 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
148 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
|
149 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
|
150 compute_cmdrow(); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
151 msg(""); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
152 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
|
153 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
154 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
155 #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
|
156 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
157 * 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
|
158 * 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
|
159 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
160 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
161 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
|
162 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
163 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
|
164 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
165 /* 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
|
166 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
|
167 && 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
|
168 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
169 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
|
170 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
171 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
172 // 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
|
173 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
178 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
179 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
180 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
|
181 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
|
182 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
183 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
184 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
185 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
|
186 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 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
|
192 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 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
|
194 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
|
195 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 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
|
199 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 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
|
205 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 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
|
207 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
|
208 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
209 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
210 // 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
|
211 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
219 int incsearch_postponed; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
220 int magic_save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
221 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
222 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
223 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
224 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
|
225 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
226 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
|
227 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
|
228 is_state->incsearch_postponed = FALSE; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
229 is_state->magic_save = p_magic; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
238 * 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
|
239 * 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
|
240 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 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
|
243 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 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
|
249 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
|
250 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 } |
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 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 * 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
|
255 * Sets search_first_line and search_last_line to the address range. |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
256 * May change the last search pattern. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 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
|
259 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
|
260 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
|
261 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
262 char_u *cmd; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
263 cmdmod_T save_cmdmod = cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
264 char_u *p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
265 int delim_optional = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
266 int delim; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
267 char_u *end; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
268 char *dummy; |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
269 exarg_T ea; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
270 pos_T save_cursor; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
271 int use_last_pat; |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
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 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
276 if (!p_is || cmd_silent) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
277 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
278 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
279 // by default search all lines |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
280 search_first_line = 0; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
281 search_last_line = MAXLNUM; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
282 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
283 if (firstc == '/' || firstc == '?') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
284 return TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
285 if (firstc != ':') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
286 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
287 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
288 vim_memset(&ea, 0, sizeof(ea)); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
289 ea.line1 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
290 ea.line2 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
291 ea.cmd = ccline.cmdbuff; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
292 ea.addr_type = ADDR_LINES; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
293 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
294 parse_command_modifiers(&ea, &dummy, TRUE); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
295 cmdmod = save_cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
296 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
297 cmd = skip_range(ea.cmd, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
298 if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
299 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
300 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
301 // Skip over "substitute" to find the pattern separator. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
302 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
303 ; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
304 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
305 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
306 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
307 if (STRNCMP(cmd, "substitute", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
308 || STRNCMP(cmd, "smagic", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
309 || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
310 || STRNCMP(cmd, "vglobal", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
311 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
312 if (*cmd == 's' && cmd[1] == 'm') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
313 p_magic = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
314 else if (*cmd == 's' && cmd[1] == 'n') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
315 p_magic = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
316 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
317 else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
318 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
319 // skip over flags |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
320 while (ASCII_ISALPHA(*(p = skipwhite(p)))) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
321 ++p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
322 if (*p == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
323 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
324 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
325 else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
326 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
327 || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
328 || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
329 || STRNCMP(cmd, "global", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
330 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
331 // skip over "!" |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
332 if (*p == '!') |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
333 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
334 p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
335 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
336 return FALSE; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
337 } |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
338 if (*cmd != 'g') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
339 delim_optional = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
340 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
341 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
342 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
343 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
344 p = skipwhite(p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
345 delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
346 end = skip_regexp(p, delim, p_magic, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
347 |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
348 use_last_pat = end == p && *end == delim; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
349 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
350 if (end == p && !use_last_pat) |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
351 return FALSE; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
352 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
353 // Don't do 'hlsearch' highlighting if the pattern matches everything. |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
354 if (!use_last_pat) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
355 { |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
356 char c = *end; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
357 int empty; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
358 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
359 *end = NUL; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
360 empty = empty_pattern(p); |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
361 *end = c; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
362 if (empty) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
363 return FALSE; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
364 } |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
365 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
366 // found a non-empty pattern or // |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
367 *skiplen = (int)(p - ccline.cmdbuff); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
368 *patlen = (int)(end - p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
369 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
370 // parse the address range |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
371 save_cursor = curwin->w_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
372 curwin->w_cursor = is_state->search_start; |
14760
fd69edd2c67e
patch 8.1.0392: error while typing :/foo/s// with 'incsearch' enabled
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
373 parse_cmd_address(&ea, &dummy, TRUE); |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
374 if (ea.addr_count > 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
375 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
376 // Allow for reverse match. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
377 if (ea.line2 < ea.line1) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
378 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
379 search_first_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
380 search_last_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
381 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
382 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
383 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
384 search_first_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
385 search_last_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
386 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
387 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
388 else if (cmd[0] == 's' && cmd[1] != 'o') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
389 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
390 // :s defaults to the current line |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
391 search_first_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
392 search_last_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
393 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
394 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
395 curwin->w_cursor = save_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
396 return TRUE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
397 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
398 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
399 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
400 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
401 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
402 incsearch_state_T *is_state, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
403 int call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
404 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
405 if (is_state->did_incsearch) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
406 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
407 is_state->did_incsearch = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
408 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
409 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
410 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
411 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
412 if (!EQUAL_POS(is_state->save_cursor, is_state->search_start)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
413 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
414 // put the '" mark at the original position |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
415 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
416 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
417 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
418 curwin->w_cursor = is_state->search_start; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
419 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
420 restore_viewstate(&is_state->old_viewstate); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
421 highlight_match = FALSE; |
14652
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
422 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
423 // by default search all lines |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
424 search_first_line = 0; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
425 search_last_line = MAXLNUM; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
426 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
427 p_magic = is_state->magic_save; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
428 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
429 validate_cursor(); /* needed for TAB */ |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
430 redraw_all_later(SOME_VALID); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
431 if (call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
432 update_screen(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
433 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
434 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
435 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
436 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
437 * 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
|
438 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
439 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
440 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
|
441 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
442 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
443 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
|
444 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
445 int skiplen, patlen; |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
446 int found; // do_search() result |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
447 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
|
448 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
449 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
450 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
451 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
452 int use_last_pat; |
17155
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
453 int did_do_incsearch = is_state->did_incsearch; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
454 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
455 // Parsing range may already set the last search pattern. |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15064
diff
changeset
|
456 // NOTE: must call restore_last_search_pattern() before returning! |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
457 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
458 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
459 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
460 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
461 restore_last_search_pattern(); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
462 finish_incsearch_highlighting(FALSE, is_state, TRUE); |
17155
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
463 if (did_do_incsearch && vpeekc() == NUL) |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
464 // may have skipped a redraw, do it now |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
465 redrawcmd(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
466 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
467 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
468 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
469 // 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
|
470 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
471 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
472 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
473 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
|
474 return; |
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 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
|
477 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
478 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
|
479 // 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
|
480 curwin->w_cursor = is_state->search_start; |
14976
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
481 else if (search_first_line > curbuf->b_ml.ml_line_count) |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
482 { |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
483 // start after the last line |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
484 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
485 curwin->w_cursor.col = MAXCOL; |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
486 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
487 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
488 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
489 // 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
|
490 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
|
491 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
|
492 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
493 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
494 // Use the previous pattern for ":s//". |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
495 next_char = ccline.cmdbuff[skiplen + patlen]; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
496 use_last_pat = patlen == 0 && skiplen > 0 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
497 && ccline.cmdbuff[skiplen - 1] == next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
498 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
499 // If there is no pattern, don't do anything. |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
500 if (patlen == 0 && !use_last_pat) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
501 { |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
502 found = 0; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
503 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
|
504 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
|
505 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
506 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
507 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
508 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
|
509 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
510 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
|
511 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
512 ++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
|
513 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
514 // 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
|
515 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
|
516 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
517 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
518 search_flags += SEARCH_KEEP; |
14524
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
519 if (search_first_line != 0) |
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
520 search_flags += SEARCH_START; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
521 ccline.cmdbuff[skiplen + patlen] = NUL; |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
522 found = do_search(NULL, firstc == ':' ? '/' : firstc, |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
523 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
|
524 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
525 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
527 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
528 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
529 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
530 ccline.cmdbuff[skiplen + patlen] = next_char; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
531 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
532 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
533 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
|
534 || curwin->w_cursor.lnum > search_last_line) |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
535 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
536 // match outside of address range |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
537 found = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
538 curwin->w_cursor = is_state->search_start; |
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
539 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
540 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
541 // 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
|
542 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
543 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
544 (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
|
545 got_int = FALSE; // don't abandon the command line |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
546 found = 0; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
547 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 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
|
549 // 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
|
550 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
|
551 } |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
552 if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
553 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
|
554 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
555 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
|
556 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
557 // 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
|
558 // 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
|
559 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
|
560 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
|
561 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
562 |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
563 if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
564 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
565 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
|
566 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
567 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
|
568 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
|
569 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
570 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
|
571 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
|
572 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
|
573 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
574 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
575 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
|
576 |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
577 // Disable 'hlsearch' highlighting if the pattern matches everything. |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
578 // Avoids a flash when typing "foo\|". |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
579 if (!use_last_pat) |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
580 { |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
581 next_char = ccline.cmdbuff[skiplen + patlen]; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
582 ccline.cmdbuff[skiplen + patlen] = NUL; |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
583 if (empty_pattern(ccline.cmdbuff) && !no_hlsearch) |
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
584 { |
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
585 redraw_all_later(SOME_VALID); |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
586 set_no_hlsearch(TRUE); |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
587 } |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
588 ccline.cmdbuff[skiplen + patlen] = next_char; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
589 } |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
590 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
591 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
592 // 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
|
593 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
|
594 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
|
595 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
596 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
|
597 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
|
598 |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
599 // Leave it at the end to make CTRL-R CTRL-W work. But not when beyond the |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
600 // end of the pattern, e.g. for ":s/pat/". |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
601 if (ccline.cmdbuff[skiplen + patlen] != NUL) |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
602 curwin->w_cursor = is_state->search_start; |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
603 else if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
604 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
|
605 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
606 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
607 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
608 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
|
609 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
610 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
611 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
612 * 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
|
613 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 * 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
|
615 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 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
|
618 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
|
619 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 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
|
621 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
622 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
623 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
|
624 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
625 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
626 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
|
627 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
|
628 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
|
629 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
630 // Parsing range may already set the last search pattern. |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15064
diff
changeset
|
631 // NOTE: must call restore_last_search_pattern() before returning! |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
632 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
633 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
634 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
635 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
636 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
637 return OK; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
638 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
639 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
640 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
641 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
642 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
643 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
644 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
645 if (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
|
646 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
647 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
|
648 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
649 patlen = (int)STRLEN(pat); |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
650 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
651 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
|
652 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
|
653 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
654 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
655 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
656 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
|
657 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
658 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
|
659 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
|
660 // 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
|
661 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
662 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
663 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
|
664 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
665 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
666 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
|
667 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
668 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
|
669 ++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
|
670 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
|
671 pat[patlen] = NUL; |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
672 i = searchit(curwin, curbuf, &t, NULL, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
673 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
|
674 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
|
675 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
|
676 --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
|
677 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
|
678 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
679 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
680 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
|
681 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
|
682 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
|
683 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
|
684 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
685 // 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
|
686 // 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
|
687 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
|
688 (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
|
689 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
690 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
|
691 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
692 // 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
|
693 // 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
|
694 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
|
695 (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
|
696 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
697 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
|
698 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
699 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
700 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
701 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
702 (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
|
703 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
704 (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
|
705 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
706 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
707 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
|
708 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
|
709 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
|
710 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
711 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
712 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
713 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
|
714 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
|
715 redrawcmdline(); |
17411
9c4ddc78df74
patch 8.1.1704: C-R C-W does not work after C-G when using 'incsearch'
Bram Moolenaar <Bram@vim.org>
parents:
17336
diff
changeset
|
716 curwin->w_cursor = is_state->match_end; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
717 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
718 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
719 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
|
720 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
|
721 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
722 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
723 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
724 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
725 * 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
|
726 * 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
|
727 * 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
|
728 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
729 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
730 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
|
731 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
732 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
|
733 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
734 // Parsing range may already set the last search pattern. |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15064
diff
changeset
|
735 // NOTE: must call restore_last_search_pattern() before returning! |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
736 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
737 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
738 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
739 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
740 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
741 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
742 } |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15064
diff
changeset
|
743 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
744 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
745 // 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
|
746 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
|
747 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
748 curwin->w_cursor = is_state->match_end; |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
749 *c = gchar_cursor(); |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
750 if (*c != NUL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
751 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
752 // 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
|
753 // 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
|
754 // 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
|
755 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
|
756 *c = MB_TOLOWER(*c); |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
757 if (*c == firstc || vim_strchr((char_u *)( |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
758 p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
759 { |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
760 // put a backslash before special characters |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
761 stuffcharReadbuff(*c); |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
762 *c = '\\'; |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
763 } |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
764 // add any composing characters |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
765 if (mb_char2len(*c) != mb_ptr2len(ml_get_cursor())) |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
766 { |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
767 int save_c = *c; |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
768 |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
769 while (mb_char2len(*c) != mb_ptr2len(ml_get_cursor())) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15083
diff
changeset
|
770 { |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
771 curwin->w_cursor.col += mb_char2len(*c); |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
772 *c = gchar_cursor(); |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
773 stuffcharReadbuff(*c); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15083
diff
changeset
|
774 } |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
775 *c = save_c; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
776 } |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
777 return FAIL; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
778 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
779 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
780 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
781 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
782 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
783 |
17155
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
784 #ifdef FEAT_ARABIC |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
785 /* |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
786 * Return TRUE if the command line has an Arabic character at or after "start" |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
787 * for "len" bytes. |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
788 */ |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
789 static int |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
790 cmdline_has_arabic(int start, int len) |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
791 { |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
792 int j; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
793 int mb_l; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
794 int u8c; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
795 char_u *p; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
796 int u8cc[MAX_MCO]; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
797 |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
798 if (!enc_utf8) |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
799 return FALSE; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
800 |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
801 for (j = start; j < start + len; j += mb_l) |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
802 { |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
803 p = ccline.cmdbuff + j; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
804 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
805 mb_l = utfc_ptr2len_len(p, start + len - j); |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
806 if (ARABIC_CHAR(u8c)) |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
807 return TRUE; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
808 } |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
809 return FALSE; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
810 } |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
811 #endif |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
812 |
14858
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
813 void |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
814 cmdline_init(void) |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
815 { |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
816 vim_memset(&ccline, 0, sizeof(struct cmdline_info)); |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
817 } |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
818 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
819 /* |
7 | 820 * getcmdline() - accept a command line starting with firstc. |
821 * | |
822 * firstc == ':' get ":" command line. | |
823 * firstc == '/' or '?' get search pattern | |
824 * firstc == '=' get expression | |
825 * firstc == '@' get text for input() function | |
826 * firstc == '>' get text for debug mode | |
827 * firstc == NUL get text for :insert command | |
828 * firstc == -1 like NUL, and break on CTRL-C | |
829 * | |
830 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
831 * command line. | |
832 * | |
833 * Careful: getcmdline() can be called recursively! | |
834 * | |
835 * Return pointer to allocated string if there is a commandline, NULL | |
836 * otherwise. | |
837 */ | |
838 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
839 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
840 int firstc, |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
841 long count, // only used for incremental search |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
842 int indent, // indent for inside conditionals |
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
843 int do_concat UNUSED) |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
844 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
845 return getcmdline_int(firstc, count, indent, TRUE); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
846 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
847 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
848 static char_u * |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
849 getcmdline_int( |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
850 int firstc, |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
851 long count UNUSED, // only used for incremental search |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
852 int indent, // indent for inside conditionals |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
853 int init_ccline) // clear ccline first |
7 | 854 { |
855 int c; | |
856 int i; | |
857 int j; | |
858 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
859 int do_abbr; /* when TRUE check for abbr. */ | |
860 #ifdef FEAT_CMDHIST | |
861 char_u *lookfor = NULL; /* string to match */ | |
862 int hiscnt; /* current history line in use */ | |
863 int histype; /* history type to be used */ | |
864 #endif | |
865 #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
|
866 incsearch_state_T is_state; |
7 | 867 #endif |
868 int did_wild_list = FALSE; /* did wild_list() recently */ | |
869 int wim_index = 0; /* index in wim_flags[] */ | |
870 int res; | |
871 int save_msg_scroll = msg_scroll; | |
872 int save_State = State; /* remember State when called */ | |
873 int some_key_typed = FALSE; /* one of the keys was typed */ | |
874 #ifdef FEAT_MOUSE | |
875 /* mouse drag and release events are ignored, unless they are | |
876 * preceded with a mouse down event */ | |
877 int ignore_drag_release = TRUE; | |
878 #endif | |
879 #ifdef FEAT_EVAL | |
880 int break_ctrl_c = FALSE; | |
881 #endif | |
882 expand_T xpc; | |
883 long *b_im_ptr = NULL; | |
195 | 884 struct cmdline_info save_ccline; |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
885 int did_save_ccline = FALSE; |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
886 int cmdline_type; |
7 | 887 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
888 if (ccline.cmdbuff != NULL) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
889 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
890 // Being called recursively. Since ccline is global, we need to save |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
891 // the current buffer and restore it when returning. |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
892 save_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
893 did_save_ccline = TRUE; |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
894 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
895 if (init_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
896 vim_memset(&ccline, 0, sizeof(struct cmdline_info)); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
897 |
7 | 898 #ifdef FEAT_EVAL |
899 if (firstc == -1) | |
900 { | |
901 firstc = NUL; | |
902 break_ctrl_c = TRUE; | |
903 } | |
904 #endif | |
905 #ifdef FEAT_RIGHTLEFT | |
906 /* start without Hebrew mapping for a command line */ | |
907 if (firstc == ':' || firstc == '=' || firstc == '>') | |
908 cmd_hkmap = 0; | |
909 #endif | |
910 | |
911 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
|
912 |
7 | 913 #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
|
914 init_incsearch_state(&is_state); |
7 | 915 #endif |
916 | |
917 /* | |
918 * set some variables for redrawcmd() | |
919 */ | |
920 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 921 ccline.cmdindent = (firstc > 0 ? indent : 0); |
922 | |
923 /* alloc initial ccline.cmdbuff */ | |
924 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 925 if (ccline.cmdbuff == NULL) |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
926 goto theend; // out of memory |
7 | 927 ccline.cmdlen = ccline.cmdpos = 0; |
928 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
|
929 sb_text_start_cmdline(); |
7 | 930 |
164 | 931 /* autoindent for :insert and :append */ |
932 if (firstc <= 0) | |
933 { | |
6929 | 934 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 935 ccline.cmdbuff[indent] = NUL; |
936 ccline.cmdpos = indent; | |
937 ccline.cmdspos = indent; | |
938 ccline.cmdlen = indent; | |
939 } | |
940 | |
7 | 941 ExpandInit(&xpc); |
1718 | 942 ccline.xpc = &xpc; |
7 | 943 |
944 #ifdef FEAT_RIGHTLEFT | |
945 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
946 && (firstc == '/' || firstc == '?')) | |
947 cmdmsg_rl = TRUE; | |
948 else | |
949 cmdmsg_rl = FALSE; | |
950 #endif | |
951 | |
952 redir_off = TRUE; /* don't redirect the typed command */ | |
953 if (!cmd_silent) | |
954 { | |
955 i = msg_scrolled; | |
956 msg_scrolled = 0; /* avoid wait_return message */ | |
957 gotocmdline(TRUE); | |
958 msg_scrolled += i; | |
959 redrawcmdprompt(); /* draw prompt or indent */ | |
960 set_cmdspos(); | |
961 } | |
962 xpc.xp_context = EXPAND_NOTHING; | |
963 xpc.xp_backslash = XP_BS_NONE; | |
632 | 964 #ifndef BACKSLASH_IN_FILENAME |
965 xpc.xp_shell = FALSE; | |
966 #endif | |
7 | 967 |
531 | 968 #if defined(FEAT_EVAL) |
969 if (ccline.input_fn) | |
970 { | |
971 xpc.xp_context = ccline.xp_context; | |
972 xpc.xp_pattern = ccline.cmdbuff; | |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16287
diff
changeset
|
973 # if defined(FEAT_CMDL_COMPL) |
531 | 974 xpc.xp_arg = ccline.xp_arg; |
1322 | 975 # endif |
531 | 976 } |
977 #endif | |
978 | |
7 | 979 /* |
980 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
981 * doing ":@0" when register 0 doesn't contain a CR. | |
982 */ | |
983 msg_scroll = FALSE; | |
984 | |
985 State = CMDLINE; | |
986 | |
987 if (firstc == '/' || firstc == '?' || firstc == '@') | |
988 { | |
989 /* Use ":lmap" mappings for search pattern and input(). */ | |
990 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
991 b_im_ptr = &curbuf->b_p_iminsert; | |
992 else | |
993 b_im_ptr = &curbuf->b_p_imsearch; | |
994 if (*b_im_ptr == B_IMODE_LMAP) | |
995 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
996 #ifdef HAVE_INPUT_METHOD |
7 | 997 im_set_active(*b_im_ptr == B_IMODE_IM); |
998 #endif | |
999 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1000 #ifdef HAVE_INPUT_METHOD |
7 | 1001 else if (p_imcmdline) |
1002 im_set_active(TRUE); | |
1003 #endif | |
1004 | |
1005 #ifdef FEAT_MOUSE | |
1006 setmouse(); | |
1007 #endif | |
1008 #ifdef CURSOR_SHAPE | |
1009 ui_cursor_shape(); /* may show different cursor shape */ | |
1010 #endif | |
1011 | |
571 | 1012 /* When inside an autocommand for writing "exiting" may be set and |
1013 * terminal mode set to cooked. Need to set raw mode here then. */ | |
1014 settmode(TMODE_RAW); | |
1015 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
1016 /* 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
|
1017 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
|
1018 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
|
1019 |
7 | 1020 #ifdef FEAT_CMDHIST |
1021 init_history(); | |
1022 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
1023 histype = hist_char2type(firstc); | |
1024 #endif | |
1025 | |
1026 #ifdef FEAT_DIGRAPHS | |
1868 | 1027 do_digraph(-1); /* init digraph typeahead */ |
7 | 1028 #endif |
1029 | |
5993 | 1030 /* If something above caused an error, reset the flags, we do want to type |
1031 * and execute commands. Display may be messed up a bit. */ | |
1032 if (did_emsg) | |
1033 redrawcmd(); | |
1034 did_emsg = FALSE; | |
1035 got_int = FALSE; | |
1036 | |
7 | 1037 /* |
1038 * Collect the command string, handling editing keys. | |
1039 */ | |
1040 for (;;) | |
1041 { | |
972 | 1042 redir_off = TRUE; /* Don't redirect the typed command. |
1043 Repeated, because a ":redir" inside | |
1044 completion may switch it on. */ | |
7 | 1045 #ifdef USE_ON_FLY_SCROLL |
1046 dont_scroll = FALSE; /* allow scrolling here */ | |
1047 #endif | |
1048 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
1049 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
1050 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
|
1051 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
|
1052 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
|
1053 |
7 | 1054 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 1055 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
1056 /* 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
|
1057 * anything, such as stop completion. */ |
1472 | 1058 do |
1059 c = safe_vgetc(); | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1060 while (c == K_IGNORE || c == K_NOP); |
1472 | 1061 |
7 | 1062 if (KeyTyped) |
1063 { | |
1064 some_key_typed = TRUE; | |
1065 #ifdef FEAT_RIGHTLEFT | |
1066 if (cmd_hkmap) | |
1067 c = hkmap(c); | |
1068 if (cmdmsg_rl && !KeyStuffed) | |
1069 { | |
1070 /* Invert horizontal movements and operations. Only when | |
1071 * typed by the user directly, not when the result of a | |
1072 * mapping. */ | |
1073 switch (c) | |
1074 { | |
1075 case K_RIGHT: c = K_LEFT; break; | |
1076 case K_S_RIGHT: c = K_S_LEFT; break; | |
1077 case K_C_RIGHT: c = K_C_LEFT; break; | |
1078 case K_LEFT: c = K_RIGHT; break; | |
1079 case K_S_LEFT: c = K_S_RIGHT; break; | |
1080 case K_C_LEFT: c = K_C_RIGHT; break; | |
1081 } | |
1082 } | |
1083 #endif | |
1084 } | |
1085 | |
1086 /* | |
1087 * Ignore got_int when CTRL-C was typed here. | |
1088 * Don't ignore it in :global, we really need to break then, e.g., for | |
1089 * ":g/pat/normal /pat" (without the <CR>). | |
1090 * Don't ignore it for the input() function. | |
1091 */ | |
1092 if ((c == Ctrl_C | |
1093 #ifdef UNIX | |
1094 || c == intr_char | |
1095 #endif | |
1096 ) | |
1097 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
1098 && firstc != '@' | |
1099 #endif | |
1100 #ifdef FEAT_EVAL | |
1101 && !break_ctrl_c | |
1102 #endif | |
1103 && !global_busy) | |
1104 got_int = FALSE; | |
1105 | |
1106 #ifdef FEAT_CMDHIST | |
1107 /* free old command line when finished moving around in the history | |
1108 * list */ | |
1109 if (lookfor != NULL | |
180 | 1110 && c != K_S_DOWN && c != K_S_UP |
230 | 1111 && c != K_DOWN && c != K_UP |
7 | 1112 && c != K_PAGEDOWN && c != K_PAGEUP |
1113 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 1114 && c != K_LEFT && c != K_RIGHT |
7 | 1115 && (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
|
1116 VIM_CLEAR(lookfor); |
7 | 1117 #endif |
1118 | |
1119 /* | |
1718 | 1120 * When there are matching completions to select <S-Tab> works like |
1121 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 1122 */ |
1718 | 1123 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 1124 c = Ctrl_P; |
1125 | |
1126 #ifdef FEAT_WILDMENU | |
1127 /* Special translations for 'wildmenu' */ | |
1128 if (did_wild_list && p_wmnu) | |
1129 { | |
230 | 1130 if (c == K_LEFT) |
7 | 1131 c = Ctrl_P; |
230 | 1132 else if (c == K_RIGHT) |
7 | 1133 c = Ctrl_N; |
1134 } | |
1135 /* Hitting CR after "emenu Name.": complete submenu */ | |
1136 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1137 && ccline.cmdpos > 1 | |
1138 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1139 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1140 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1141 c = K_DOWN; | |
1142 #endif | |
1143 | |
1144 /* free expanded names when finished walking through matches */ | |
1145 if (xpc.xp_numfiles != -1 | |
1146 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1147 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1148 && c != Ctrl_L) | |
1149 { | |
1150 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1151 did_wild_list = FALSE; | |
1152 #ifdef FEAT_WILDMENU | |
230 | 1153 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1154 #endif |
1155 xpc.xp_context = EXPAND_NOTHING; | |
1156 wim_index = 0; | |
1157 #ifdef FEAT_WILDMENU | |
1158 if (p_wmnu && wild_menu_showing != 0) | |
1159 { | |
1160 int skt = KeyTyped; | |
532 | 1161 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1162 |
1163 if (ccline.input_fn) | |
1164 RedrawingDisabled = 0; | |
7 | 1165 |
1166 if (wild_menu_showing == WM_SCROLLED) | |
1167 { | |
1168 /* Entered command line, move it up */ | |
1169 cmdline_row--; | |
1170 redrawcmd(); | |
1171 } | |
1172 else if (save_p_ls != -1) | |
1173 { | |
1174 /* restore 'laststatus' and 'winminheight' */ | |
1175 p_ls = save_p_ls; | |
1176 p_wmh = save_p_wmh; | |
1177 last_status(FALSE); | |
1178 update_screen(VALID); /* redraw the screen NOW */ | |
1179 redrawcmd(); | |
1180 save_p_ls = -1; | |
1181 } | |
1182 else | |
1183 { | |
1184 win_redraw_last_status(topframe); | |
1185 redraw_statuslines(); | |
1186 } | |
532 | 1187 KeyTyped = skt; |
1188 wild_menu_showing = 0; | |
531 | 1189 if (ccline.input_fn) |
1190 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1191 } |
1192 #endif | |
1193 } | |
1194 | |
1195 #ifdef FEAT_WILDMENU | |
1196 /* Special translations for 'wildmenu' */ | |
1197 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1198 { | |
1199 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1200 if (c == K_DOWN && ccline.cmdpos > 0 |
1201 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1202 c = p_wc; |
230 | 1203 else if (c == K_UP) |
7 | 1204 { |
1205 /* Hitting <Up>: Remove one submenu name in front of the | |
1206 * cursor */ | |
1207 int found = FALSE; | |
1208 | |
1209 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1210 i = 0; | |
1211 while (--j > 0) | |
1212 { | |
1213 /* check for start of menu name */ | |
1214 if (ccline.cmdbuff[j] == ' ' | |
1215 && ccline.cmdbuff[j - 1] != '\\') | |
1216 { | |
1217 i = j + 1; | |
1218 break; | |
1219 } | |
1220 /* check for start of submenu name */ | |
1221 if (ccline.cmdbuff[j] == '.' | |
1222 && ccline.cmdbuff[j - 1] != '\\') | |
1223 { | |
1224 if (found) | |
1225 { | |
1226 i = j + 1; | |
1227 break; | |
1228 } | |
1229 else | |
1230 found = TRUE; | |
1231 } | |
1232 } | |
1233 if (i > 0) | |
1234 cmdline_del(i); | |
1235 c = p_wc; | |
1236 xpc.xp_context = EXPAND_NOTHING; | |
1237 } | |
1238 } | |
714 | 1239 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1240 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1241 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1242 { |
1243 char_u upseg[5]; | |
1244 | |
1245 upseg[0] = PATHSEP; | |
1246 upseg[1] = '.'; | |
1247 upseg[2] = '.'; | |
1248 upseg[3] = PATHSEP; | |
1249 upseg[4] = NUL; | |
1250 | |
1318 | 1251 if (c == K_DOWN |
1252 && ccline.cmdpos > 0 | |
1253 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1254 && (ccline.cmdpos < 3 | |
1255 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1256 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1257 { | |
1258 /* go down a directory */ | |
1259 c = p_wc; | |
1260 } | |
230 | 1261 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1262 { |
1263 /* If in a direct ancestor, strip off one ../ to go down */ | |
1264 int found = FALSE; | |
1265 | |
1266 j = ccline.cmdpos; | |
1267 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1268 while (--j > i) | |
1269 { | |
39 | 1270 if (has_mbyte) |
1271 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
7 | 1272 if (vim_ispathsep(ccline.cmdbuff[j])) |
1273 { | |
1274 found = TRUE; | |
1275 break; | |
1276 } | |
1277 } | |
1278 if (found | |
1279 && ccline.cmdbuff[j - 1] == '.' | |
1280 && ccline.cmdbuff[j - 2] == '.' | |
1281 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1282 { | |
1283 cmdline_del(j - 2); | |
1284 c = p_wc; | |
1285 } | |
1286 } | |
230 | 1287 else if (c == K_UP) |
7 | 1288 { |
1289 /* go up a directory */ | |
1290 int found = FALSE; | |
1291 | |
1292 j = ccline.cmdpos - 1; | |
1293 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1294 while (--j > i) | |
1295 { | |
1296 if (has_mbyte) | |
1297 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1298 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1299 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1300 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1301 ccline.cmdbuff[j + 1]) == NULL |
7 | 1302 #endif |
1303 ) | |
1304 { | |
1305 if (found) | |
1306 { | |
1307 i = j + 1; | |
1308 break; | |
1309 } | |
1310 else | |
1311 found = TRUE; | |
1312 } | |
1313 } | |
1314 | |
1315 if (!found) | |
1316 j = i; | |
1317 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1318 j += 4; | |
1319 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1320 && j == i) | |
1321 j += 3; | |
1322 else | |
1323 j = 0; | |
1324 if (j > 0) | |
1325 { | |
1326 /* TODO this is only for DOS/UNIX systems - need to put in | |
1327 * machine-specific stuff here and in upseg init */ | |
1328 cmdline_del(j); | |
1329 put_on_cmdline(upseg + 1, 3, FALSE); | |
1330 } | |
1331 else if (ccline.cmdpos > i) | |
1332 cmdline_del(i); | |
3204 | 1333 |
1334 /* Now complete in the new directory. Set KeyTyped in case the | |
1335 * Up key came from a mapping. */ | |
7 | 1336 c = p_wc; |
3204 | 1337 KeyTyped = TRUE; |
7 | 1338 } |
1339 } | |
1340 | |
1341 #endif /* FEAT_WILDMENU */ | |
1342 | |
1343 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1344 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1345 if (c == Ctrl_BSL) | |
1346 { | |
1347 ++no_mapping; | |
1348 ++allow_keys; | |
1389 | 1349 c = plain_vgetc(); |
7 | 1350 --no_mapping; |
1351 --allow_keys; | |
3859 | 1352 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1353 * is in a mapping. */ | |
1354 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
14842
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1355 || (ccline.cmdfirstc == '=' && KeyTyped) |
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1356 #ifdef FEAT_EVAL |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1357 || cmdline_star > 0 |
14842
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1358 #endif |
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1359 )) |
7 | 1360 { |
1361 vungetc(c); | |
1362 c = Ctrl_BSL; | |
1363 } | |
1364 #ifdef FEAT_EVAL | |
1365 else if (c == 'e') | |
1366 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1367 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1368 int len; |
7 | 1369 |
1370 /* | |
1371 * Replace the command line with the result of an expression. | |
625 | 1372 * Need to save and restore the current command line, to be |
1373 * able to enter a new one... | |
7 | 1374 */ |
1375 if (ccline.cmdpos == ccline.cmdlen) | |
1376 new_cmdpos = 99999; /* keep it at the end */ | |
1377 else | |
1378 new_cmdpos = ccline.cmdpos; | |
95 | 1379 |
7 | 1380 c = get_expr_register(); |
1381 if (c == '=') | |
1382 { | |
634 | 1383 /* Need to save and restore ccline. And set "textlock" |
632 | 1384 * to avoid nasty things like going to another buffer when |
1385 * evaluating an expression. */ | |
634 | 1386 ++textlock; |
7 | 1387 p = get_expr_line(); |
634 | 1388 --textlock; |
2617 | 1389 |
1390 if (p != NULL) | |
7 | 1391 { |
2617 | 1392 len = (int)STRLEN(p); |
1393 if (realloc_cmdbuff(len + 1) == OK) | |
1394 { | |
1395 ccline.cmdlen = len; | |
1396 STRCPY(ccline.cmdbuff, p); | |
1397 vim_free(p); | |
1398 | |
1399 /* Restore the cursor or use the position set with | |
1400 * set_cmdline_pos(). */ | |
1401 if (new_cmdpos > ccline.cmdlen) | |
1402 ccline.cmdpos = ccline.cmdlen; | |
1403 else | |
1404 ccline.cmdpos = new_cmdpos; | |
1405 | |
1406 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1407 redrawcmd(); | |
1408 goto cmdline_changed; | |
1409 } | |
15064
7b2dcca9e0c1
patch 8.1.0543: Coverity warns for leaking memory and using wrong struct
Bram Moolenaar <Bram@vim.org>
parents:
14976
diff
changeset
|
1410 vim_free(p); |
7 | 1411 } |
1412 } | |
1413 beep_flush(); | |
2636 | 1414 got_int = FALSE; /* don't abandon the command line */ |
1415 did_emsg = FALSE; | |
1416 emsg_on_display = FALSE; | |
1417 redrawcmd(); | |
1418 goto cmdline_not_changed; | |
7 | 1419 } |
1420 #endif | |
1421 else | |
1422 { | |
1423 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1424 restart_edit = 'a'; | |
1425 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1426 in history */ | |
1427 goto returncmd; /* back to Normal mode */ | |
1428 } | |
1429 } | |
1430 | |
1431 #ifdef FEAT_CMDWIN | |
1432 if (c == cedit_key || c == K_CMDWIN) | |
1433 { | |
6211 | 1434 if (ex_normal_busy == 0 && got_int == FALSE) |
1435 { | |
1436 /* | |
1437 * Open a window to edit the command line (and history). | |
1438 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1439 c = open_cmdwin(); |
6211 | 1440 some_key_typed = TRUE; |
1441 } | |
7 | 1442 } |
1443 # ifdef FEAT_DIGRAPHS | |
1444 else | |
1445 # endif | |
1446 #endif | |
1447 #ifdef FEAT_DIGRAPHS | |
1448 c = do_digraph(c); | |
1449 #endif | |
1450 | |
1451 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1452 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1453 { | |
168 | 1454 /* In Ex mode a backslash escapes a newline. */ |
1455 if (exmode_active | |
1456 && c != ESC | |
1318 | 1457 && ccline.cmdpos == ccline.cmdlen |
168 | 1458 && ccline.cmdpos > 0 |
1459 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1460 { | |
1461 if (c == K_KENTER) | |
1462 c = '\n'; | |
1463 } | |
1464 else | |
7 | 1465 { |
168 | 1466 gotesc = FALSE; /* Might have typed ESC previously, don't |
1467 truncate the cmdline now. */ | |
1468 if (ccheck_abbr(c + ABBR_OFF)) | |
1469 goto cmdline_changed; | |
1470 if (!cmd_silent) | |
1471 { | |
1472 windgoto(msg_row, 0); | |
1473 out_flush(); | |
1474 } | |
1475 break; | |
7 | 1476 } |
1477 } | |
1478 | |
1479 /* | |
1480 * Completion for 'wildchar' or 'wildcharm' key. | |
1481 * - hitting <ESC> twice means: abandon command line. | |
1482 * - wildcard expansion is only done when the 'wildchar' key is really | |
1483 * typed, not when it comes from a macro | |
1484 */ | |
1485 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1486 { | |
1487 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1488 { | |
1489 /* if 'wildmode' contains "list" may still need to list */ | |
1490 if (xpc.xp_numfiles > 1 | |
1491 && !did_wild_list | |
1492 && (wim_flags[wim_index] & WIM_LIST)) | |
1493 { | |
1494 (void)showmatches(&xpc, FALSE); | |
1495 redrawcmd(); | |
1496 did_wild_list = TRUE; | |
1497 } | |
1498 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1499 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1500 firstc != '@'); | |
7 | 1501 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1502 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1503 firstc != '@'); | |
7 | 1504 else |
1505 res = OK; /* don't insert 'wildchar' now */ | |
1506 } | |
1507 else /* typed p_wc first time */ | |
1508 { | |
1509 wim_index = 0; | |
1510 j = ccline.cmdpos; | |
1511 /* if 'wildmode' first contains "longest", get longest | |
1512 * common part */ | |
1513 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1514 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1515 firstc != '@'); | |
7 | 1516 else |
3961 | 1517 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1518 firstc != '@'); | |
7 | 1519 |
1520 /* if interrupted while completing, behave like it failed */ | |
1521 if (got_int) | |
1522 { | |
1523 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1524 got_int = FALSE; /* don't abandon the command line */ | |
1525 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1526 #ifdef FEAT_WILDMENU | |
1527 xpc.xp_context = EXPAND_NOTHING; | |
1528 #endif | |
1529 goto cmdline_changed; | |
1530 } | |
1531 | |
1532 /* when more than one match, and 'wildmode' first contains | |
1533 * "list", or no change and 'wildmode' contains "longest,list", | |
1534 * list all matches */ | |
1535 if (res == OK && xpc.xp_numfiles > 1) | |
1536 { | |
1537 /* a "longest" that didn't do anything is skipped (but not | |
1538 * "list:longest") */ | |
1539 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1540 wim_index = 1; | |
1541 if ((wim_flags[wim_index] & WIM_LIST) | |
1542 #ifdef FEAT_WILDMENU | |
1543 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1544 #endif | |
1545 ) | |
1546 { | |
1547 if (!(wim_flags[0] & WIM_LONGEST)) | |
1548 { | |
1549 #ifdef FEAT_WILDMENU | |
1550 int p_wmnu_save = p_wmnu; | |
1551 p_wmnu = 0; | |
1552 #endif | |
3961 | 1553 /* remove match */ |
1554 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1555 #ifdef FEAT_WILDMENU |
1556 p_wmnu = p_wmnu_save; | |
1557 #endif | |
1558 } | |
1559 #ifdef FEAT_WILDMENU | |
1560 (void)showmatches(&xpc, p_wmnu | |
1561 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1562 #else | |
1563 (void)showmatches(&xpc, FALSE); | |
1564 #endif | |
1565 redrawcmd(); | |
1566 did_wild_list = TRUE; | |
1567 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1568 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1569 firstc != '@'); | |
7 | 1570 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1571 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1572 firstc != '@'); | |
7 | 1573 } |
1574 else | |
6949 | 1575 vim_beep(BO_WILD); |
7 | 1576 } |
1577 #ifdef FEAT_WILDMENU | |
1578 else if (xpc.xp_numfiles == -1) | |
1579 xpc.xp_context = EXPAND_NOTHING; | |
1580 #endif | |
1581 } | |
1582 if (wim_index < 3) | |
1583 ++wim_index; | |
1584 if (c == ESC) | |
1585 gotesc = TRUE; | |
1586 if (res == OK) | |
1587 goto cmdline_changed; | |
1588 } | |
1589 | |
1590 gotesc = FALSE; | |
1591 | |
1592 /* <S-Tab> goes to last match, in a clumsy way */ | |
1593 if (c == K_S_TAB && KeyTyped) | |
1594 { | |
3961 | 1595 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1596 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1597 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1598 goto cmdline_changed; |
1599 } | |
1600 | |
1601 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1602 c = NL; | |
1603 | |
1604 do_abbr = TRUE; /* default: check for abbreviation */ | |
1605 | |
1606 /* | |
1607 * Big switch for a typed command line character. | |
1608 */ | |
1609 switch (c) | |
1610 { | |
1611 case K_BS: | |
1612 case Ctrl_H: | |
1613 case K_DEL: | |
1614 case K_KDEL: | |
1615 case Ctrl_W: | |
1616 if (c == K_KDEL) | |
1617 c = K_DEL; | |
1618 | |
1619 /* | |
1620 * delete current character is the same as backspace on next | |
1621 * character, except at end of line | |
1622 */ | |
1623 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1624 ++ccline.cmdpos; | |
1625 if (has_mbyte && c == K_DEL) | |
1626 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1627 ccline.cmdbuff + ccline.cmdpos); | |
1628 if (ccline.cmdpos > 0) | |
1629 { | |
1630 char_u *p; | |
1631 | |
1632 j = ccline.cmdpos; | |
1633 p = ccline.cmdbuff + j; | |
1634 if (has_mbyte) | |
1635 { | |
1636 p = mb_prevptr(ccline.cmdbuff, p); | |
1637 if (c == Ctrl_W) | |
1638 { | |
1639 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1640 p = mb_prevptr(ccline.cmdbuff, p); | |
1641 i = mb_get_class(p); | |
1642 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1643 p = mb_prevptr(ccline.cmdbuff, p); | |
1644 if (mb_get_class(p) != i) | |
474 | 1645 p += (*mb_ptr2len)(p); |
7 | 1646 } |
1647 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
1648 else if (c == Ctrl_W) |
7 | 1649 { |
1650 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1651 --p; | |
1652 i = vim_iswordc(p[-1]); | |
1653 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1654 && vim_iswordc(p[-1]) == i) | |
1655 --p; | |
1656 } | |
1657 else | |
1658 --p; | |
1659 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1660 ccline.cmdlen -= j - ccline.cmdpos; | |
1661 i = ccline.cmdpos; | |
1662 while (i < ccline.cmdlen) | |
1663 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1664 | |
1665 /* Truncate at the end, required for multi-byte chars. */ | |
1666 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1667 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1668 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1669 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1670 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
|
1671 /* 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
|
1672 * 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
|
1673 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
|
1674 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1675 #endif |
7 | 1676 redrawcmd(); |
1677 } | |
1678 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1679 && ccline.cmdprompt == NULL && indent == 0) | |
1680 { | |
1681 /* In ex and debug mode it doesn't make sense to return. */ | |
1682 if (exmode_active | |
1683 #ifdef FEAT_EVAL | |
1684 || ccline.cmdfirstc == '>' | |
1685 #endif | |
1686 ) | |
1687 goto cmdline_not_changed; | |
1688 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1689 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1690 if (!cmd_silent) |
1691 { | |
1692 #ifdef FEAT_RIGHTLEFT | |
1693 if (cmdmsg_rl) | |
1694 msg_col = Columns; | |
1695 else | |
1696 #endif | |
1697 msg_col = 0; | |
1698 msg_putchar(' '); /* delete ':' */ | |
1699 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1700 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1701 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
|
1702 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
|
1703 #endif |
7 | 1704 redraw_cmdline = TRUE; |
1705 goto returncmd; /* back to cmd mode */ | |
1706 } | |
1707 goto cmdline_changed; | |
1708 | |
1709 case K_INS: | |
1710 case K_KINS: | |
1711 ccline.overstrike = !ccline.overstrike; | |
1712 #ifdef CURSOR_SHAPE | |
1713 ui_cursor_shape(); /* may show different cursor shape */ | |
1714 #endif | |
1715 goto cmdline_not_changed; | |
1716 | |
1717 case Ctrl_HAT: | |
782 | 1718 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1719 { |
1720 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1721 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1722 #ifdef HAVE_INPUT_METHOD |
7 | 1723 im_set_active(FALSE); /* Disable input method */ |
1724 #endif | |
1725 if (b_im_ptr != NULL) | |
1726 { | |
1727 if (State & LANGMAP) | |
1728 *b_im_ptr = B_IMODE_LMAP; | |
1729 else | |
1730 *b_im_ptr = B_IMODE_NONE; | |
1731 } | |
1732 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1733 #ifdef HAVE_INPUT_METHOD |
7 | 1734 else |
1735 { | |
1736 /* There are no ":lmap" mappings, toggle IM. When | |
1737 * 'imdisable' is set don't try getting the status, it's | |
1738 * always off. */ | |
1739 if ((p_imdisable && b_im_ptr != NULL) | |
1740 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1741 { | |
1742 im_set_active(FALSE); /* Disable input method */ | |
1743 if (b_im_ptr != NULL) | |
1744 *b_im_ptr = B_IMODE_NONE; | |
1745 } | |
1746 else | |
1747 { | |
1748 im_set_active(TRUE); /* Enable input method */ | |
1749 if (b_im_ptr != NULL) | |
1750 *b_im_ptr = B_IMODE_IM; | |
1751 } | |
1752 } | |
1753 #endif | |
1754 if (b_im_ptr != NULL) | |
1755 { | |
1756 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1757 set_iminsert_global(); | |
1758 else | |
1759 set_imsearch_global(); | |
1760 } | |
1761 #ifdef CURSOR_SHAPE | |
1762 ui_cursor_shape(); /* may show different cursor shape */ | |
1763 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1764 #if defined(FEAT_KEYMAP) |
7 | 1765 /* Show/unshow value of 'keymap' in status lines later. */ |
1766 status_redraw_curbuf(); | |
1767 #endif | |
1768 goto cmdline_not_changed; | |
1769 | |
1770 /* case '@': only in very old vi */ | |
1771 case Ctrl_U: | |
1772 /* delete all characters left of the cursor */ | |
1773 j = ccline.cmdpos; | |
1774 ccline.cmdlen -= j; | |
1775 i = ccline.cmdpos = 0; | |
1776 while (i < ccline.cmdlen) | |
1777 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1778 /* Truncate at the end, required for multi-byte chars. */ | |
1779 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1780 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1781 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
|
1782 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
|
1783 #endif |
7 | 1784 redrawcmd(); |
1785 goto cmdline_changed; | |
1786 | |
1787 #ifdef FEAT_CLIPBOARD | |
1788 case Ctrl_Y: | |
1789 /* Copy the modeless selection, if there is one. */ | |
1790 if (clip_star.state != SELECT_CLEARED) | |
1791 { | |
1792 if (clip_star.state == SELECT_DONE) | |
1793 clip_copy_modeless_selection(TRUE); | |
1794 goto cmdline_not_changed; | |
1795 } | |
1796 break; | |
1797 #endif | |
1798 | |
1799 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1800 case Ctrl_C: | |
571 | 1801 /* In exmode it doesn't make sense to return. Except when |
161 | 1802 * ":normal" runs out of characters. */ |
1803 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1804 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1805 goto cmdline_not_changed; |
1806 | |
1807 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1808 putting it in history */ | |
1809 goto returncmd; /* back to cmd mode */ | |
1810 | |
1811 case Ctrl_R: /* insert register */ | |
1812 #ifdef USE_ON_FLY_SCROLL | |
1813 dont_scroll = TRUE; /* disallow scrolling here */ | |
1814 #endif | |
1815 putcmdline('"', TRUE); | |
1816 ++no_mapping; | |
1389 | 1817 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1818 if (i == Ctrl_O) |
1819 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1820 if (i == Ctrl_R) | |
1389 | 1821 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
|
1822 extra_char = NUL; |
7 | 1823 --no_mapping; |
1824 #ifdef FEAT_EVAL | |
1825 /* | |
1826 * Insert the result of an expression. | |
1827 * Need to save the current command line, to be able to enter | |
1828 * a new one... | |
1829 */ | |
1830 new_cmdpos = -1; | |
1831 if (c == '=') | |
1832 { | |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1833 if (ccline.cmdfirstc == '=' // can't do this recursively |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1834 || cmdline_star > 0) // or when typing a password |
7 | 1835 { |
1836 beep_flush(); | |
1837 c = ESC; | |
1838 } | |
1839 else | |
1840 c = get_expr_register(); | |
1841 } | |
1842 #endif | |
1843 if (c != ESC) /* use ESC to cancel inserting register */ | |
1844 { | |
1015 | 1845 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1846 |
613 | 1847 #ifdef FEAT_EVAL |
606 | 1848 /* When there was a serious error abort getting the |
1849 * command line. */ | |
1850 if (aborting()) | |
1851 { | |
1852 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1853 putting it in history */ | |
1854 goto returncmd; /* back to cmd mode */ | |
1855 } | |
613 | 1856 #endif |
7 | 1857 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1858 #ifdef FEAT_EVAL | |
1859 if (new_cmdpos >= 0) | |
1860 { | |
1861 /* set_cmdline_pos() was used */ | |
1862 if (new_cmdpos > ccline.cmdlen) | |
1863 ccline.cmdpos = ccline.cmdlen; | |
1864 else | |
1865 ccline.cmdpos = new_cmdpos; | |
1866 } | |
1867 #endif | |
1868 } | |
1869 redrawcmd(); | |
1870 goto cmdline_changed; | |
1871 | |
1872 case Ctrl_D: | |
1873 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1874 break; /* Use ^D as normal char instead */ | |
1875 | |
1876 redrawcmd(); | |
1877 continue; /* don't do incremental search now */ | |
1878 | |
1879 case K_RIGHT: | |
1880 case K_S_RIGHT: | |
1881 case K_C_RIGHT: | |
1882 do | |
1883 { | |
1884 if (ccline.cmdpos >= ccline.cmdlen) | |
1885 break; | |
1886 i = cmdline_charsize(ccline.cmdpos); | |
1887 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1888 break; | |
1889 ccline.cmdspos += i; | |
1890 if (has_mbyte) | |
474 | 1891 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1892 + ccline.cmdpos); |
1893 else | |
1894 ++ccline.cmdpos; | |
1895 } | |
180 | 1896 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1897 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1898 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1899 if (has_mbyte) | |
1900 set_cmdspos_cursor(); | |
1901 goto cmdline_not_changed; | |
1902 | |
1903 case K_LEFT: | |
1904 case K_S_LEFT: | |
1905 case K_C_LEFT: | |
1456 | 1906 if (ccline.cmdpos == 0) |
1907 goto cmdline_not_changed; | |
7 | 1908 do |
1909 { | |
1910 --ccline.cmdpos; | |
1911 if (has_mbyte) /* move to first byte of char */ | |
1912 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1913 ccline.cmdbuff + ccline.cmdpos); | |
1914 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1915 } | |
1456 | 1916 while (ccline.cmdpos > 0 |
1917 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1918 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1919 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1920 if (has_mbyte) | |
1921 set_cmdspos_cursor(); | |
1922 goto cmdline_not_changed; | |
1923 | |
1924 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
|
1925 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1926 goto cmdline_not_changed; |
7 | 1927 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1928 #ifdef FEAT_GUI_MSWIN |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1929 /* On MS-Windows ignore <M-F4>, we get it when closing the window |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1930 * was cancelled. */ |
625 | 1931 case K_F4: |
1932 if (mod_mask == MOD_MASK_ALT) | |
1933 { | |
1934 redrawcmd(); /* somehow the cmdline is cleared */ | |
1935 goto cmdline_not_changed; | |
1936 } | |
1937 break; | |
1938 #endif | |
1939 | |
7 | 1940 #ifdef FEAT_MOUSE |
1941 case K_MIDDLEDRAG: | |
1942 case K_MIDDLERELEASE: | |
1943 goto cmdline_not_changed; /* Ignore mouse */ | |
1944 | |
1945 case K_MIDDLEMOUSE: | |
1946 # ifdef FEAT_GUI | |
1947 /* When GUI is active, also paste when 'mouse' is empty */ | |
1948 if (!gui.in_use) | |
1949 # endif | |
1950 if (!mouse_has(MOUSE_COMMAND)) | |
1951 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1952 # ifdef FEAT_CLIPBOARD |
7 | 1953 if (clip_star.available) |
1015 | 1954 cmdline_paste('*', TRUE, TRUE); |
7 | 1955 else |
692 | 1956 # endif |
1015 | 1957 cmdline_paste(0, TRUE, TRUE); |
7 | 1958 redrawcmd(); |
1959 goto cmdline_changed; | |
1960 | |
692 | 1961 # ifdef FEAT_DND |
7 | 1962 case K_DROP: |
1015 | 1963 cmdline_paste('~', TRUE, FALSE); |
7 | 1964 redrawcmd(); |
1965 goto cmdline_changed; | |
692 | 1966 # endif |
7 | 1967 |
1968 case K_LEFTDRAG: | |
1969 case K_LEFTRELEASE: | |
1970 case K_RIGHTDRAG: | |
1971 case K_RIGHTRELEASE: | |
1972 /* Ignore drag and release events when the button-down wasn't | |
1973 * seen before. */ | |
1974 if (ignore_drag_release) | |
1975 goto cmdline_not_changed; | |
1976 /* FALLTHROUGH */ | |
1977 case K_LEFTMOUSE: | |
1978 case K_RIGHTMOUSE: | |
1979 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1980 ignore_drag_release = TRUE; | |
1981 else | |
1982 ignore_drag_release = FALSE; | |
1983 # ifdef FEAT_GUI | |
1984 /* When GUI is active, also move when 'mouse' is empty */ | |
1985 if (!gui.in_use) | |
1986 # endif | |
1987 if (!mouse_has(MOUSE_COMMAND)) | |
1988 goto cmdline_not_changed; /* Ignore mouse */ | |
1989 # ifdef FEAT_CLIPBOARD | |
1990 if (mouse_row < cmdline_row && clip_star.available) | |
1991 { | |
1992 int button, is_click, is_drag; | |
1993 | |
1994 /* | |
1995 * Handle modeless selection. | |
1996 */ | |
1997 button = get_mouse_button(KEY2TERMCAP1(c), | |
1998 &is_click, &is_drag); | |
1999 if (mouse_model_popup() && button == MOUSE_LEFT | |
2000 && (mod_mask & MOD_MASK_SHIFT)) | |
2001 { | |
2002 /* Translate shift-left to right button. */ | |
2003 button = MOUSE_RIGHT; | |
2004 mod_mask &= ~MOD_MASK_SHIFT; | |
2005 } | |
2006 clip_modeless(button, is_click, is_drag); | |
2007 goto cmdline_not_changed; | |
2008 } | |
2009 # endif | |
2010 | |
2011 set_cmdspos(); | |
2012 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
2013 ++ccline.cmdpos) | |
2014 { | |
2015 i = cmdline_charsize(ccline.cmdpos); | |
2016 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
2017 && mouse_col < ccline.cmdspos % Columns + i) | |
2018 break; | |
2019 if (has_mbyte) | |
2020 { | |
2021 /* Count ">" for double-wide char that doesn't fit. */ | |
2022 correct_cmdspos(ccline.cmdpos, i); | |
474 | 2023 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 2024 + ccline.cmdpos) - 1; |
2025 } | |
2026 ccline.cmdspos += i; | |
2027 } | |
2028 goto cmdline_not_changed; | |
2029 | |
2030 /* Mouse scroll wheel: ignored here */ | |
2031 case K_MOUSEDOWN: | |
2032 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2033 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2034 case K_MOUSERIGHT: |
7 | 2035 /* Alternate buttons ignored here */ |
2036 case K_X1MOUSE: | |
2037 case K_X1DRAG: | |
2038 case K_X1RELEASE: | |
2039 case K_X2MOUSE: | |
2040 case K_X2DRAG: | |
2041 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
2042 case K_MOUSEMOVE: |
7 | 2043 goto cmdline_not_changed; |
2044 | |
2045 #endif /* FEAT_MOUSE */ | |
2046 | |
2047 #ifdef FEAT_GUI | |
2048 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
2049 case K_LEFTRELEASE_NM: | |
2050 goto cmdline_not_changed; | |
2051 | |
2052 case K_VER_SCROLLBAR: | |
540 | 2053 if (msg_scrolled == 0) |
7 | 2054 { |
2055 gui_do_scroll(); | |
2056 redrawcmd(); | |
2057 } | |
2058 goto cmdline_not_changed; | |
2059 | |
2060 case K_HOR_SCROLLBAR: | |
540 | 2061 if (msg_scrolled == 0) |
7 | 2062 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2063 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 2064 redrawcmd(); |
2065 } | |
2066 goto cmdline_not_changed; | |
2067 #endif | |
692 | 2068 #ifdef FEAT_GUI_TABLINE |
2069 case K_TABLINE: | |
2070 case K_TABMENU: | |
2071 /* Don't want to change any tabs here. Make sure the same tab | |
2072 * is still selected. */ | |
2073 if (gui_use_tabline()) | |
2074 gui_mch_set_curtab(tabpage_index(curtab)); | |
2075 goto cmdline_not_changed; | |
2076 #endif | |
2077 | |
7 | 2078 case K_SELECT: /* end of Select mode mapping - ignore */ |
2079 goto cmdline_not_changed; | |
2080 | |
2081 case Ctrl_B: /* begin of command line */ | |
2082 case K_HOME: | |
2083 case K_KHOME: | |
2084 case K_S_HOME: | |
2085 case K_C_HOME: | |
2086 ccline.cmdpos = 0; | |
2087 set_cmdspos(); | |
2088 goto cmdline_not_changed; | |
2089 | |
2090 case Ctrl_E: /* end of command line */ | |
2091 case K_END: | |
2092 case K_KEND: | |
2093 case K_S_END: | |
2094 case K_C_END: | |
2095 ccline.cmdpos = ccline.cmdlen; | |
2096 set_cmdspos_cursor(); | |
2097 goto cmdline_not_changed; | |
2098 | |
2099 case Ctrl_A: /* all matches */ | |
3961 | 2100 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2101 break; |
2102 goto cmdline_changed; | |
2103 | |
772 | 2104 case Ctrl_L: |
2105 #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
|
2106 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2107 goto cmdline_not_changed; |
2108 #endif | |
2109 | |
2110 /* completion: longest common part */ | |
3961 | 2111 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2112 break; |
2113 goto cmdline_changed; | |
2114 | |
2115 case Ctrl_N: /* next match */ | |
2116 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2117 if (xpc.xp_numfiles > 0) |
7 | 2118 { |
3961 | 2119 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2120 0, firstc != '@') == FAIL) | |
7 | 2121 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2122 goto cmdline_not_changed; |
7 | 2123 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2124 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2125 /* FALLTHROUGH */ |
7 | 2126 case K_UP: |
2127 case K_DOWN: | |
2128 case K_S_UP: | |
2129 case K_S_DOWN: | |
2130 case K_PAGEUP: | |
2131 case K_KPAGEUP: | |
2132 case K_PAGEDOWN: | |
2133 case K_KPAGEDOWN: | |
2134 if (hislen == 0 || firstc == NUL) /* no history */ | |
2135 goto cmdline_not_changed; | |
2136 | |
2137 i = hiscnt; | |
2138 | |
2139 /* save current command string so it can be restored later */ | |
2140 if (lookfor == NULL) | |
2141 { | |
2142 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2143 goto cmdline_not_changed; | |
2144 lookfor[ccline.cmdpos] = NUL; | |
2145 } | |
2146 | |
2147 j = (int)STRLEN(lookfor); | |
2148 for (;;) | |
2149 { | |
2150 /* one step backwards */ | |
230 | 2151 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2152 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2153 { |
2154 if (hiscnt == hislen) /* first time */ | |
2155 hiscnt = hisidx[histype]; | |
2156 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2157 hiscnt = hislen - 1; | |
2158 else if (hiscnt != hisidx[histype] + 1) | |
2159 --hiscnt; | |
2160 else /* at top of list */ | |
2161 { | |
2162 hiscnt = i; | |
2163 break; | |
2164 } | |
2165 } | |
2166 else /* one step forwards */ | |
2167 { | |
2168 /* on last entry, clear the line */ | |
2169 if (hiscnt == hisidx[histype]) | |
2170 { | |
2171 hiscnt = hislen; | |
2172 break; | |
2173 } | |
2174 | |
2175 /* not on a history line, nothing to do */ | |
2176 if (hiscnt == hislen) | |
2177 break; | |
2178 if (hiscnt == hislen - 1) /* wrap around */ | |
2179 hiscnt = 0; | |
2180 else | |
2181 ++hiscnt; | |
2182 } | |
2183 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2184 { | |
2185 hiscnt = i; | |
2186 break; | |
2187 } | |
230 | 2188 if ((c != K_UP && c != K_DOWN) |
180 | 2189 || hiscnt == i |
7 | 2190 || STRNCMP(history[histype][hiscnt].hisstr, |
2191 lookfor, (size_t)j) == 0) | |
2192 break; | |
2193 } | |
2194 | |
2195 if (hiscnt != i) /* jumped to other entry */ | |
2196 { | |
2197 char_u *p; | |
2198 int len; | |
2199 int old_firstc; | |
2200 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2201 VIM_CLEAR(ccline.cmdbuff); |
1718 | 2202 xpc.xp_context = EXPAND_NOTHING; |
7 | 2203 if (hiscnt == hislen) |
2204 p = lookfor; /* back to the old one */ | |
2205 else | |
2206 p = history[histype][hiscnt].hisstr; | |
2207 | |
2208 if (histype == HIST_SEARCH | |
2209 && p != lookfor | |
2210 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2211 { | |
2212 /* Correct for the separator character used when | |
2213 * adding the history entry vs the one used now. | |
2214 * First loop: count length. | |
2215 * Second loop: copy the characters. */ | |
2216 for (i = 0; i <= 1; ++i) | |
2217 { | |
2218 len = 0; | |
2219 for (j = 0; p[j] != NUL; ++j) | |
2220 { | |
2221 /* Replace old sep with new sep, unless it is | |
2222 * escaped. */ | |
2223 if (p[j] == old_firstc | |
2224 && (j == 0 || p[j - 1] != '\\')) | |
2225 { | |
2226 if (i > 0) | |
2227 ccline.cmdbuff[len] = firstc; | |
2228 } | |
2229 else | |
2230 { | |
2231 /* Escape new sep, unless it is already | |
2232 * escaped. */ | |
2233 if (p[j] == firstc | |
2234 && (j == 0 || p[j - 1] != '\\')) | |
2235 { | |
2236 if (i > 0) | |
2237 ccline.cmdbuff[len] = '\\'; | |
2238 ++len; | |
2239 } | |
2240 if (i > 0) | |
2241 ccline.cmdbuff[len] = p[j]; | |
2242 } | |
2243 ++len; | |
2244 } | |
2245 if (i == 0) | |
2246 { | |
2247 alloc_cmdbuff(len); | |
2248 if (ccline.cmdbuff == NULL) | |
2249 goto returncmd; | |
2250 } | |
2251 } | |
2252 ccline.cmdbuff[len] = NUL; | |
2253 } | |
2254 else | |
2255 { | |
2256 alloc_cmdbuff((int)STRLEN(p)); | |
2257 if (ccline.cmdbuff == NULL) | |
2258 goto returncmd; | |
2259 STRCPY(ccline.cmdbuff, p); | |
2260 } | |
2261 | |
2262 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2263 redrawcmd(); | |
2264 goto cmdline_changed; | |
2265 } | |
2266 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2267 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2268 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2269 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2270 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2271 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2272 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
|
2273 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
|
2274 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
|
2275 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2276 break; |
7 | 2277 #endif |
2278 | |
2279 case Ctrl_V: | |
2280 case Ctrl_Q: | |
2281 #ifdef FEAT_MOUSE | |
2282 ignore_drag_release = TRUE; | |
2283 #endif | |
2284 putcmdline('^', TRUE); | |
2285 c = get_literal(); /* get next (two) character(s) */ | |
2286 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
|
2287 extra_char = NUL; |
7 | 2288 /* may need to remove ^ when composing char was typed */ |
2289 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2290 { | |
2291 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2292 msg_putchar(' '); | |
2293 cursorcmd(); | |
2294 } | |
2295 break; | |
2296 | |
2297 #ifdef FEAT_DIGRAPHS | |
2298 case Ctrl_K: | |
2299 #ifdef FEAT_MOUSE | |
2300 ignore_drag_release = TRUE; | |
2301 #endif | |
2302 putcmdline('?', TRUE); | |
2303 #ifdef USE_ON_FLY_SCROLL | |
2304 dont_scroll = TRUE; /* disallow scrolling here */ | |
2305 #endif | |
2306 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
|
2307 extra_char = NUL; |
7 | 2308 if (c != NUL) |
2309 break; | |
2310 | |
2311 redrawcmd(); | |
2312 goto cmdline_not_changed; | |
2313 #endif /* FEAT_DIGRAPHS */ | |
2314 | |
2315 #ifdef FEAT_RIGHTLEFT | |
2316 case Ctrl__: /* CTRL-_: switch language mode */ | |
2317 if (!p_ari) | |
2318 break; | |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2319 cmd_hkmap = !cmd_hkmap; |
7 | 2320 goto cmdline_not_changed; |
2321 #endif | |
2322 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2323 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
|
2324 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
|
2325 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
|
2326 |
7 | 2327 default: |
2328 #ifdef UNIX | |
2329 if (c == intr_char) | |
2330 { | |
2331 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2332 putting it in history */ | |
2333 goto returncmd; /* back to Normal mode */ | |
2334 } | |
2335 #endif | |
2336 /* | |
2337 * Normal character with no special meaning. Just set mod_mask | |
2338 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2339 * the string <S-Space>. This should only happen after ^V. | |
2340 */ | |
2341 if (!IS_SPECIAL(c)) | |
2342 mod_mask = 0x0; | |
2343 break; | |
2344 } | |
2345 /* | |
2346 * End of switch on command line character. | |
2347 * We come here if we have a normal character. | |
2348 */ | |
2349 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2350 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2351 && (ccheck_abbr( |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2352 // Add ABBR_OFF for characters above 0x100, this is |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2353 // what check_abbr() expects. |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2354 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : c) |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2355 || c == Ctrl_RSB)) |
7 | 2356 goto cmdline_changed; |
2357 | |
2358 /* | |
2359 * put the character in the command line | |
2360 */ | |
2361 if (IS_SPECIAL(c) || mod_mask != 0) | |
2362 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2363 else | |
2364 { | |
2365 if (has_mbyte) | |
2366 { | |
2367 j = (*mb_char2bytes)(c, IObuff); | |
2368 IObuff[j] = NUL; /* exclude composing chars */ | |
2369 put_on_cmdline(IObuff, j, TRUE); | |
2370 } | |
2371 else | |
2372 { | |
2373 IObuff[0] = c; | |
2374 put_on_cmdline(IObuff, 1, TRUE); | |
2375 } | |
2376 } | |
2377 goto cmdline_changed; | |
2378 | |
2379 /* | |
2380 * This part implements incremental searches for "/" and "?" | |
2381 * Jump to cmdline_not_changed when a character has been read but the command | |
2382 * line did not change. Then we only search and redraw if something changed in | |
2383 * the past. | |
2384 * Jump to cmdline_changed when the command line did change. | |
2385 * (Sorry for the goto's, I know it is ugly). | |
2386 */ | |
2387 cmdline_not_changed: | |
2388 #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
|
2389 if (!is_state.incsearch_postponed) |
7 | 2390 continue; |
2391 #endif | |
2392 | |
2393 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
|
2394 /* 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
|
2395 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
|
2396 |
7 | 2397 #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
|
2398 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2399 #endif |
2400 | |
2401 #ifdef FEAT_RIGHTLEFT | |
2402 if (cmdmsg_rl | |
2403 # ifdef FEAT_ARABIC | |
17155
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2404 || (p_arshape && !p_tbidi |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2405 && cmdline_has_arabic(0, ccline.cmdlen)) |
7 | 2406 # endif |
2407 ) | |
2408 /* Always redraw the whole command line to fix shaping and | |
3374 | 2409 * right-left typing. Not efficient, but it works. |
2410 * Do it only when there are no characters left to read | |
2411 * to avoid useless intermediate redraws. */ | |
2412 if (vpeekc() == NUL) | |
2413 redrawcmd(); | |
7 | 2414 #endif |
2415 } | |
2416 | |
2417 returncmd: | |
2418 | |
2419 #ifdef FEAT_RIGHTLEFT | |
2420 cmdmsg_rl = FALSE; | |
2421 #endif | |
2422 | |
2423 ExpandCleanup(&xpc); | |
1718 | 2424 ccline.xpc = NULL; |
7 | 2425 |
2426 #ifdef FEAT_SEARCH_EXTRA | |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
2427 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2428 #endif |
2429 | |
2430 if (ccline.cmdbuff != NULL) | |
2431 { | |
2432 /* | |
2433 * Put line in history buffer (":" and "=" only when it was typed). | |
2434 */ | |
2435 #ifdef FEAT_CMDHIST | |
2436 if (ccline.cmdlen && firstc != NUL | |
2437 && (some_key_typed || histype == HIST_SEARCH)) | |
2438 { | |
2439 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2440 histype == HIST_SEARCH ? firstc : NUL); | |
2441 if (firstc == ':') | |
2442 { | |
2443 vim_free(new_last_cmdline); | |
2444 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2445 } | |
2446 } | |
2447 #endif | |
2448 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2449 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
|
2450 abandon_cmdline(); |
7 | 2451 } |
2452 | |
2453 /* | |
2454 * If the screen was shifted up, redraw the whole screen (later). | |
2455 * If the line is too long, clear it, so ruler and shown command do | |
2456 * not get printed in the middle of it. | |
2457 */ | |
2458 msg_check(); | |
2459 msg_scroll = save_msg_scroll; | |
2460 redir_off = FALSE; | |
2461 | |
2462 /* When the command line was typed, no need for a wait-return prompt. */ | |
2463 if (some_key_typed) | |
2464 need_wait_return = FALSE; | |
2465 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2466 /* 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
|
2467 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
|
2468 |
7 | 2469 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2470 #ifdef HAVE_INPUT_METHOD |
7 | 2471 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2472 im_save_status(b_im_ptr); | |
2473 im_set_active(FALSE); | |
2474 #endif | |
2475 #ifdef FEAT_MOUSE | |
2476 setmouse(); | |
2477 #endif | |
2478 #ifdef CURSOR_SHAPE | |
2479 ui_cursor_shape(); /* may show different cursor shape */ | |
2480 #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
|
2481 sb_text_end_cmdline(); |
7 | 2482 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2483 theend: |
95 | 2484 { |
2485 char_u *p = ccline.cmdbuff; | |
2486 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2487 if (did_save_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2488 restore_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2489 else |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2490 ccline.cmdbuff = NULL; |
95 | 2491 return p; |
2492 } | |
7 | 2493 } |
2494 | |
2495 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2496 /* | |
2497 * Get a command line with a prompt. | |
2498 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2499 * f_input() when evaluating an expression from CTRL-R =). | |
2500 * Returns the command line in allocated memory, or NULL. | |
2501 */ | |
2502 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2503 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2504 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2505 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2506 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2507 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2508 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2509 { |
2510 char_u *s; | |
2511 struct cmdline_info save_ccline; | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2512 int did_save_ccline = FALSE; |
7 | 2513 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
|
2514 int msg_silent_save = msg_silent; |
7 | 2515 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2516 if (ccline.cmdbuff != NULL) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2517 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2518 // Save the values of the current cmdline and restore them below. |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2519 save_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2520 did_save_ccline = TRUE; |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2521 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2522 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2523 vim_memset(&ccline, 0, sizeof(struct cmdline_info)); |
7 | 2524 ccline.cmdprompt = prompt; |
2525 ccline.cmdattr = attr; | |
531 | 2526 # ifdef FEAT_EVAL |
2527 ccline.xp_context = xp_context; | |
2528 ccline.xp_arg = xp_arg; | |
2529 ccline.input_fn = (firstc == '@'); | |
2530 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2531 msg_silent = 0; |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2532 s = getcmdline_int(firstc, 1L, 0, FALSE); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2533 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2534 if (did_save_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2535 restore_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2536 |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2537 msg_silent = msg_silent_save; |
3020 | 2538 /* Restore msg_col, the prompt from input() may have changed it. |
2539 * But only if called recursively and the commandline is therefore being | |
2540 * restored to an old one; if not, the input() prompt stays on the screen, | |
2541 * so we need its modified msg_col left intact. */ | |
2542 if (ccline.cmdbuff != NULL) | |
2543 msg_col = msg_col_save; | |
7 | 2544 |
2545 return s; | |
2546 } | |
2547 #endif | |
2548 | |
632 | 2549 /* |
634 | 2550 * Return TRUE when the text must not be changed and we can't switch to |
2551 * another window or buffer. Used when editing the command line, evaluating | |
2552 * 'balloonexpr', etc. | |
632 | 2553 */ |
2554 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2555 text_locked(void) |
632 | 2556 { |
2557 #ifdef FEAT_CMDWIN | |
2558 if (cmdwin_type != 0) | |
2559 return TRUE; | |
2560 #endif | |
634 | 2561 return textlock != 0; |
632 | 2562 } |
2563 | |
2564 /* | |
2565 * Give an error message for a command that isn't allowed while the cmdline | |
2566 * window is open or editing the cmdline in another way. | |
2567 */ | |
2568 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2569 text_locked_msg(void) |
632 | 2570 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
2571 emsg(_(get_text_locked_msg())); |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2572 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2573 |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
2574 char * |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2575 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2576 { |
632 | 2577 #ifdef FEAT_CMDWIN |
2578 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2579 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2580 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2581 return e_secure; |
632 | 2582 } |
2583 | |
819 | 2584 /* |
1834 | 2585 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2586 * and give an error message. | |
819 | 2587 */ |
2588 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2589 curbuf_locked(void) |
819 | 2590 { |
2591 if (curbuf_lock > 0) | |
2592 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
2593 emsg(_("E788: Not allowed to edit another buffer now")); |
819 | 2594 return TRUE; |
2595 } | |
1834 | 2596 return allbuf_locked(); |
2597 } | |
2598 | |
2599 /* | |
2600 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2601 * message. | |
2602 */ | |
2603 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2604 allbuf_locked(void) |
1834 | 2605 { |
2606 if (allbuf_lock > 0) | |
2607 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
2608 emsg(_("E811: Not allowed to change buffer information now")); |
1834 | 2609 return TRUE; |
2610 } | |
819 | 2611 return FALSE; |
2612 } | |
2613 | |
7 | 2614 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2615 cmdline_charsize(int idx) |
7 | 2616 { |
2617 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2618 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2619 return 1; | |
2620 #endif | |
2621 return ptr2cells(ccline.cmdbuff + idx); | |
2622 } | |
2623 | |
2624 /* | |
2625 * Compute the offset of the cursor on the command line for the prompt and | |
2626 * indent. | |
2627 */ | |
2628 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2629 set_cmdspos(void) |
7 | 2630 { |
531 | 2631 if (ccline.cmdfirstc != NUL) |
7 | 2632 ccline.cmdspos = 1 + ccline.cmdindent; |
2633 else | |
2634 ccline.cmdspos = 0 + ccline.cmdindent; | |
2635 } | |
2636 | |
2637 /* | |
2638 * Compute the screen position for the cursor on the command line. | |
2639 */ | |
2640 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2641 set_cmdspos_cursor(void) |
7 | 2642 { |
2643 int i, m, c; | |
2644 | |
2645 set_cmdspos(); | |
2646 if (KeyTyped) | |
534 | 2647 { |
7 | 2648 m = Columns * Rows; |
534 | 2649 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2650 m = MAXCOL; | |
2651 } | |
7 | 2652 else |
2653 m = MAXCOL; | |
2654 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2655 { | |
2656 c = cmdline_charsize(i); | |
2657 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2658 if (has_mbyte) | |
2659 correct_cmdspos(i, c); | |
1612 | 2660 /* If the cmdline doesn't fit, show cursor on last visible char. |
2661 * Don't move the cursor itself, so we can still append. */ | |
7 | 2662 if ((ccline.cmdspos += c) >= m) |
2663 { | |
2664 ccline.cmdspos -= c; | |
2665 break; | |
2666 } | |
2667 if (has_mbyte) | |
474 | 2668 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2669 } |
2670 } | |
2671 | |
2672 /* | |
2673 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2674 * character that doesn't fit, so that a ">" must be displayed. | |
2675 */ | |
2676 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2677 correct_cmdspos(int idx, int cells) |
7 | 2678 { |
474 | 2679 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2680 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2681 && ccline.cmdspos % Columns + cells > Columns) | |
2682 ccline.cmdspos++; | |
2683 } | |
2684 | |
2685 /* | |
2686 * Get an Ex command line for the ":" command. | |
2687 */ | |
2688 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2689 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2690 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2691 void *cookie UNUSED, |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
2692 int indent, /* indent for inside conditionals */ |
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
2693 int do_concat) |
7 | 2694 { |
2695 /* When executing a register, remove ':' that's in front of each line. */ | |
2696 if (exec_from_reg && vpeekc() == ':') | |
2697 (void)vgetc(); | |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
2698 return getcmdline(c, 1L, indent, do_concat); |
7 | 2699 } |
2700 | |
2701 /* | |
2702 * Get an Ex command line for Ex mode. | |
2703 * In Ex mode we only use the OS supplied line editing features and no | |
2704 * mappings or abbreviations. | |
168 | 2705 * Returns a string in allocated memory or NULL. |
7 | 2706 */ |
2707 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2708 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2709 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2710 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2711 void *cookie UNUSED, |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
2712 int indent, /* indent for inside conditionals */ |
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
2713 int do_concat UNUSED) |
7 | 2714 { |
168 | 2715 garray_T line_ga; |
2716 char_u *pend; | |
2717 int startcol = 0; | |
1329 | 2718 int c1 = 0; |
168 | 2719 int escaped = FALSE; /* CTRL-V typed */ |
2720 int vcol = 0; | |
2721 char_u *p; | |
1329 | 2722 int prev_char; |
5966 | 2723 int len; |
7 | 2724 |
2725 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2726 * confuses the system function that computes tabstops. */ | |
2727 cursor_on(); | |
2728 | |
2729 /* always start in column 0; write a newline if necessary */ | |
2730 compute_cmdrow(); | |
168 | 2731 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2732 msg_putchar('\n'); |
168 | 2733 if (promptc == ':') |
7 | 2734 { |
164 | 2735 /* indent that is only displayed, not in the line itself */ |
168 | 2736 if (p_prompt) |
2737 msg_putchar(':'); | |
7 | 2738 while (indent-- > 0) |
2739 msg_putchar(' '); | |
2740 startcol = msg_col; | |
2741 } | |
2742 | |
2743 ga_init2(&line_ga, 1, 30); | |
2744 | |
164 | 2745 /* autoindent for :insert and :append is in the line itself */ |
168 | 2746 if (promptc <= 0) |
164 | 2747 { |
2748 vcol = indent; | |
2749 while (indent >= 8) | |
2750 { | |
2751 ga_append(&line_ga, TAB); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
2752 msg_puts(" "); |
164 | 2753 indent -= 8; |
2754 } | |
2755 while (indent-- > 0) | |
2756 { | |
2757 ga_append(&line_ga, ' '); | |
2758 msg_putchar(' '); | |
2759 } | |
2760 } | |
168 | 2761 ++no_mapping; |
2762 ++allow_keys; | |
164 | 2763 |
7 | 2764 /* |
2765 * Get the line, one character at a time. | |
2766 */ | |
2767 got_int = FALSE; | |
168 | 2768 while (!got_int) |
7 | 2769 { |
6733
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2770 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
|
2771 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
|
2772 |
7 | 2773 if (ga_grow(&line_ga, 40) == FAIL) |
2774 break; | |
2775 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2776 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2777 * 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
|
2778 */ |
1329 | 2779 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
|
2780 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2781 /* 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
|
2782 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
|
2783 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
|
2784 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2785 c1 = vgetc(); |
7 | 2786 |
2787 /* | |
168 | 2788 * Handle line editing. |
2789 * Previously this was left to the system, putting the terminal in | |
2790 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2791 */ |
168 | 2792 if (got_int) |
2793 { | |
2794 msg_putchar('\n'); | |
2795 break; | |
2796 } | |
2797 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2798 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
|
2799 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2800 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
|
2801 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
|
2802 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2803 |
168 | 2804 if (!escaped) |
7 | 2805 { |
168 | 2806 /* CR typed means "enter", which is NL */ |
2807 if (c1 == '\r') | |
2808 c1 = '\n'; | |
2809 | |
2810 if (c1 == BS || c1 == K_BS | |
2811 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2812 { |
168 | 2813 if (line_ga.ga_len > 0) |
2814 { | |
5966 | 2815 if (has_mbyte) |
2816 { | |
2817 p = (char_u *)line_ga.ga_data; | |
2818 p[line_ga.ga_len] = NUL; | |
2819 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2820 line_ga.ga_len -= len; | |
2821 } | |
2822 else | |
2823 --line_ga.ga_len; | |
168 | 2824 goto redraw; |
2825 } | |
2826 continue; | |
7 | 2827 } |
2828 | |
168 | 2829 if (c1 == Ctrl_U) |
7 | 2830 { |
168 | 2831 msg_col = startcol; |
2832 msg_clr_eos(); | |
2833 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
|
2834 goto redraw; |
168 | 2835 } |
2836 | |
2837 if (c1 == Ctrl_T) | |
2838 { | |
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
|
2839 sw = get_sw_value(curbuf); |
168 | 2840 p = (char_u *)line_ga.ga_data; |
2841 p[line_ga.ga_len] = NUL; | |
5995 | 2842 indent = get_indent_str(p, 8, FALSE); |
3740 | 2843 indent += sw - indent % sw; |
168 | 2844 add_indent: |
5995 | 2845 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2846 { |
7009 | 2847 (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
|
2848 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
|
2849 s = skipwhite(p); |
168 | 2850 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2851 *s = ' '; | |
2852 ++line_ga.ga_len; | |
7 | 2853 } |
168 | 2854 redraw: |
2855 /* redraw the line */ | |
2856 msg_col = startcol; | |
2857 vcol = 0; | |
5966 | 2858 p = (char_u *)line_ga.ga_data; |
2859 p[line_ga.ga_len] = NUL; | |
2860 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2861 { |
168 | 2862 if (*p == TAB) |
7 | 2863 { |
168 | 2864 do |
2865 msg_putchar(' '); | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2866 while (++vcol % 8); |
5966 | 2867 ++p; |
7 | 2868 } |
168 | 2869 else |
164 | 2870 { |
5966 | 2871 len = MB_PTR2LEN(p); |
2872 msg_outtrans_len(p, len); | |
2873 vcol += ptr2cells(p); | |
2874 p += len; | |
7 | 2875 } |
2876 } | |
168 | 2877 msg_clr_eos(); |
1329 | 2878 windgoto(msg_row, msg_col); |
168 | 2879 continue; |
2880 } | |
2881 | |
2882 if (c1 == Ctrl_D) | |
2883 { | |
2884 /* Delete one shiftwidth. */ | |
2885 p = (char_u *)line_ga.ga_data; | |
2886 if (prev_char == '0' || prev_char == '^') | |
7 | 2887 { |
168 | 2888 if (prev_char == '^') |
2889 ex_keep_indent = TRUE; | |
2890 indent = 0; | |
2891 p[--line_ga.ga_len] = NUL; | |
7 | 2892 } |
2893 else | |
2894 { | |
168 | 2895 p[line_ga.ga_len] = NUL; |
5995 | 2896 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
|
2897 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
|
2898 { |
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
|
2899 --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
|
2900 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
|
2901 } |
168 | 2902 } |
5995 | 2903 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2904 { |
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
|
2905 s = skipwhite(p); |
168 | 2906 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2907 --line_ga.ga_len; | |
7 | 2908 } |
168 | 2909 goto add_indent; |
2910 } | |
2911 | |
2912 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2913 { | |
2914 escaped = TRUE; | |
2915 continue; | |
7 | 2916 } |
168 | 2917 |
2918 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2919 if (IS_SPECIAL(c1)) | |
2920 continue; | |
7 | 2921 } |
168 | 2922 |
2923 if (IS_SPECIAL(c1)) | |
2924 c1 = '?'; | |
5966 | 2925 if (has_mbyte) |
2926 len = (*mb_char2bytes)(c1, | |
2927 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2928 else | |
2929 { | |
2930 len = 1; | |
2931 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2932 } | |
168 | 2933 if (c1 == '\n') |
2934 msg_putchar('\n'); | |
2935 else if (c1 == TAB) | |
2936 { | |
2937 /* Don't use chartabsize(), 'ts' can be different */ | |
2938 do | |
2939 msg_putchar(' '); | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2940 while (++vcol % 8); |
168 | 2941 } |
7 | 2942 else |
2943 { | |
168 | 2944 msg_outtrans_len( |
5966 | 2945 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2946 vcol += char2cells(c1); |
7 | 2947 } |
5966 | 2948 line_ga.ga_len += len; |
168 | 2949 escaped = FALSE; |
2950 | |
2951 windgoto(msg_row, msg_col); | |
164 | 2952 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2953 |
2590 | 2954 /* We are done when a NL is entered, but not when it comes after an |
2955 * odd number of backslashes, that results in a NUL. */ | |
2956 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2957 { |
2590 | 2958 int bcount = 0; |
2959 | |
2960 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2961 ++bcount; | |
2962 | |
2963 if (bcount > 0) | |
2964 { | |
2965 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2966 * "\NL", etc. */ | |
2967 line_ga.ga_len -= (bcount + 1) / 2; | |
2968 pend -= (bcount + 1) / 2; | |
2969 pend[-1] = '\n'; | |
2970 } | |
2971 | |
2972 if ((bcount & 1) == 0) | |
2973 { | |
2974 --line_ga.ga_len; | |
2975 --pend; | |
2976 *pend = NUL; | |
2977 break; | |
2978 } | |
7 | 2979 } |
2980 } | |
2981 | |
168 | 2982 --no_mapping; |
2983 --allow_keys; | |
2984 | |
7 | 2985 /* make following messages go to the next line */ |
2986 msg_didout = FALSE; | |
2987 msg_col = 0; | |
2988 if (msg_row < Rows - 1) | |
2989 ++msg_row; | |
2990 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2991 | |
2992 if (got_int) | |
2993 ga_clear(&line_ga); | |
2994 | |
2995 return (char_u *)line_ga.ga_data; | |
2996 } | |
2997 | |
502 | 2998 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2999 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 3000 /* |
3001 * Return TRUE if ccline.overstrike is on. | |
3002 */ | |
3003 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3004 cmdline_overstrike(void) |
7 | 3005 { |
3006 return ccline.overstrike; | |
3007 } | |
3008 | |
3009 /* | |
3010 * Return TRUE if the cursor is at the end of the cmdline. | |
3011 */ | |
3012 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3013 cmdline_at_end(void) |
7 | 3014 { |
3015 return (ccline.cmdpos >= ccline.cmdlen); | |
3016 } | |
3017 #endif | |
3018 | |
574 | 3019 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 3020 /* |
3021 * Return the virtual column number at the current cursor position. | |
3022 * This is used by the IM code to obtain the start of the preedit string. | |
3023 */ | |
3024 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3025 cmdline_getvcol_cursor(void) |
7 | 3026 { |
3027 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
3028 return MAXCOL; | |
3029 | |
3030 if (has_mbyte) | |
3031 { | |
3032 colnr_T col; | |
3033 int i = 0; | |
3034 | |
3035 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 3036 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 3037 |
3038 return col; | |
3039 } | |
3040 else | |
3041 return ccline.cmdpos; | |
3042 } | |
3043 #endif | |
3044 | |
3045 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
3046 /* | |
3047 * If part of the command line is an IM preedit string, redraw it with | |
3048 * IM feedback attributes. The cursor position is restored after drawing. | |
3049 */ | |
3050 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3051 redrawcmd_preedit(void) |
7 | 3052 { |
3053 if ((State & CMDLINE) | |
3054 && xic != NULL | |
976 | 3055 /* && im_get_status() doesn't work when using SCIM */ |
7 | 3056 && !p_imdisable |
3057 && im_is_preediting()) | |
3058 { | |
3059 int cmdpos = 0; | |
3060 int cmdspos; | |
3061 int old_row; | |
3062 int old_col; | |
3063 colnr_T col; | |
3064 | |
3065 old_row = msg_row; | |
3066 old_col = msg_col; | |
531 | 3067 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 3068 |
3069 if (has_mbyte) | |
3070 { | |
3071 for (col = 0; col < preedit_start_col | |
3072 && cmdpos < ccline.cmdlen; ++col) | |
3073 { | |
3074 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 3075 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3076 } |
3077 } | |
3078 else | |
3079 { | |
3080 cmdspos += preedit_start_col; | |
3081 cmdpos += preedit_start_col; | |
3082 } | |
3083 | |
3084 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3085 msg_col = cmdspos % (int)Columns; | |
3086 if (msg_row >= Rows) | |
3087 msg_row = Rows - 1; | |
3088 | |
3089 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3090 { | |
3091 int char_len; | |
3092 int char_attr; | |
3093 | |
3094 char_attr = im_get_feedback_attr(col); | |
3095 if (char_attr < 0) | |
3096 break; /* end of preedit string */ | |
3097 | |
3098 if (has_mbyte) | |
474 | 3099 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3100 else |
3101 char_len = 1; | |
3102 | |
3103 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3104 cmdpos += char_len; | |
3105 } | |
3106 | |
3107 msg_row = old_row; | |
3108 msg_col = old_col; | |
3109 } | |
3110 } | |
3111 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3112 | |
3113 /* | |
3114 * Allocate a new command line buffer. | |
3115 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3116 */ | |
3117 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3118 alloc_cmdbuff(int len) |
7 | 3119 { |
3120 /* | |
3121 * give some extra space to avoid having to allocate all the time | |
3122 */ | |
3123 if (len < 80) | |
3124 len = 100; | |
3125 else | |
3126 len += 20; | |
3127 | |
3128 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3129 ccline.cmdbufflen = len; | |
3130 } | |
3131 | |
3132 /* | |
3133 * Re-allocate the command line to length len + something extra. | |
3134 * return FAIL for failure, OK otherwise | |
3135 */ | |
3136 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3137 realloc_cmdbuff(int len) |
7 | 3138 { |
3139 char_u *p; | |
3140 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3141 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3142 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
|
3143 |
7 | 3144 p = ccline.cmdbuff; |
3145 alloc_cmdbuff(len); /* will get some more */ | |
3146 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3147 { | |
3148 ccline.cmdbuff = p; /* keep the old one */ | |
3149 return FAIL; | |
3150 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3151 /* 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
|
3152 * 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
|
3153 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
|
3154 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3155 vim_free(p); |
1718 | 3156 |
3157 if (ccline.xpc != NULL | |
3158 && ccline.xpc->xp_pattern != NULL | |
3159 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3160 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3161 { | |
1754 | 3162 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3163 |
3164 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3165 * to point into the newly allocated memory. */ | |
3166 if (i >= 0 && i <= ccline.cmdlen) | |
3167 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3168 } | |
3169 | |
7 | 3170 return OK; |
3171 } | |
3172 | |
359 | 3173 #if defined(FEAT_ARABIC) || defined(PROTO) |
3174 static char_u *arshape_buf = NULL; | |
3175 | |
3176 # if defined(EXITFREE) || defined(PROTO) | |
3177 void | |
17266
a9556c0ba457
patch 8.1.1632: build with EXITFREE but without +arabic fails
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
3178 free_arshape_buf(void) |
359 | 3179 { |
3180 vim_free(arshape_buf); | |
3181 } | |
3182 # endif | |
3183 #endif | |
3184 | |
7 | 3185 /* |
3186 * Draw part of the cmdline at the current cursor position. But draw stars | |
3187 * when cmdline_star is TRUE. | |
3188 */ | |
3189 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3190 draw_cmdline(int start, int len) |
7 | 3191 { |
3192 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3193 int i; | |
3194 | |
3195 if (cmdline_star > 0) | |
3196 for (i = 0; i < len; ++i) | |
3197 { | |
3198 msg_putchar('*'); | |
3199 if (has_mbyte) | |
474 | 3200 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3201 } |
3202 else | |
3203 #endif | |
3204 #ifdef FEAT_ARABIC | |
17155
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3205 if (p_arshape && !p_tbidi && cmdline_has_arabic(start, len)) |
7 | 3206 { |
3207 static int buflen = 0; | |
3208 char_u *p; | |
3209 int j; | |
3210 int newlen = 0; | |
3211 int mb_l; | |
719 | 3212 int pc, pc1 = 0; |
7 | 3213 int prev_c = 0; |
3214 int prev_c1 = 0; | |
714 | 3215 int u8c; |
3216 int u8cc[MAX_MCO]; | |
7 | 3217 int nc = 0; |
3218 | |
3219 /* | |
3220 * Do arabic shaping into a temporary buffer. This is very | |
3221 * inefficient! | |
3222 */ | |
507 | 3223 if (len * 2 + 2 > buflen) |
7 | 3224 { |
3225 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3226 * alloc()/free() calls. */ | |
359 | 3227 vim_free(arshape_buf); |
507 | 3228 buflen = len * 2 + 2; |
359 | 3229 arshape_buf = alloc(buflen); |
3230 if (arshape_buf == NULL) | |
7 | 3231 return; /* out of memory */ |
3232 } | |
3233 | |
507 | 3234 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3235 { | |
3236 /* Prepend a space to draw the leading composing char on. */ | |
3237 arshape_buf[0] = ' '; | |
3238 newlen = 1; | |
3239 } | |
3240 | |
7 | 3241 for (j = start; j < start + len; j += mb_l) |
3242 { | |
3243 p = ccline.cmdbuff + j; | |
714 | 3244 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3245 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3246 if (ARABIC_CHAR(u8c)) |
3247 { | |
3248 /* Do Arabic shaping. */ | |
3249 if (cmdmsg_rl) | |
3250 { | |
3251 /* displaying from right to left */ | |
3252 pc = prev_c; | |
3253 pc1 = prev_c1; | |
714 | 3254 prev_c1 = u8cc[0]; |
7 | 3255 if (j + mb_l >= start + len) |
3256 nc = NUL; | |
3257 else | |
3258 nc = utf_ptr2char(p + mb_l); | |
3259 } | |
3260 else | |
3261 { | |
3262 /* displaying from left to right */ | |
3263 if (j + mb_l >= start + len) | |
3264 pc = NUL; | |
3265 else | |
714 | 3266 { |
3267 int pcc[MAX_MCO]; | |
3268 | |
3269 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3270 start + len - j - mb_l); |
714 | 3271 pc1 = pcc[0]; |
3272 } | |
7 | 3273 nc = prev_c; |
3274 } | |
3275 prev_c = u8c; | |
3276 | |
714 | 3277 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3278 |
359 | 3279 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3280 if (u8cc[0] != 0) |
7 | 3281 { |
714 | 3282 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3283 if (u8cc[1] != 0) | |
3284 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3285 arshape_buf + newlen); |
7 | 3286 } |
3287 } | |
3288 else | |
3289 { | |
3290 prev_c = u8c; | |
359 | 3291 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3292 newlen += mb_l; |
3293 } | |
3294 } | |
3295 | |
359 | 3296 msg_outtrans_len(arshape_buf, newlen); |
7 | 3297 } |
3298 else | |
3299 #endif | |
3300 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3301 } | |
3302 | |
3303 /* | |
3304 * Put a character on the command line. Shifts the following text to the | |
3305 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3306 * "c" must be printable (fit in one display cell)! | |
3307 */ | |
3308 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3309 putcmdline(int c, int shift) |
7 | 3310 { |
3311 if (cmd_silent) | |
3312 return; | |
3313 msg_no_more = TRUE; | |
3314 msg_putchar(c); | |
3315 if (shift) | |
3316 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3317 msg_no_more = FALSE; | |
3318 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3319 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3320 extra_char_shift = shift; |
7 | 3321 } |
3322 | |
3323 /* | |
3324 * Undo a putcmdline(c, FALSE). | |
3325 */ | |
3326 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3327 unputcmdline(void) |
7 | 3328 { |
3329 if (cmd_silent) | |
3330 return; | |
3331 msg_no_more = TRUE; | |
3332 if (ccline.cmdlen == ccline.cmdpos) | |
3333 msg_putchar(' '); | |
3558 | 3334 else if (has_mbyte) |
3335 draw_cmdline(ccline.cmdpos, | |
3336 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
7 | 3337 else |
3338 draw_cmdline(ccline.cmdpos, 1); | |
3339 msg_no_more = FALSE; | |
3340 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3341 extra_char = NUL; |
7 | 3342 } |
3343 | |
3344 /* | |
3345 * Put the given string, of the given length, onto the command line. | |
3346 * If len is -1, then STRLEN() is used to calculate the length. | |
3347 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3348 * part will be redrawn, otherwise it will not. If this function is called | |
3349 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3350 * called afterwards. | |
3351 */ | |
3352 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3353 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3354 { |
3355 int retval; | |
3356 int i; | |
3357 int m; | |
3358 int c; | |
3359 | |
3360 if (len < 0) | |
3361 len = (int)STRLEN(str); | |
3362 | |
3363 /* Check if ccline.cmdbuff needs to be longer */ | |
3364 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
|
3365 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3366 else |
3367 retval = OK; | |
3368 if (retval == OK) | |
3369 { | |
3370 if (!ccline.overstrike) | |
3371 { | |
3372 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3373 ccline.cmdbuff + ccline.cmdpos, | |
3374 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3375 ccline.cmdlen += len; | |
3376 } | |
3377 else | |
3378 { | |
3379 if (has_mbyte) | |
3380 { | |
3381 /* Count nr of characters in the new string. */ | |
3382 m = 0; | |
474 | 3383 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3384 ++m; |
3385 /* Count nr of bytes in cmdline that are overwritten by these | |
3386 * characters. */ | |
3387 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3388 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3389 --m; |
3390 if (i < ccline.cmdlen) | |
3391 { | |
3392 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3393 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3394 ccline.cmdlen += ccline.cmdpos + len - i; | |
3395 } | |
3396 else | |
3397 ccline.cmdlen = ccline.cmdpos + len; | |
3398 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
3399 else if (ccline.cmdpos + len > ccline.cmdlen) |
7 | 3400 ccline.cmdlen = ccline.cmdpos + len; |
3401 } | |
3402 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3403 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3404 | |
3405 if (enc_utf8) | |
3406 { | |
3407 /* When the inserted text starts with a composing character, | |
3408 * backup to the character before it. There could be two of them. | |
3409 */ | |
3410 i = 0; | |
3411 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3412 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3413 { | |
3414 i = (*mb_head_off)(ccline.cmdbuff, | |
3415 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3416 ccline.cmdpos -= i; | |
3417 len += i; | |
3418 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3419 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
3420 #ifdef FEAT_ARABIC |
7 | 3421 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) |
3422 { | |
3423 /* Check the previous character for Arabic combining pair. */ | |
3424 i = (*mb_head_off)(ccline.cmdbuff, | |
3425 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3426 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3427 + ccline.cmdpos - i), c)) | |
3428 { | |
3429 ccline.cmdpos -= i; | |
3430 len += i; | |
3431 } | |
3432 else | |
3433 i = 0; | |
3434 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
3435 #endif |
7 | 3436 if (i != 0) |
3437 { | |
3438 /* Also backup the cursor position. */ | |
3439 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3440 ccline.cmdspos -= i; | |
3441 msg_col -= i; | |
3442 if (msg_col < 0) | |
3443 { | |
3444 msg_col += Columns; | |
3445 --msg_row; | |
3446 } | |
3447 } | |
3448 } | |
3449 | |
3450 if (redraw && !cmd_silent) | |
3451 { | |
3452 msg_no_more = TRUE; | |
3453 i = cmdline_row; | |
3114 | 3454 cursorcmd(); |
7 | 3455 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3456 /* Avoid clearing the rest of the line too often. */ | |
3457 if (cmdline_row != i || ccline.overstrike) | |
3458 msg_clr_eos(); | |
3459 msg_no_more = FALSE; | |
3460 } | |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3461 if (KeyTyped) |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3462 { |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3463 m = Columns * Rows; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3464 if (m < 0) /* overflow, Columns or Rows at weird value */ |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3465 m = MAXCOL; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3466 } |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3467 else |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3468 m = MAXCOL; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3469 for (i = 0; i < len; ++i) |
7 | 3470 { |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3471 c = cmdline_charsize(ccline.cmdpos); |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3472 /* count ">" for a double-wide char that doesn't fit. */ |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3473 if (has_mbyte) |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3474 correct_cmdspos(ccline.cmdpos, c); |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3475 /* Stop cursor at the end of the screen, but do increment the |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3476 * insert position, so that entering a very long command |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3477 * works, even though you can't see it. */ |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3478 if (ccline.cmdspos + c < m) |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3479 ccline.cmdspos += c; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3480 |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3481 if (has_mbyte) |
7 | 3482 { |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3483 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3484 if (c > len - i - 1) |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3485 c = len - i - 1; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3486 ccline.cmdpos += c; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3487 i += c; |
7 | 3488 } |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3489 ++ccline.cmdpos; |
7 | 3490 } |
3491 } | |
3492 if (redraw) | |
3493 msg_check(); | |
3494 return retval; | |
3495 } | |
3496 | |
95 | 3497 static struct cmdline_info prev_ccline; |
3498 static int prev_ccline_used = FALSE; | |
3499 | |
3500 /* | |
3501 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3502 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3503 * available globally in prev_ccline. | |
3504 */ | |
3505 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3506 save_cmdline(struct cmdline_info *ccp) |
95 | 3507 { |
3508 if (!prev_ccline_used) | |
3509 { | |
3510 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3511 prev_ccline_used = TRUE; | |
3512 } | |
3513 *ccp = prev_ccline; | |
3514 prev_ccline = ccline; | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3515 ccline.cmdbuff = NULL; // signal that ccline is not in use |
95 | 3516 } |
3517 | |
3518 /* | |
1214 | 3519 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3520 */ |
3521 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3522 restore_cmdline(struct cmdline_info *ccp) |
95 | 3523 { |
3524 ccline = prev_ccline; | |
3525 prev_ccline = *ccp; | |
3526 } | |
3527 | |
15 | 3528 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3529 * 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
|
3530 * Used by CTRL-R command in command-line mode. |
15 | 3531 * insert_reg() can't be used here, because special characters from the |
3532 * register contents will be interpreted as commands. | |
3533 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3534 * Return FAIL for failure, OK otherwise. |
15 | 3535 */ |
3536 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3537 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3538 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3539 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
|
3540 int remcr) /* remove trailing CR */ |
15 | 3541 { |
3542 long i; | |
3543 char_u *arg; | |
772 | 3544 char_u *p; |
15 | 3545 int allocated; |
3546 | |
3547 /* check for valid regname; also accept special characters for CTRL-R in | |
3548 * the command line */ | |
3549 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
|
3550 && 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
|
3551 && !valid_yank_reg(regname, FALSE)) |
15 | 3552 return FAIL; |
3553 | |
3554 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3555 * CTRL-C to break the loop. */ | |
3556 line_breakcheck(); | |
3557 if (got_int) | |
3558 return FAIL; | |
3559 | |
3560 #ifdef FEAT_CLIPBOARD | |
3561 regname = may_get_selection(regname); | |
3562 #endif | |
3563 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3564 // Need to set "textlock" to avoid nasty things like going to another |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3565 // buffer when evaluating an expression. |
634 | 3566 ++textlock; |
15 | 3567 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3568 --textlock; |
15 | 3569 |
3570 if (i) | |
3571 { | |
3572 /* Got the value of a special register in "arg". */ | |
3573 if (arg == NULL) | |
3574 return FAIL; | |
772 | 3575 |
3576 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3577 * part of the word. */ | |
3578 p = arg; | |
3579 if (p_is && regname == Ctrl_W) | |
3580 { | |
3581 char_u *w; | |
3582 int len; | |
3583 | |
3584 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3585 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3586 { |
3587 if (has_mbyte) | |
3588 { | |
3589 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3590 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3591 break; | |
3592 w -= len; | |
3593 } | |
3594 else | |
3595 { | |
3596 if (!vim_iswordc(w[-1])) | |
3597 break; | |
3598 --w; | |
3599 } | |
3600 } | |
2937 | 3601 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3602 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3603 p += len; | |
3604 } | |
3605 | |
3606 cmdline_paste_str(p, literally); | |
15 | 3607 if (allocated) |
3608 vim_free(arg); | |
3609 return OK; | |
3610 } | |
3611 | |
1015 | 3612 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3613 } |
3614 | |
3615 /* | |
3616 * Put a string on the command line. | |
3617 * When "literally" is TRUE, insert literally. | |
3618 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3619 * line. | |
3620 */ | |
3621 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3622 cmdline_paste_str(char_u *s, int literally) |
15 | 3623 { |
3624 int c, cv; | |
3625 | |
3626 if (literally) | |
3627 put_on_cmdline(s, -1, TRUE); | |
3628 else | |
3629 while (*s != NUL) | |
3630 { | |
3631 cv = *s; | |
3632 if (cv == Ctrl_V && s[1]) | |
3633 ++s; | |
3634 if (has_mbyte) | |
1606 | 3635 c = mb_cptr2char_adv(&s); |
15 | 3636 else |
3637 c = *s++; | |
3628 | 3638 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3639 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3640 #ifdef UNIX |
3641 || c == intr_char | |
3642 #endif | |
3643 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3644 stuffcharReadbuff(Ctrl_V); | |
3645 stuffcharReadbuff(c); | |
3646 } | |
3647 } | |
3648 | |
7 | 3649 #ifdef FEAT_WILDMENU |
3650 /* | |
3651 * Delete characters on the command line, from "from" to the current | |
3652 * position. | |
3653 */ | |
3654 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3655 cmdline_del(int from) |
7 | 3656 { |
3657 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3658 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3659 ccline.cmdlen -= ccline.cmdpos - from; | |
3660 ccline.cmdpos = from; | |
3661 } | |
3662 #endif | |
3663 | |
3664 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3665 * 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
|
3666 * 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
|
3667 * overwritten. |
7 | 3668 */ |
3669 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3670 redrawcmdline(void) |
7 | 3671 { |
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
|
3672 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
|
3673 } |
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
|
3674 |
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
|
3675 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
|
3676 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
|
3677 { |
7 | 3678 if (cmd_silent) |
3679 return; | |
3680 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
|
3681 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
|
3682 compute_cmdrow(); |
7 | 3683 redrawcmd(); |
3684 cursorcmd(); | |
3685 } | |
3686 | |
3687 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3688 redrawcmdprompt(void) |
7 | 3689 { |
3690 int i; | |
3691 | |
3692 if (cmd_silent) | |
3693 return; | |
531 | 3694 if (ccline.cmdfirstc != NUL) |
7 | 3695 msg_putchar(ccline.cmdfirstc); |
3696 if (ccline.cmdprompt != NULL) | |
3697 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3698 msg_puts_attr((char *)ccline.cmdprompt, ccline.cmdattr); |
7 | 3699 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; |
3700 /* do the reverse of set_cmdspos() */ | |
531 | 3701 if (ccline.cmdfirstc != NUL) |
7 | 3702 --ccline.cmdindent; |
3703 } | |
3704 else | |
3705 for (i = ccline.cmdindent; i > 0; --i) | |
3706 msg_putchar(' '); | |
3707 } | |
3708 | |
3709 /* | |
3710 * Redraw what is currently on the command line. | |
3711 */ | |
3712 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3713 redrawcmd(void) |
7 | 3714 { |
3715 if (cmd_silent) | |
3716 return; | |
3717 | |
683 | 3718 /* when 'incsearch' is set there may be no command line while redrawing */ |
3719 if (ccline.cmdbuff == NULL) | |
3720 { | |
3721 windgoto(cmdline_row, 0); | |
3722 msg_clr_eos(); | |
3723 return; | |
3724 } | |
3725 | |
7 | 3726 msg_start(); |
3727 redrawcmdprompt(); | |
3728 | |
3729 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3730 msg_no_more = TRUE; | |
3731 draw_cmdline(0, ccline.cmdlen); | |
3732 msg_clr_eos(); | |
3733 msg_no_more = FALSE; | |
3734 | |
3735 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
|
3736 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
|
3737 putcmdline(extra_char, extra_char_shift); |
7 | 3738 |
3739 /* | |
3740 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3741 * in cmdline mode we can reset them now. | |
3742 */ | |
3743 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3744 | |
3745 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3746 * in cmdline mode */ | |
3747 skip_redraw = FALSE; | |
3748 } | |
3749 | |
3750 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3751 compute_cmdrow(void) |
7 | 3752 { |
540 | 3753 if (exmode_active || msg_scrolled != 0) |
7 | 3754 cmdline_row = Rows - 1; |
3755 else | |
3756 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
|
3757 + lastwin->w_status_height; |
7 | 3758 } |
3759 | |
3760 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3761 cursorcmd(void) |
7 | 3762 { |
3763 if (cmd_silent) | |
3764 return; | |
3765 | |
3766 #ifdef FEAT_RIGHTLEFT | |
3767 if (cmdmsg_rl) | |
3768 { | |
3769 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3770 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3771 if (msg_row <= 0) | |
3772 msg_row = Rows - 1; | |
3773 } | |
3774 else | |
3775 #endif | |
3776 { | |
3777 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3778 msg_col = ccline.cmdspos % (int)Columns; | |
3779 if (msg_row >= Rows) | |
3780 msg_row = Rows - 1; | |
3781 } | |
3782 | |
3783 windgoto(msg_row, msg_col); | |
3784 #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
|
3785 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
|
3786 redrawcmd_preedit(); |
7 | 3787 #endif |
3788 #ifdef MCH_CURSOR_SHAPE | |
3789 mch_update_cursor(); | |
3790 #endif | |
3791 } | |
3792 | |
3793 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3794 gotocmdline(int clr) |
7 | 3795 { |
3796 msg_start(); | |
3797 #ifdef FEAT_RIGHTLEFT | |
3798 if (cmdmsg_rl) | |
3799 msg_col = Columns - 1; | |
3800 else | |
3801 #endif | |
3802 msg_col = 0; /* always start in column 0 */ | |
3803 if (clr) /* clear the bottom line(s) */ | |
3804 msg_clr_eos(); /* will reset clear_cmdline */ | |
3805 windgoto(cmdline_row, 0); | |
3806 } | |
3807 | |
3808 /* | |
3809 * Check the word in front of the cursor for an abbreviation. | |
3810 * Called when the non-id character "c" has been entered. | |
3811 * When an abbreviation is recognized it is removed from the text with | |
3812 * backspaces and the replacement string is inserted, followed by "c". | |
3813 */ | |
3814 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3815 ccheck_abbr(int c) |
7 | 3816 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3817 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3818 |
7 | 3819 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3820 return FALSE; | |
3821 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3822 /* 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
|
3823 * 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
|
3824 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
|
3825 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3826 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
|
3827 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3828 && 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
|
3829 && 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
|
3830 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3831 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3832 /* 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
|
3833 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3834 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3835 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3836 } |
3837 | |
3164 | 3838 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3839 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3840 sort_func_compare(const void *s1, const void *s2) |
3164 | 3841 { |
3842 char_u *p1 = *(char_u **)s1; | |
3843 char_u *p2 = *(char_u **)s2; | |
3844 | |
3845 if (*p1 != '<' && *p2 == '<') return -1; | |
3846 if (*p1 == '<' && *p2 != '<') return 1; | |
3847 return STRCMP(p1, p2); | |
3848 } | |
3849 #endif | |
3850 | |
7 | 3851 /* |
3852 * Return FAIL if this is not an appropriate context in which to do | |
3853 * completion of anything, return OK if it is (even if there are no matches). | |
3854 * For the caller, this means that the character is just passed through like a | |
3855 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3856 */ | |
3857 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3858 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3859 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3860 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3861 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3862 int escape) /* if TRUE, escape the returned matches */ |
7 | 3863 { |
3864 int i, j; | |
3865 char_u *p1; | |
3866 char_u *p2; | |
3867 int difflen; | |
3868 int v; | |
3869 | |
3870 if (xp->xp_numfiles == -1) | |
3871 { | |
3872 set_expand_context(xp); | |
3873 cmd_showtail = expand_showtail(xp); | |
3874 } | |
3875 | |
3876 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3877 { | |
3878 beep_flush(); | |
3879 return OK; /* Something illegal on command line */ | |
3880 } | |
3881 if (xp->xp_context == EXPAND_NOTHING) | |
3882 { | |
3883 /* Caller can use the character as a normal char instead */ | |
3884 return FAIL; | |
3885 } | |
3886 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3887 msg_puts("..."); /* show that we are busy */ |
7 | 3888 out_flush(); |
3889 | |
3890 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3891 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3892 |
3893 if (type == WILD_NEXT || type == WILD_PREV) | |
3894 { | |
3895 /* | |
3896 * Get next/previous match for a previous expanded pattern. | |
3897 */ | |
3898 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3899 } | |
3900 else | |
3901 { | |
3902 /* | |
3903 * Translate string into pattern and expand it. | |
3904 */ | |
1965 | 3905 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3906 xp->xp_context)) == NULL) | |
7 | 3907 p2 = NULL; |
3908 else | |
3909 { | |
2652 | 3910 int use_options = options | |
3961 | 3911 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3912 if (escape) | |
3913 use_options |= WILD_ESCAPE; | |
2652 | 3914 |
3915 if (p_wic) | |
3916 use_options += WILD_ICASE; | |
1965 | 3917 p2 = ExpandOne(xp, p1, |
3918 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3919 use_options, type); |
7 | 3920 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3921 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3922 if (p2 != NULL && type == WILD_LONGEST) |
3923 { | |
1965 | 3924 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3925 if (ccline.cmdbuff[i + j] == '*' |
3926 || ccline.cmdbuff[i + j] == '?') | |
3927 break; | |
3928 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
|
3929 VIM_CLEAR(p2); |
7 | 3930 } |
3931 } | |
3932 } | |
3933 | |
3934 if (p2 != NULL && !got_int) | |
3935 { | |
1965 | 3936 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
|
3937 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3938 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3939 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3940 xp->xp_pattern = ccline.cmdbuff + i; |
3941 } | |
3942 else | |
3943 v = OK; | |
3944 if (v == OK) | |
3945 { | |
323 | 3946 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3947 &ccline.cmdbuff[ccline.cmdpos], | |
3948 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3949 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3950 ccline.cmdlen += difflen; |
3951 ccline.cmdpos += difflen; | |
3952 } | |
3953 } | |
3954 vim_free(p2); | |
3955 | |
3956 redrawcmd(); | |
33 | 3957 cursorcmd(); |
7 | 3958 |
3959 /* When expanding a ":map" command and no matches are found, assume that | |
3960 * the key is supposed to be inserted literally */ | |
3961 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3962 return FAIL; | |
3963 | |
3964 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
3965 beep_flush(); | |
3966 else if (xp->xp_numfiles == 1) | |
3967 /* free expanded pattern */ | |
3968 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
3969 | |
3970 return OK; | |
3971 } | |
3972 | |
3973 /* | |
3974 * Do wildcard expansion on the string 'str'. | |
3975 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 3976 * Return a pointer to allocated memory containing the new string. |
7 | 3977 * Return NULL for failure. |
3978 * | |
1412 | 3979 * "orig" is the originally expanded string, copied to allocated memory. It |
3980 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
3981 * WILD_PREV "orig" should be NULL. | |
3982 * | |
838 | 3983 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
3984 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 3985 * |
3986 * mode = WILD_FREE: just free previously expanded matches | |
3987 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
3988 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
3989 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
3990 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
3991 * mode = WILD_ALL: return all matches concatenated | |
3992 * mode = WILD_LONGEST: return longest matched part | |
3398 | 3993 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 3994 * |
3995 * options = WILD_LIST_NOTFOUND: list entries without a match | |
3996 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
3997 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
3998 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
3999 * options = WILD_ADD_SLASH: add a slash after directory names | |
4000 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
4001 * options = WILD_SILENT: don't print warning messages | |
4002 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 4003 * options = WILD_ICASE: ignore case for files |
7 | 4004 * |
4005 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
4006 */ | |
4007 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4008 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4009 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4010 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4011 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
|
4012 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4013 int mode) |
7 | 4014 { |
4015 char_u *ss = NULL; | |
4016 static int findex; | |
4017 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 4018 int orig_saved = FALSE; |
7 | 4019 int i; |
4020 long_u len; | |
4021 int non_suf_match; /* number without matching suffix */ | |
4022 | |
4023 /* | |
4024 * first handle the case of using an old match | |
4025 */ | |
4026 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4027 { | |
4028 if (xp->xp_numfiles > 0) | |
4029 { | |
4030 if (mode == WILD_PREV) | |
4031 { | |
4032 if (findex == -1) | |
4033 findex = xp->xp_numfiles; | |
4034 --findex; | |
4035 } | |
4036 else /* mode == WILD_NEXT */ | |
4037 ++findex; | |
4038 | |
4039 /* | |
4040 * When wrapping around, return the original string, set findex to | |
4041 * -1. | |
4042 */ | |
4043 if (findex < 0) | |
4044 { | |
4045 if (orig_save == NULL) | |
4046 findex = xp->xp_numfiles - 1; | |
4047 else | |
4048 findex = -1; | |
4049 } | |
4050 if (findex >= xp->xp_numfiles) | |
4051 { | |
4052 if (orig_save == NULL) | |
4053 findex = 0; | |
4054 else | |
4055 findex = -1; | |
4056 } | |
4057 #ifdef FEAT_WILDMENU | |
4058 if (p_wmnu) | |
4059 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4060 findex, cmd_showtail); | |
4061 #endif | |
4062 if (findex == -1) | |
4063 return vim_strsave(orig_save); | |
4064 return vim_strsave(xp->xp_files[findex]); | |
4065 } | |
4066 else | |
4067 return NULL; | |
4068 } | |
4069 | |
1412 | 4070 /* free old names */ |
7 | 4071 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4072 { | |
4073 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4074 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
|
4075 VIM_CLEAR(orig_save); |
7 | 4076 } |
4077 findex = 0; | |
4078 | |
4079 if (mode == WILD_FREE) /* only release file name */ | |
4080 return NULL; | |
4081 | |
4082 if (xp->xp_numfiles == -1) | |
4083 { | |
4084 vim_free(orig_save); | |
4085 orig_save = orig; | |
1432 | 4086 orig_saved = TRUE; |
7 | 4087 |
4088 /* | |
4089 * Do the expansion. | |
4090 */ | |
4091 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4092 options) == FAIL) | |
4093 { | |
4094 #ifdef FNAME_ILLEGAL | |
4095 /* Illegal file name has been silently skipped. But when there | |
4096 * are wildcards, the real problem is that there was no match, | |
4097 * causing the pattern to be added, which has illegal characters. | |
4098 */ | |
4099 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
4100 semsg(_(e_nomatch2), str); |
7 | 4101 #endif |
4102 } | |
4103 else if (xp->xp_numfiles == 0) | |
4104 { | |
4105 if (!(options & WILD_SILENT)) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
4106 semsg(_(e_nomatch2), str); |
7 | 4107 } |
4108 else | |
4109 { | |
4110 /* Escape the matches for use on the command line. */ | |
4111 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4112 | |
4113 /* | |
4114 * Check for matching suffixes in file names. | |
4115 */ | |
3398 | 4116 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4117 && mode != WILD_LONGEST) | |
7 | 4118 { |
4119 if (xp->xp_numfiles) | |
4120 non_suf_match = xp->xp_numfiles; | |
4121 else | |
4122 non_suf_match = 1; | |
4123 if ((xp->xp_context == EXPAND_FILES | |
4124 || xp->xp_context == EXPAND_DIRECTORIES) | |
4125 && xp->xp_numfiles > 1) | |
4126 { | |
4127 /* | |
4128 * More than one match; check suffix. | |
4129 * The files will have been sorted on matching suffix in | |
4130 * expand_wildcards, only need to check the first two. | |
4131 */ | |
4132 non_suf_match = 0; | |
4133 for (i = 0; i < 2; ++i) | |
4134 if (match_suffix(xp->xp_files[i])) | |
4135 ++non_suf_match; | |
4136 } | |
4137 if (non_suf_match != 1) | |
4138 { | |
4139 /* Can we ever get here unless it's while expanding | |
4140 * interactively? If not, we can get rid of this all | |
4141 * together. Don't really want to wait for this message | |
4142 * (and possibly have to hit return to continue!). | |
4143 */ | |
4144 if (!(options & WILD_SILENT)) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
4145 emsg(_(e_toomany)); |
7 | 4146 else if (!(options & WILD_NO_BEEP)) |
4147 beep_flush(); | |
4148 } | |
4149 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4150 ss = vim_strsave(xp->xp_files[0]); | |
4151 } | |
4152 } | |
4153 } | |
4154 | |
4155 /* Find longest common part */ | |
4156 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4157 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4158 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4159 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4160 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4161 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4162 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4163 if (has_mbyte) |
7 | 4164 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4165 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
|
4166 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
|
4167 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4168 else |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4169 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
|
4170 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
|
4171 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4172 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4173 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
|
4174 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4175 ci = xp->xp_files[i][len]; |
4242 | 4176 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4177 || xp->xp_context == EXPAND_FILES |
714 | 4178 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4179 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4180 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4181 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4182 break; |
4183 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4184 else if (c0 != ci) |
7 | 4185 break; |
4186 } | |
4187 if (i < xp->xp_numfiles) | |
4188 { | |
4189 if (!(options & WILD_NO_BEEP)) | |
6949 | 4190 vim_beep(BO_WILD); |
7 | 4191 break; |
4192 } | |
4193 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4194 |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
4195 ss = alloc(len + 1); |
7 | 4196 if (ss) |
419 | 4197 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4198 findex = -1; /* next p_wc gets first one */ |
4199 } | |
4200 | |
4201 /* Concatenate all matching names */ | |
4202 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4203 { | |
4204 len = 0; | |
4205 for (i = 0; i < xp->xp_numfiles; ++i) | |
4206 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
4207 ss = alloc(len); |
7 | 4208 if (ss != NULL) |
4209 { | |
4210 *ss = NUL; | |
4211 for (i = 0; i < xp->xp_numfiles; ++i) | |
4212 { | |
4213 STRCAT(ss, xp->xp_files[i]); | |
4214 if (i != xp->xp_numfiles - 1) | |
4215 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4216 } | |
4217 } | |
4218 } | |
4219 | |
4220 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4221 ExpandCleanup(xp); | |
4222 | |
1412 | 4223 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4224 if (!orig_saved) |
1412 | 4225 vim_free(orig); |
4226 | |
7 | 4227 return ss; |
4228 } | |
4229 | |
4230 /* | |
4231 * Prepare an expand structure for use. | |
4232 */ | |
4233 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4234 ExpandInit(expand_T *xp) |
7 | 4235 { |
1718 | 4236 xp->xp_pattern = NULL; |
1965 | 4237 xp->xp_pattern_len = 0; |
7 | 4238 xp->xp_backslash = XP_BS_NONE; |
632 | 4239 #ifndef BACKSLASH_IN_FILENAME |
4240 xp->xp_shell = FALSE; | |
4241 #endif | |
7 | 4242 xp->xp_numfiles = -1; |
4243 xp->xp_files = NULL; | |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16287
diff
changeset
|
4244 #if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
632 | 4245 xp->xp_arg = NULL; |
4246 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4247 xp->xp_line = NULL; |
7 | 4248 } |
4249 | |
4250 /* | |
4251 * Cleanup an expand structure after use. | |
4252 */ | |
4253 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4254 ExpandCleanup(expand_T *xp) |
7 | 4255 { |
4256 if (xp->xp_numfiles >= 0) | |
4257 { | |
4258 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4259 xp->xp_numfiles = -1; | |
4260 } | |
4261 } | |
4262 | |
4263 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4264 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4265 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4266 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4267 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4268 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4269 int options) |
7 | 4270 { |
4271 int i; | |
4272 char_u *p; | |
4273 | |
4274 /* | |
4275 * May change home directory back to "~" | |
4276 */ | |
4277 if (options & WILD_HOME_REPLACE) | |
4278 tilde_replace(str, numfiles, files); | |
4279 | |
4280 if (options & WILD_ESCAPE) | |
4281 { | |
4282 if (xp->xp_context == EXPAND_FILES | |
2778 | 4283 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4284 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4285 || xp->xp_context == EXPAND_BUFFERS |
4286 || xp->xp_context == EXPAND_DIRECTORIES) | |
4287 { | |
4288 /* | |
4289 * Insert a backslash into a file name before a space, \, %, # | |
4290 * and wildmatch characters, except '~'. | |
4291 */ | |
4292 for (i = 0; i < numfiles; ++i) | |
4293 { | |
4294 /* for ":set path=" we need to escape spaces twice */ | |
4295 if (xp->xp_backslash == XP_BS_THREE) | |
4296 { | |
4297 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4298 if (p != NULL) | |
4299 { | |
4300 vim_free(files[i]); | |
4301 files[i] = p; | |
719 | 4302 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4303 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4304 if (p != NULL) | |
4305 { | |
4306 vim_free(files[i]); | |
4307 files[i] = p; | |
4308 } | |
4309 #endif | |
4310 } | |
4311 } | |
1589 | 4312 #ifdef BACKSLASH_IN_FILENAME |
4313 p = vim_strsave_fnameescape(files[i], FALSE); | |
4314 #else | |
1586 | 4315 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4316 #endif |
7 | 4317 if (p != NULL) |
4318 { | |
4319 vim_free(files[i]); | |
4320 files[i] = p; | |
4321 } | |
4322 | |
4323 /* If 'str' starts with "\~", replace "~" at start of | |
4324 * files[i] with "\~". */ | |
4325 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4326 escape_fname(&files[i]); |
7 | 4327 } |
4328 xp->xp_backslash = XP_BS_NONE; | |
435 | 4329 |
4330 /* If the first file starts with a '+' escape it. Otherwise it | |
4331 * could be seen as "+cmd". */ | |
4332 if (*files[0] == '+') | |
4333 escape_fname(&files[0]); | |
7 | 4334 } |
4335 else if (xp->xp_context == EXPAND_TAGS) | |
4336 { | |
4337 /* | |
4338 * Insert a backslash before characters in a tag name that | |
4339 * would terminate the ":tag" command. | |
4340 */ | |
4341 for (i = 0; i < numfiles; ++i) | |
4342 { | |
4343 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4344 if (p != NULL) | |
4345 { | |
4346 vim_free(files[i]); | |
4347 files[i] = p; | |
4348 } | |
4349 } | |
4350 } | |
4351 } | |
4352 } | |
4353 | |
4354 /* | |
1586 | 4355 * Escape special characters in "fname" for when used as a file name argument |
4356 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4357 * Returns the result in allocated memory. | |
4358 */ | |
4359 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4360 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4361 { |
1685 | 4362 char_u *p; |
1586 | 4363 #ifdef BACKSLASH_IN_FILENAME |
4364 char_u buf[20]; | |
4365 int j = 0; | |
4366 | |
5481 | 4367 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4368 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4369 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4370 buf[j++] = *p; |
4371 buf[j] = NUL; | |
1700 | 4372 p = vim_strsave_escaped(fname, buf); |
1586 | 4373 #else |
1685 | 4374 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4375 if (shell && csh_like_shell() && p != NULL) | |
4376 { | |
4377 char_u *s; | |
4378 | |
4379 /* For csh and similar shells need to put two backslashes before '!'. | |
4380 * One is taken by Vim, one by the shell. */ | |
4381 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4382 vim_free(p); | |
4383 p = s; | |
4384 } | |
1700 | 4385 #endif |
4386 | |
4387 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4388 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4389 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4390 escape_fname(&p); |
4391 | |
1685 | 4392 return p; |
1586 | 4393 } |
4394 | |
4395 /* | |
435 | 4396 * Put a backslash before the file name in "pp", which is in allocated memory. |
4397 */ | |
4398 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4399 escape_fname(char_u **pp) |
435 | 4400 { |
4401 char_u *p; | |
4402 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
4403 p = alloc(STRLEN(*pp) + 2); |
435 | 4404 if (p != NULL) |
4405 { | |
4406 p[0] = '\\'; | |
4407 STRCPY(p + 1, *pp); | |
4408 vim_free(*pp); | |
4409 *pp = p; | |
4410 } | |
4411 } | |
4412 | |
4413 /* | |
7 | 4414 * For each file name in files[num_files]: |
4415 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4416 */ | |
4417 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4418 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4419 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4420 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4421 char_u **files) |
7 | 4422 { |
4423 int i; | |
4424 char_u *p; | |
4425 | |
4426 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4427 { | |
4428 for (i = 0; i < num_files; ++i) | |
4429 { | |
4430 p = home_replace_save(NULL, files[i]); | |
4431 if (p != NULL) | |
4432 { | |
4433 vim_free(files[i]); | |
4434 files[i] = p; | |
4435 } | |
4436 } | |
4437 } | |
4438 } | |
4439 | |
4440 /* | |
4441 * Show all matches for completion on the command line. | |
4442 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4443 * be inserted like a normal character. | |
4444 */ | |
4445 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4446 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4447 { |
4448 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4449 int num_files; | |
4450 char_u **files_found; | |
4451 int i, j, k; | |
4452 int maxlen; | |
4453 int lines; | |
4454 int columns; | |
4455 char_u *p; | |
4456 int lastlen; | |
4457 int attr; | |
4458 int showtail; | |
4459 | |
4460 if (xp->xp_numfiles == -1) | |
4461 { | |
4462 set_expand_context(xp); | |
4463 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4464 &num_files, &files_found); | |
4465 showtail = expand_showtail(xp); | |
4466 if (i != EXPAND_OK) | |
4467 return i; | |
4468 | |
4469 } | |
4470 else | |
4471 { | |
4472 num_files = xp->xp_numfiles; | |
4473 files_found = xp->xp_files; | |
4474 showtail = cmd_showtail; | |
4475 } | |
4476 | |
4477 #ifdef FEAT_WILDMENU | |
4478 if (!wildmenu) | |
4479 { | |
4480 #endif | |
4481 msg_didany = FALSE; /* lines_left will be set */ | |
4482 msg_start(); /* prepare for paging */ | |
4483 msg_putchar('\n'); | |
4484 out_flush(); | |
4485 cmdline_row = msg_row; | |
4486 msg_didany = FALSE; /* lines_left will be set again */ | |
4487 msg_start(); /* prepare for paging */ | |
4488 #ifdef FEAT_WILDMENU | |
4489 } | |
4490 #endif | |
4491 | |
4492 if (got_int) | |
4493 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4494 #ifdef FEAT_WILDMENU | |
4495 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
|
4496 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4497 #endif |
4498 else | |
4499 { | |
4500 /* find the length of the longest file name */ | |
4501 maxlen = 0; | |
4502 for (i = 0; i < num_files; ++i) | |
4503 { | |
4504 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4505 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4506 || xp->xp_context == EXPAND_BUFFERS)) |
4507 { | |
4508 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4509 j = vim_strsize(NameBuff); | |
4510 } | |
4511 else | |
4512 j = vim_strsize(L_SHOWFILE(i)); | |
4513 if (j > maxlen) | |
4514 maxlen = j; | |
4515 } | |
4516 | |
4517 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4518 lines = num_files; | |
4519 else | |
4520 { | |
4521 /* compute the number of columns and lines for the listing */ | |
4522 maxlen += 2; /* two spaces between file names */ | |
4523 columns = ((int)Columns + 2) / maxlen; | |
4524 if (columns < 1) | |
4525 columns = 1; | |
4526 lines = (num_files + columns - 1) / columns; | |
4527 } | |
4528 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4529 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4530 |
4531 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4532 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4533 msg_puts_attr(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4534 msg_clr_eos(); |
4535 msg_advance(maxlen - 3); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4536 msg_puts_attr(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4537 } |
4538 | |
4539 /* list the files line by line */ | |
4540 for (i = 0; i < lines; ++i) | |
4541 { | |
4542 lastlen = 999; | |
4543 for (k = i; k < num_files; k += lines) | |
4544 { | |
4545 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4546 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4547 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4548 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4549 msg_advance(maxlen + 1); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4550 msg_puts((char *)p); |
7 | 4551 msg_advance(maxlen + 3); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4552 msg_outtrans_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4553 break; |
4554 } | |
4555 for (j = maxlen - lastlen; --j >= 0; ) | |
4556 msg_putchar(' '); | |
4557 if (xp->xp_context == EXPAND_FILES | |
714 | 4558 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4559 || xp->xp_context == EXPAND_BUFFERS) |
4560 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4561 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4562 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4563 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4564 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4565 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4566 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4567 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4568 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4569 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4570 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
|
4571 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4572 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4573 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4574 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4575 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4576 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4577 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4578 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4579 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4580 j = mch_isdir(files_found[k]); |
7 | 4581 if (showtail) |
4582 p = L_SHOWFILE(k); | |
4583 else | |
4584 { | |
4585 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4586 TRUE); | |
4587 p = NameBuff; | |
4588 } | |
4589 } | |
4590 else | |
4591 { | |
4592 j = FALSE; | |
4593 p = L_SHOWFILE(k); | |
4594 } | |
4595 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4596 } | |
4597 if (msg_col > 0) /* when not wrapped around */ | |
4598 { | |
4599 msg_clr_eos(); | |
4600 msg_putchar('\n'); | |
4601 } | |
4602 out_flush(); /* show one line at a time */ | |
4603 if (got_int) | |
4604 { | |
4605 got_int = FALSE; | |
4606 break; | |
4607 } | |
4608 } | |
4609 | |
4610 /* | |
4611 * we redraw the command below the lines that we have just listed | |
4612 * This is a bit tricky, but it saves a lot of screen updating. | |
4613 */ | |
4614 cmdline_row = msg_row; /* will put it back later */ | |
4615 } | |
4616 | |
4617 if (xp->xp_numfiles == -1) | |
4618 FreeWild(num_files, files_found); | |
4619 | |
4620 return EXPAND_OK; | |
4621 } | |
4622 | |
4623 /* | |
4624 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4625 * Find tail of file name path, but ignore trailing "/". | |
4626 */ | |
4627 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4628 sm_gettail(char_u *s) |
7 | 4629 { |
4630 char_u *p; | |
4631 char_u *t = s; | |
4632 int had_sep = FALSE; | |
4633 | |
4634 for (p = s; *p != NUL; ) | |
4635 { | |
4636 if (vim_ispathsep(*p) | |
4637 #ifdef BACKSLASH_IN_FILENAME | |
4638 && !rem_backslash(p) | |
4639 #endif | |
4640 ) | |
4641 had_sep = TRUE; | |
4642 else if (had_sep) | |
4643 { | |
4644 t = p; | |
4645 had_sep = FALSE; | |
4646 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4647 MB_PTR_ADV(p); |
7 | 4648 } |
4649 return t; | |
4650 } | |
4651 | |
4652 /* | |
4653 * Return TRUE if we only need to show the tail of completion matches. | |
4654 * When not completing file names or there is a wildcard in the path FALSE is | |
4655 * returned. | |
4656 */ | |
4657 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4658 expand_showtail(expand_T *xp) |
7 | 4659 { |
4660 char_u *s; | |
4661 char_u *end; | |
4662 | |
4663 /* When not completing file names a "/" may mean something different. */ | |
714 | 4664 if (xp->xp_context != EXPAND_FILES |
4665 && xp->xp_context != EXPAND_SHELLCMD | |
4666 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4667 return FALSE; |
4668 | |
4669 end = gettail(xp->xp_pattern); | |
4670 if (end == xp->xp_pattern) /* there is no path separator */ | |
4671 return FALSE; | |
4672 | |
4673 for (s = xp->xp_pattern; s < end; s++) | |
4674 { | |
4675 /* Skip escaped wildcards. Only when the backslash is not a path | |
4676 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4677 if (rem_backslash(s)) | |
4678 ++s; | |
4679 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4680 return FALSE; | |
4681 } | |
4682 return TRUE; | |
4683 } | |
4684 | |
4685 /* | |
4686 * Prepare a string for expansion. | |
4687 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4688 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4689 * When expanding other names: The string will be used with regcomp(). Copy |
4690 * the name into allocated memory and prepend "^". | |
4691 */ | |
4692 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4693 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4694 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4695 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4696 int context) /* EXPAND_FILES etc. */ |
7 | 4697 { |
4698 char_u *retval; | |
4699 int i, j; | |
4700 int new_len; | |
4701 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4702 int ends_in_star; |
7 | 4703 |
714 | 4704 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4705 && context != EXPAND_FILES_IN_PATH |
714 | 4706 && context != EXPAND_SHELLCMD |
4707 && context != EXPAND_DIRECTORIES) | |
7 | 4708 { |
4709 /* | |
4710 * Matching will be done internally (on something other than files). | |
4711 * So we convert the file-matching-type wildcards into our kind for | |
4712 * use with vim_regcomp(). First work out how long it will be: | |
4713 */ | |
4714 | |
4715 /* For help tags the translation is done in find_help_tags(). | |
4716 * For a tag pattern starting with "/" no translation is needed. */ | |
4717 if (context == EXPAND_HELP | |
4718 || context == EXPAND_COLORS | |
4719 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4720 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4721 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4722 || 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
|
4723 || ((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
|
4724 || 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
|
4725 && fname[0] == '/')) |
7 | 4726 retval = vim_strnsave(fname, len); |
4727 else | |
4728 { | |
4729 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4730 for (i = 0; i < len; i++) | |
4731 { | |
4732 if (fname[i] == '*' || fname[i] == '~') | |
4733 new_len++; /* '*' needs to be replaced by ".*" | |
4734 '~' needs to be replaced by "\~" */ | |
4735 | |
4736 /* Buffer names are like file names. "." should be literal */ | |
4737 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4738 new_len++; /* "." becomes "\." */ | |
4739 | |
4740 /* Custom expansion takes care of special things, match | |
4741 * backslashes literally (perhaps also for other types?) */ | |
634 | 4742 if ((context == EXPAND_USER_DEFINED |
4743 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4744 new_len++; /* '\' becomes "\\" */ |
4745 } | |
4746 retval = alloc(new_len); | |
4747 if (retval != NULL) | |
4748 { | |
4749 retval[0] = '^'; | |
4750 j = 1; | |
4751 for (i = 0; i < len; i++, j++) | |
4752 { | |
4753 /* Skip backslash. But why? At least keep it for custom | |
4754 * expansion. */ | |
4755 if (context != EXPAND_USER_DEFINED | |
407 | 4756 && context != EXPAND_USER_LIST |
4757 && fname[i] == '\\' | |
4758 && ++i == len) | |
7 | 4759 break; |
4760 | |
4761 switch (fname[i]) | |
4762 { | |
4763 case '*': retval[j++] = '.'; | |
4764 break; | |
4765 case '~': retval[j++] = '\\'; | |
4766 break; | |
4767 case '?': retval[j] = '.'; | |
4768 continue; | |
4769 case '.': if (context == EXPAND_BUFFERS) | |
4770 retval[j++] = '\\'; | |
4771 break; | |
407 | 4772 case '\\': if (context == EXPAND_USER_DEFINED |
4773 || context == EXPAND_USER_LIST) | |
7 | 4774 retval[j++] = '\\'; |
4775 break; | |
4776 } | |
4777 retval[j] = fname[i]; | |
4778 } | |
4779 retval[j] = NUL; | |
4780 } | |
4781 } | |
4782 } | |
4783 else | |
4784 { | |
4785 retval = alloc(len + 4); | |
4786 if (retval != NULL) | |
4787 { | |
419 | 4788 vim_strncpy(retval, fname, len); |
7 | 4789 |
4790 /* | |
831 | 4791 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4792 * * would become **, which walks the whole tree. | |
7 | 4793 * ~ would be at the start of the file name, but not the tail. |
4794 * $ could be anywhere in the tail. | |
4795 * ` could be anywhere in the file name. | |
1484 | 4796 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4797 */ |
4798 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4799 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
|
4800 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4801 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4802 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4803 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4804 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4805 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4806 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4807 #endif |
7 | 4808 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4809 && !ends_in_star |
7 | 4810 && vim_strchr(tail, '$') == NULL |
4811 && vim_strchr(retval, '`') == NULL) | |
4812 retval[len++] = '*'; | |
1484 | 4813 else if (len > 0 && retval[len - 1] == '$') |
4814 --len; | |
7 | 4815 retval[len] = NUL; |
4816 } | |
4817 } | |
4818 return retval; | |
4819 } | |
4820 | |
4821 /* | |
4822 * Must parse the command line so far to work out what context we are in. | |
4823 * Completion can then be done based on that context. | |
4824 * This routine sets the variables: | |
4825 * xp->xp_pattern The start of the pattern to be expanded within | |
4826 * the command line (ends at the cursor). | |
4827 * xp->xp_context The type of thing to expand. Will be one of: | |
4828 * | |
4829 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4830 * the command line, like an unknown command. Caller | |
4831 * should beep. | |
4832 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4833 * a normal char, rather than for completion. eg | |
4834 * :s/^I/ | |
4835 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4836 * it. | |
4837 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
17266
diff
changeset
|
4838 * EXPAND_FILES After command with EX_XFILE set, or after setting |
7 | 4839 * with P_EXPAND set. eg :e ^I, :w>>^I |
4840 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4841 * when we know only directories are of interest. eg | |
4842 * :set dir=^I | |
714 | 4843 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4844 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4845 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4846 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4847 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4848 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4849 * EXPAND_EVENTS Complete event names | |
4850 * EXPAND_SYNTAX Complete :syntax command arguments | |
4851 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4852 * EXPAND_AUGROUP Complete autocommand group names | |
4853 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4854 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4855 * eg :unmap a^I , :cunab x^I | |
4856 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4857 * eg :call sub^I | |
4858 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4859 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4860 * names in expressions, eg :while s^I | |
4861 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4862 * EXPAND_USER Complete user names |
7 | 4863 */ |
4864 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4865 set_expand_context(expand_T *xp) |
7 | 4866 { |
168 | 4867 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4868 if (ccline.cmdfirstc != ':' |
4869 #ifdef FEAT_EVAL | |
168 | 4870 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4871 && !ccline.input_fn |
7 | 4872 #endif |
4873 ) | |
4874 { | |
4875 xp->xp_context = EXPAND_NOTHING; | |
4876 return; | |
4877 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4878 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4879 } |
4880 | |
4881 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4882 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4883 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4884 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
|
4885 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
|
4886 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4887 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4888 { |
4889 int old_char = NUL; | |
4890 char_u *nextcomm; | |
4891 | |
4892 /* | |
4893 * Avoid a UMR warning from Purify, only save the character if it has been | |
4894 * written before. | |
4895 */ | |
4896 if (col < len) | |
4897 old_char = str[col]; | |
4898 str[col] = NUL; | |
4899 nextcomm = str; | |
168 | 4900 |
4901 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4902 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4903 { |
4904 # ifdef FEAT_CMDL_COMPL | |
168 | 4905 /* pass CMD_SIZE because there is no real command */ |
4906 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4907 # endif |
4908 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4909 else if (use_ccline && ccline.input_fn) |
531 | 4910 { |
4911 xp->xp_context = ccline.xp_context; | |
4912 xp->xp_pattern = ccline.cmdbuff; | |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16287
diff
changeset
|
4913 # if defined(FEAT_CMDL_COMPL) |
531 | 4914 xp->xp_arg = ccline.xp_arg; |
1322 | 4915 # endif |
531 | 4916 } |
168 | 4917 else |
4918 #endif | |
4919 while (nextcomm != NULL) | |
4920 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4921 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4922 /* 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
|
4923 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4924 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4925 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4926 |
7 | 4927 str[col] = old_char; |
4928 } | |
4929 | |
4930 /* | |
4931 * Expand the command line "str" from context "xp". | |
4932 * "xp" must have been set by set_cmd_context(). | |
4933 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4934 * starts. | |
4935 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4936 * cursor. | |
4937 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4938 * key that triggered expansion literally. | |
4939 * Returns EXPAND_OK otherwise. | |
4940 */ | |
4941 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4942 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4943 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4944 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
|
4945 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4946 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4947 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4948 { |
4949 char_u *file_str = NULL; | |
2652 | 4950 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4951 |
4952 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4953 { | |
4954 beep_flush(); | |
4955 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4956 } | |
4957 if (xp->xp_context == EXPAND_NOTHING) | |
4958 { | |
4959 /* Caller can use the character as a normal char instead */ | |
4960 return EXPAND_NOTHING; | |
4961 } | |
4962 | |
4963 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 4964 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
4965 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 4966 if (file_str == NULL) |
4967 return EXPAND_UNSUCCESSFUL; | |
4968 | |
2652 | 4969 if (p_wic) |
4970 options += WILD_ICASE; | |
4971 | |
7 | 4972 /* find all files that match the description */ |
2652 | 4973 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 4974 { |
4975 *matchcount = 0; | |
4976 *matches = NULL; | |
4977 } | |
4978 vim_free(file_str); | |
4979 | |
4980 return EXPAND_OK; | |
4981 } | |
4982 | |
4983 #ifdef FEAT_MULTI_LANG | |
4984 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4985 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4986 * 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
|
4987 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 4988 */ |
4989 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4990 cleanup_help_tags(int num_file, char_u **file) |
7 | 4991 { |
4992 int i, j; | |
4993 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4994 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4995 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4996 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4997 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
|
4998 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4999 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5000 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5001 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5002 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5003 *p = NUL; |
7 | 5004 |
5005 for (i = 0; i < num_file; ++i) | |
5006 { | |
5007 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
|
5008 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5009 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5010 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 5011 { |
5012 /* Sorting on priority means the same item in another language may | |
5013 * be anywhere. Search all items for a match up to the "@en". */ | |
5014 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
|
5015 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
|
5016 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5017 break; |
5018 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5019 /* item only exists with @en, remove it */ |
7 | 5020 file[i][len] = NUL; |
5021 } | |
5022 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5023 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5024 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5025 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
|
5026 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5027 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5028 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5029 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5030 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
|
5031 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5032 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5033 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5034 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5035 } |
7 | 5036 } |
5037 #endif | |
5038 | |
5039 /* | |
5040 * Do the expansion based on xp->xp_context and "pat". | |
5041 */ | |
5042 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5043 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5044 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5045 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5046 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5047 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5048 int options) /* EW_ flags */ |
7 | 5049 { |
5050 #ifdef FEAT_CMDL_COMPL | |
5051 regmatch_T regmatch; | |
5052 #endif | |
5053 int ret; | |
5054 int flags; | |
5055 | |
5056 flags = EW_DIR; /* include directories */ | |
5057 if (options & WILD_LIST_NOTFOUND) | |
5058 flags |= EW_NOTFOUND; | |
5059 if (options & WILD_ADD_SLASH) | |
5060 flags |= EW_ADDSLASH; | |
5061 if (options & WILD_KEEP_ALL) | |
5062 flags |= EW_KEEPALL; | |
5063 if (options & WILD_SILENT) | |
5064 flags |= EW_SILENT; | |
6659 | 5065 if (options & WILD_ALLLINKS) |
5066 flags |= EW_ALLLINKS; | |
7 | 5067 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5068 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5069 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5070 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5071 { |
5072 /* | |
5073 * Expand file or directory names. | |
5074 */ | |
5075 int free_pat = FALSE; | |
5076 int i; | |
5077 | |
5078 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5079 * space */ | |
5080 if (xp->xp_backslash != XP_BS_NONE) | |
5081 { | |
5082 free_pat = TRUE; | |
5083 pat = vim_strsave(pat); | |
5084 for (i = 0; pat[i]; ++i) | |
5085 if (pat[i] == '\\') | |
5086 { | |
5087 if (xp->xp_backslash == XP_BS_THREE | |
5088 && pat[i + 1] == '\\' | |
5089 && pat[i + 2] == '\\' | |
5090 && pat[i + 3] == ' ') | |
1621 | 5091 STRMOVE(pat + i, pat + i + 3); |
7 | 5092 if (xp->xp_backslash == XP_BS_ONE |
5093 && pat[i + 1] == ' ') | |
1621 | 5094 STRMOVE(pat + i, pat + i + 1); |
7 | 5095 } |
5096 } | |
5097 | |
5098 if (xp->xp_context == EXPAND_FILES) | |
5099 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5100 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
|
5101 flags |= (EW_FILE | EW_PATH); |
7 | 5102 else |
5103 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5104 if (options & WILD_ICASE) |
5105 flags |= EW_ICASE; | |
5106 | |
2016 | 5107 /* Expand wildcards, supporting %:h and the like. */ |
5108 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5109 if (free_pat) |
5110 vim_free(pat); | |
5111 return ret; | |
5112 } | |
5113 | |
5114 *file = (char_u **)""; | |
5115 *num_file = 0; | |
5116 if (xp->xp_context == EXPAND_HELP) | |
5117 { | |
1696 | 5118 /* With an empty argument we would get all the help tags, which is |
5119 * very slow. Get matches for "help" instead. */ | |
5120 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5121 num_file, file, FALSE) == OK) | |
7 | 5122 { |
5123 #ifdef FEAT_MULTI_LANG | |
5124 cleanup_help_tags(*num_file, *file); | |
5125 #endif | |
5126 return OK; | |
5127 } | |
5128 return FAIL; | |
5129 } | |
5130 | |
5131 #ifndef FEAT_CMDL_COMPL | |
5132 return FAIL; | |
5133 #else | |
716 | 5134 if (xp->xp_context == EXPAND_SHELLCMD) |
5135 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5136 if (xp->xp_context == EXPAND_OLD_SETTING) |
5137 return ExpandOldSetting(num_file, file); | |
5138 if (xp->xp_context == EXPAND_BUFFERS) | |
5139 return ExpandBufnames(pat, num_file, file, options); | |
5140 if (xp->xp_context == EXPAND_TAGS | |
5141 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5142 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5143 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5144 { |
5145 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5146 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
|
5147 directories); |
2929 | 5148 } |
7 | 5149 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5150 { |
3106 | 5151 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5152 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5153 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5154 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5155 { |
5156 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5157 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5158 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5159 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5160 { |
5161 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
|
5162 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5163 } |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16287
diff
changeset
|
5164 # if defined(FEAT_EVAL) |
407 | 5165 if (xp->xp_context == EXPAND_USER_LIST) |
856 | 5166 return ExpandUserList(xp, num_file, file); |
407 | 5167 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5168 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5169 return ExpandPackAddDir(pat, num_file, file); |
7 | 5170 |
5171 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5172 if (regmatch.regprog == NULL) | |
5173 return FAIL; | |
5174 | |
5175 /* set ignore-case according to p_ic, p_scs and pat */ | |
5176 regmatch.rm_ic = ignorecase(pat); | |
5177 | |
5178 if (xp->xp_context == EXPAND_SETTINGS | |
5179 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5180 ret = ExpandSettings(xp, ®match, num_file, file); | |
5181 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5182 ret = ExpandMappings(®match, num_file, file); | |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16287
diff
changeset
|
5183 # if defined(FEAT_EVAL) |
7 | 5184 else if (xp->xp_context == EXPAND_USER_DEFINED) |
5185 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5186 # endif | |
5187 else | |
5188 { | |
5189 static struct expgen | |
5190 { | |
5191 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5192 char_u *((*func)(expand_T *, int)); |
7 | 5193 int ic; |
2849 | 5194 int escaped; |
7 | 5195 } tab[] = |
5196 { | |
2849 | 5197 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5198 {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
|
5199 {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
|
5200 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5201 #ifdef FEAT_CMDHIST |
5202 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5203 #endif | |
2849 | 5204 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5205 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5206 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5207 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5208 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5209 #ifdef FEAT_EVAL |
2849 | 5210 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5211 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5212 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5213 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5214 #endif |
5215 #ifdef FEAT_MENU | |
2849 | 5216 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5217 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5218 #endif |
5219 #ifdef FEAT_SYN_HL | |
2849 | 5220 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5221 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5222 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5223 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5224 #endif |
2849 | 5225 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5226 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5227 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5228 #ifdef FEAT_CSCOPE |
2849 | 5229 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5230 #endif |
1868 | 5231 #ifdef FEAT_SIGNS |
2849 | 5232 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5233 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5234 #ifdef FEAT_PROFILE |
2849 | 5235 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5236 #endif |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
5237 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
2849 | 5238 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5239 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5240 #endif | |
5241 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5242 {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
|
5243 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5244 }; |
5245 int i; | |
5246 | |
5247 /* | |
5248 * Find a context in the table and call the ExpandGeneric() with the | |
5249 * right function to do the expansion. | |
5250 */ | |
5251 ret = FAIL; | |
1880 | 5252 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5253 if (xp->xp_context == tab[i].context) |
5254 { | |
5255 if (tab[i].ic) | |
5256 regmatch.rm_ic = TRUE; | |
2849 | 5257 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5258 tab[i].func, tab[i].escaped); |
7 | 5259 break; |
5260 } | |
5261 } | |
5262 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5263 vim_regfree(regmatch.regprog); |
7 | 5264 |
5265 return ret; | |
5266 #endif /* FEAT_CMDL_COMPL */ | |
5267 } | |
5268 | |
5269 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5270 /* | |
5271 * Expand a list of names. | |
5272 * | |
5273 * Generic function for command line completion. It calls a function to | |
5274 * obtain strings, one by one. The strings are matched against a regexp | |
5275 * program. Matching strings are copied into an array, which is returned. | |
5276 * | |
5277 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5278 */ | |
5279 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5280 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5281 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5282 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5283 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5284 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5285 char_u *((*func)(expand_T *, int)), |
7 | 5286 /* 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
|
5287 int escaped) |
7 | 5288 { |
5289 int i; | |
5290 int count = 0; | |
480 | 5291 int round; |
7 | 5292 char_u *str; |
5293 | |
5294 /* do this loop twice: | |
480 | 5295 * round == 0: count the number of matching names |
5296 * round == 1: copy the matching names into allocated memory | |
7 | 5297 */ |
480 | 5298 for (round = 0; round <= 1; ++round) |
7 | 5299 { |
5300 for (i = 0; ; ++i) | |
5301 { | |
5302 str = (*func)(xp, i); | |
5303 if (str == NULL) /* end of list */ | |
5304 break; | |
5305 if (*str == NUL) /* skip empty strings */ | |
5306 continue; | |
5307 | |
5308 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5309 { | |
480 | 5310 if (round) |
7 | 5311 { |
2849 | 5312 if (escaped) |
5313 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5314 else | |
5315 str = vim_strsave(str); | |
7 | 5316 (*file)[count] = str; |
5317 #ifdef FEAT_MENU | |
5318 if (func == get_menu_names && str != NULL) | |
5319 { | |
5320 /* test for separator added by get_menu_names() */ | |
5321 str += STRLEN(str) - 1; | |
5322 if (*str == '\001') | |
5323 *str = '.'; | |
5324 } | |
5325 #endif | |
5326 } | |
5327 ++count; | |
5328 } | |
5329 } | |
480 | 5330 if (round == 0) |
7 | 5331 { |
5332 if (count == 0) | |
5333 return OK; | |
5334 *num_file = count; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
5335 *file = ALLOC_MULT(char_u *, count); |
7 | 5336 if (*file == NULL) |
5337 { | |
5338 *file = (char_u **)""; | |
5339 return FAIL; | |
5340 } | |
5341 count = 0; | |
5342 } | |
5343 } | |
480 | 5344 |
828 | 5345 /* Sort the results. Keep menu's in the specified order. */ |
5346 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5347 { |
5348 if (xp->xp_context == EXPAND_EXPRESSION | |
5349 || xp->xp_context == EXPAND_FUNCTIONS | |
5350 || xp->xp_context == EXPAND_USER_FUNC) | |
5351 /* <SNR> functions should be sorted to the end. */ | |
5352 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5353 sort_func_compare); | |
5354 else | |
5355 sort_strings(*file, *num_file); | |
5356 } | |
480 | 5357 |
1322 | 5358 #ifdef FEAT_CMDL_COMPL |
5359 /* Reset the variables used for special highlight names expansion, so that | |
5360 * they don't show up when getting normal highlight names by ID. */ | |
5361 reset_expand_highlight(); | |
5362 #endif | |
5363 | |
7 | 5364 return OK; |
5365 } | |
5366 | |
716 | 5367 /* |
5368 * Complete a shell command. | |
5369 * Returns FAIL or OK; | |
5370 */ | |
5371 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5372 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5373 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
|
5374 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
|
5375 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
|
5376 int flagsarg) /* EW_ flags */ |
716 | 5377 { |
5378 char_u *pat; | |
5379 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5380 char_u *path = NULL; |
716 | 5381 int mustfree = FALSE; |
5382 garray_T ga; | |
5383 char_u *buf = alloc(MAXPATHL); | |
5384 size_t l; | |
5385 char_u *s, *e; | |
5386 int flags = flagsarg; | |
5387 int ret; | |
6695 | 5388 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5389 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5390 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5391 hash_T hash; |
716 | 5392 |
5393 if (buf == NULL) | |
5394 return FAIL; | |
5395 | |
5396 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5397 * space */ | |
5398 pat = vim_strsave(filepat); | |
5399 for (i = 0; pat[i]; ++i) | |
5400 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5401 STRMOVE(pat + i, pat + i + 1); |
716 | 5402 |
6695 | 5403 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5404 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5405 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
|
5406 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5407 path = (char_u *)"."; |
5408 else | |
2630 | 5409 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5410 /* 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
|
5411 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5412 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5413 if (path == NULL) |
5414 path = (char_u *)""; | |
5415 } | |
716 | 5416 |
5417 /* | |
5418 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5419 * collect them in "ga". When "." is not in $PATH also expand for the |
5420 * current directory, to find "subdir/cmd". | |
716 | 5421 */ |
5422 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
|
5423 hash_init(&found_ht); |
6695 | 5424 for (s = path; ; s = e) |
716 | 5425 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5426 #if defined(MSWIN) |
716 | 5427 e = vim_strchr(s, ';'); |
5428 #else | |
5429 e = vim_strchr(s, ':'); | |
5430 #endif | |
5431 if (e == NULL) | |
5432 e = s + STRLEN(s); | |
5433 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5434 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
|
5435 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5436 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
|
5437 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5438 // 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
|
5439 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
|
5440 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
|
5441 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5442 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
|
5443 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5444 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
|
5445 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
|
5446 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5447 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5448 // 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
|
5449 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
|
5450 |
716 | 5451 l = e - s; |
5452 if (l > MAXPATHL - 5) | |
5453 break; | |
5454 vim_strncpy(buf, s, l); | |
5455 add_pathsep(buf); | |
5456 l = STRLEN(buf); | |
5457 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5458 | |
5459 /* Expand matches in one directory of $PATH. */ | |
5460 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5461 if (ret == OK) | |
5462 { | |
5463 if (ga_grow(&ga, *num_file) == FAIL) | |
5464 FreeWild(*num_file, *file); | |
5465 else | |
5466 { | |
5467 for (i = 0; i < *num_file; ++i) | |
5468 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5469 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5470 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5471 if (STRLEN(name) > l) |
716 | 5472 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5473 // 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
|
5474 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5475 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
|
5476 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5477 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5478 // 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
|
5479 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5480 ((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
|
5481 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
|
5482 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5483 } |
716 | 5484 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5485 vim_free(name); |
716 | 5486 } |
5487 vim_free(*file); | |
5488 } | |
5489 } | |
5490 if (*e != NUL) | |
5491 ++e; | |
5492 } | |
5493 *file = ga.ga_data; | |
5494 *num_file = ga.ga_len; | |
5495 | |
5496 vim_free(buf); | |
5497 vim_free(pat); | |
5498 if (mustfree) | |
5499 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5500 hash_clear(&found_ht); |
716 | 5501 return OK; |
5502 } | |
5503 | |
5504 | |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16287
diff
changeset
|
5505 # if defined(FEAT_EVAL) |
7 | 5506 /* |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5507 * 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
|
5508 * return the result (either a string or a List). |
7 | 5509 */ |
407 | 5510 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5511 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
|
5512 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
|
5513 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5514 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5515 char_u ***file) |
7 | 5516 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5517 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
|
5518 typval_T args[4]; |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5519 sctx_T save_current_sctx = current_sctx; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5520 char_u *pat = NULL; |
407 | 5521 void *ret; |
7 | 5522 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5523 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5524 return NULL; |
7 | 5525 *num_file = 0; |
5526 *file = NULL; | |
5527 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5528 if (ccline.cmdbuff != NULL) |
1518 | 5529 { |
5530 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5531 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5532 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5533 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5534 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
|
5535 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5536 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
|
5537 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
|
5538 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
|
5539 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
|
5540 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
|
5541 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
|
5542 args[3].v_type = VAR_UNKNOWN; |
7 | 5543 |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5544 current_sctx = xp->xp_script_ctx; |
13 | 5545 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5546 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5547 |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14687
diff
changeset
|
5548 current_sctx = save_current_sctx; |
1518 | 5549 if (ccline.cmdbuff != NULL) |
5550 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5551 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5552 vim_free(pat); |
407 | 5553 return ret; |
5554 } | |
5555 | |
5556 /* | |
5557 * Expand names with a function defined by the user. | |
5558 */ | |
5559 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5560 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5561 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5562 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5563 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5564 char_u ***file) |
407 | 5565 { |
5566 char_u *retstr; | |
5567 char_u *s; | |
5568 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
|
5569 int keep; |
407 | 5570 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
|
5571 int skip; |
407 | 5572 |
5573 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5574 if (retstr == NULL) | |
7 | 5575 return FAIL; |
5576 | |
5577 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5578 for (s = retstr; *s != NUL; s = e) |
7 | 5579 { |
5580 e = vim_strchr(s, '\n'); | |
5581 if (e == NULL) | |
5582 e = s + STRLEN(s); | |
5583 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
|
5584 *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
|
5585 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5586 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
|
5587 *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
|
5588 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5589 if (!skip) |
7 | 5590 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5591 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
|
5592 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5593 ((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
|
5594 ++ga.ga_len; |
7 | 5595 } |
5596 | |
5597 if (*e != NUL) | |
5598 ++e; | |
5599 } | |
407 | 5600 vim_free(retstr); |
5601 *file = ga.ga_data; | |
5602 *num_file = ga.ga_len; | |
5603 return OK; | |
5604 } | |
5605 | |
5606 /* | |
5607 * Expand names with a list returned by a function defined by the user. | |
5608 */ | |
5609 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5610 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5611 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5612 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5613 char_u ***file) |
407 | 5614 { |
5615 list_T *retlist; | |
5616 listitem_T *li; | |
5617 garray_T ga; | |
5618 | |
5619 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5620 if (retlist == NULL) | |
5621 return FAIL; | |
5622 | |
5623 ga_init2(&ga, (int)sizeof(char *), 3); | |
5624 /* Loop over the items in the list. */ | |
5625 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5626 { | |
1917 | 5627 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5628 continue; /* Skip non-string items and empty strings */ | |
407 | 5629 |
5630 if (ga_grow(&ga, 1) == FAIL) | |
5631 break; | |
5632 | |
5633 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5634 vim_strsave(li->li_tv.vval.v_string); |
407 | 5635 ++ga.ga_len; |
5636 } | |
5637 list_unref(retlist); | |
5638 | |
7 | 5639 *file = ga.ga_data; |
5640 *num_file = ga.ga_len; | |
5641 return OK; | |
5642 } | |
5643 #endif | |
5644 | |
5645 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5646 * 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
|
5647 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5648 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5649 * 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
|
5650 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5651 * 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
|
5652 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5653 * "dirnames" is an array with one or more directory names. |
7 | 5654 */ |
5655 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5656 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5657 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5658 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5659 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5660 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5661 char *dirnames[]) |
7 | 5662 { |
5663 char_u *s; | |
5664 char_u *e; | |
5873 | 5665 char_u *match; |
7 | 5666 garray_T ga; |
2929 | 5667 int i; |
5668 int pat_len; | |
7 | 5669 |
5670 *num_file = 0; | |
5671 *file = NULL; | |
2931 | 5672 pat_len = (int)STRLEN(pat); |
2929 | 5673 ga_init2(&ga, (int)sizeof(char *), 10); |
5674 | |
5675 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5676 { |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5677 s = alloc(STRLEN(dirnames[i]) + pat_len + 7); |
2929 | 5678 if (s == NULL) |
5679 { | |
5680 ga_clear_strings(&ga); | |
5681 return FAIL; | |
5682 } | |
5683 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5684 globpath(p_rtp, s, &ga, 0); |
2929 | 5685 vim_free(s); |
5873 | 5686 } |
5687 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5688 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5689 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
|
5690 { |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5691 s = alloc(STRLEN(dirnames[i]) + pat_len + 22); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5692 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5693 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5694 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5695 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5696 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5697 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
|
5698 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5699 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5700 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5701 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5702 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5703 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5704 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
|
5705 { |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5706 s = alloc(STRLEN(dirnames[i]) + pat_len + 20); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5707 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5708 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5709 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5710 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5711 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5712 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
|
5713 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5714 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5715 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5716 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5717 |
5873 | 5718 for (i = 0; i < ga.ga_len; ++i) |
5719 { | |
5720 match = ((char_u **)ga.ga_data)[i]; | |
5721 s = match; | |
5722 e = s + STRLEN(s); | |
5723 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5724 { |
5873 | 5725 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5726 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5727 if (s < match || vim_ispathsep(*s)) |
5728 break; | |
5729 ++s; | |
5730 *e = NUL; | |
5731 mch_memmove(match, s, e - s + 1); | |
7 | 5732 } |
5733 } | |
5873 | 5734 |
2929 | 5735 if (ga.ga_len == 0) |
3628 | 5736 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5737 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5738 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5739 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5740 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5741 |
7 | 5742 *file = ga.ga_data; |
5743 *num_file = ga.ga_len; | |
5744 return OK; | |
5745 } | |
5746 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5747 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5748 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5749 * 'packpath'/pack/ * /opt/{pat} |
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 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5752 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5753 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5754 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5755 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5756 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5757 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5758 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5759 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5760 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5761 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5762 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5763 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5764 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5765 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5766 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5767 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
|
5768 |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5769 s = alloc(pat_len + 26); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5770 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5771 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5772 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5773 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5774 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5775 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
|
5776 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5777 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5778 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5779 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
|
5780 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5781 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
|
5782 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5783 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5784 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
|
5785 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5786 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5787 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5788 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5789 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5790 /* 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
|
5791 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5792 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5793 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5794 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5795 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5796 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5797 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5798 |
7 | 5799 #endif |
5800 | |
5801 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5802 /* | |
5803 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5804 * Adds the matches to "ga". Caller must init "ga". |
7 | 5805 */ |
5873 | 5806 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5807 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5808 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5809 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5810 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5811 int expand_options) |
7 | 5812 { |
5813 expand_T xpc; | |
5814 char_u *buf; | |
5815 int i; | |
5816 int num_p; | |
5817 char_u **p; | |
5818 | |
5819 buf = alloc(MAXPATHL); | |
5820 if (buf == NULL) | |
5873 | 5821 return; |
7 | 5822 |
632 | 5823 ExpandInit(&xpc); |
7 | 5824 xpc.xp_context = EXPAND_FILES; |
632 | 5825 |
7 | 5826 /* Loop over all entries in {path}. */ |
5827 while (*path != NUL) | |
5828 { | |
5829 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5830 copy_option_part(&path, buf, MAXPATHL, ","); | |
5831 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5832 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5833 # 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
|
5834 /* 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
|
5835 * 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
|
5836 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
|
5837 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5838 # else |
7 | 5839 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
|
5840 # endif |
7 | 5841 STRCAT(buf, file); |
1754 | 5842 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5843 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5844 { |
1754 | 5845 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5846 |
5847 if (ga_grow(ga, num_p) == OK) | |
7 | 5848 { |
5849 for (i = 0; i < num_p; ++i) | |
5850 { | |
5873 | 5851 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5852 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5853 ++ga->ga_len; |
7 | 5854 } |
5855 } | |
5873 | 5856 |
7 | 5857 FreeWild(num_p, p); |
5858 } | |
5859 } | |
5860 } | |
5861 | |
5862 vim_free(buf); | |
5863 } | |
5864 | |
5865 #endif | |
5866 | |
5867 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5868 | |
5869 /********************************* | |
5870 * Command line history stuff * | |
5871 *********************************/ | |
5872 | |
5873 /* | |
5874 * Translate a history character to the associated type number. | |
5875 */ | |
5876 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5877 hist_char2type(int c) |
7 | 5878 { |
5879 if (c == ':') | |
5880 return HIST_CMD; | |
5881 if (c == '=') | |
5882 return HIST_EXPR; | |
5883 if (c == '@') | |
5884 return HIST_INPUT; | |
5885 if (c == '>') | |
5886 return HIST_DEBUG; | |
5887 return HIST_SEARCH; /* must be '?' or '/' */ | |
5888 } | |
5889 | |
5890 /* | |
5891 * Table of history names. | |
5892 * These names are used in :history and various hist...() functions. | |
5893 * It is sufficient to give the significant prefix of a history name. | |
5894 */ | |
5895 | |
5896 static char *(history_names[]) = | |
5897 { | |
5898 "cmd", | |
5899 "search", | |
5900 "expr", | |
5901 "input", | |
5902 "debug", | |
5903 NULL | |
5904 }; | |
5905 | |
3503 | 5906 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5907 /* | |
5908 * Function given to ExpandGeneric() to obtain the possible first | |
5909 * arguments of the ":history command. | |
5910 */ | |
5911 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5912 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5913 { |
5914 static char_u compl[2] = { NUL, NUL }; | |
5915 char *short_names = ":=@>?/"; | |
3529 | 5916 int short_names_count = (int)STRLEN(short_names); |
3503 | 5917 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5918 | |
5919 if (idx < short_names_count) | |
5920 { | |
5921 compl[0] = (char_u)short_names[idx]; | |
5922 return compl; | |
5923 } | |
5924 if (idx < short_names_count + history_name_count) | |
5925 return (char_u *)history_names[idx - short_names_count]; | |
5926 if (idx == short_names_count + history_name_count) | |
5927 return (char_u *)"all"; | |
5928 return NULL; | |
5929 } | |
5930 #endif | |
5931 | |
7 | 5932 /* |
5933 * init_history() - Initialize the command line history. | |
5934 * Also used to re-allocate the history when the size changes. | |
5935 */ | |
356 | 5936 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5937 init_history(void) |
7 | 5938 { |
5939 int newlen; /* new length of history table */ | |
5940 histentry_T *temp; | |
5941 int i; | |
5942 int j; | |
5943 int type; | |
5944 | |
5945 /* | |
5946 * If size of history table changed, reallocate it | |
5947 */ | |
5948 newlen = (int)p_hi; | |
5949 if (newlen != hislen) /* history length changed */ | |
5950 { | |
5951 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
5952 { | |
5953 if (newlen) | |
5954 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
5955 temp = ALLOC_MULT(histentry_T, newlen); |
7 | 5956 if (temp == NULL) /* out of memory! */ |
5957 { | |
5958 if (type == 0) /* first one: just keep the old length */ | |
5959 { | |
5960 newlen = hislen; | |
5961 break; | |
5962 } | |
5963 /* Already changed one table, now we can only have zero | |
5964 * length for all tables. */ | |
5965 newlen = 0; | |
5966 type = -1; | |
5967 continue; | |
5968 } | |
5969 } | |
5970 else | |
5971 temp = NULL; | |
5972 if (newlen == 0 || temp != NULL) | |
5973 { | |
5974 if (hisidx[type] < 0) /* there are no entries yet */ | |
5975 { | |
5976 for (i = 0; i < newlen; ++i) | |
4258 | 5977 clear_hist_entry(&temp[i]); |
7 | 5978 } |
5979 else if (newlen > hislen) /* array becomes bigger */ | |
5980 { | |
5981 for (i = 0; i <= hisidx[type]; ++i) | |
5982 temp[i] = history[type][i]; | |
5983 j = i; | |
5984 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 5985 clear_hist_entry(&temp[i]); |
7 | 5986 for ( ; j < hislen; ++i, ++j) |
5987 temp[i] = history[type][j]; | |
5988 } | |
5989 else /* array becomes smaller or 0 */ | |
5990 { | |
5991 j = hisidx[type]; | |
5992 for (i = newlen - 1; ; --i) | |
5993 { | |
5994 if (i >= 0) /* copy newest entries */ | |
5995 temp[i] = history[type][j]; | |
5996 else /* remove older entries */ | |
5997 vim_free(history[type][j].hisstr); | |
5998 if (--j < 0) | |
5999 j = hislen - 1; | |
6000 if (j == hisidx[type]) | |
6001 break; | |
6002 } | |
6003 hisidx[type] = newlen - 1; | |
6004 } | |
6005 vim_free(history[type]); | |
6006 history[type] = temp; | |
6007 } | |
6008 } | |
6009 hislen = newlen; | |
6010 } | |
6011 } | |
6012 | |
4258 | 6013 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6014 clear_hist_entry(histentry_T *hisptr) |
4258 | 6015 { |
6016 hisptr->hisnum = 0; | |
6017 hisptr->viminfo = FALSE; | |
6018 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6019 hisptr->time_set = 0; |
4258 | 6020 } |
6021 | |
7 | 6022 /* |
6023 * Check if command line 'str' is already in history. | |
6024 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6025 */ | |
6026 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6027 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6028 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6029 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6030 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
|
6031 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6032 int writing) /* ignore entries read from viminfo */ |
7 | 6033 { |
6034 int i; | |
6035 int last_i = -1; | |
2986 | 6036 char_u *p; |
7 | 6037 |
6038 if (hisidx[type] < 0) | |
6039 return FALSE; | |
6040 i = hisidx[type]; | |
6041 do | |
6042 { | |
6043 if (history[type][i].hisstr == NULL) | |
6044 return FALSE; | |
2986 | 6045 |
6046 /* For search history, check that the separator character matches as | |
6047 * well. */ | |
6048 p = history[type][i].hisstr; | |
6049 if (STRCMP(str, p) == 0 | |
4285 | 6050 && !(writing && history[type][i].viminfo) |
2986 | 6051 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6052 { |
6053 if (!move_to_front) | |
6054 return TRUE; | |
6055 last_i = i; | |
6056 break; | |
6057 } | |
6058 if (--i < 0) | |
6059 i = hislen - 1; | |
6060 } while (i != hisidx[type]); | |
6061 | |
6062 if (last_i >= 0) | |
6063 { | |
6064 str = history[type][i].hisstr; | |
6065 while (i != hisidx[type]) | |
6066 { | |
6067 if (++i >= hislen) | |
6068 i = 0; | |
6069 history[type][last_i] = history[type][i]; | |
6070 last_i = i; | |
6071 } | |
4258 | 6072 history[type][i].hisnum = ++hisnum[type]; |
6073 history[type][i].viminfo = FALSE; | |
7 | 6074 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6075 history[type][i].time_set = vim_time(); |
7 | 6076 return TRUE; |
6077 } | |
6078 return FALSE; | |
6079 } | |
6080 | |
6081 /* | |
6082 * Convert history name (from table above) to its HIST_ equivalent. | |
6083 * When "name" is empty, return "cmd" history. | |
6084 * Returns -1 for unknown history name. | |
6085 */ | |
6086 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6087 get_histtype(char_u *name) |
7 | 6088 { |
6089 int i; | |
6090 int len = (int)STRLEN(name); | |
6091 | |
6092 /* No argument: use current history. */ | |
6093 if (len == 0) | |
6094 return hist_char2type(ccline.cmdfirstc); | |
6095 | |
6096 for (i = 0; history_names[i] != NULL; ++i) | |
6097 if (STRNICMP(name, history_names[i], len) == 0) | |
6098 return i; | |
6099 | |
6100 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6101 return hist_char2type(name[0]); | |
6102 | |
6103 return -1; | |
6104 } | |
6105 | |
6106 static int last_maptick = -1; /* last seen maptick */ | |
6107 | |
6108 /* | |
6109 * Add the given string to the given history. If the string is already in the | |
6110 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6111 * values. | |
6112 */ | |
6113 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6114 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6115 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6116 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6117 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
|
6118 int sep) /* separator character used (search hist) */ |
7 | 6119 { |
6120 histentry_T *hisptr; | |
6121 int len; | |
6122 | |
6123 if (hislen == 0) /* no history */ | |
6124 return; | |
6125 | |
5467 | 6126 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6127 return; | |
6128 | |
7 | 6129 /* |
6130 * Searches inside the same mapping overwrite each other, so that only | |
6131 * the last line is kept. Be careful not to remove a line that was moved | |
6132 * down, only lines that were added. | |
6133 */ | |
6134 if (histype == HIST_SEARCH && in_map) | |
6135 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6136 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6137 { |
6138 /* Current line is from the same mapping, remove it */ | |
6139 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6140 vim_free(hisptr->hisstr); | |
4258 | 6141 clear_hist_entry(hisptr); |
7 | 6142 --hisnum[histype]; |
6143 if (--hisidx[HIST_SEARCH] < 0) | |
6144 hisidx[HIST_SEARCH] = hislen - 1; | |
6145 } | |
6146 last_maptick = -1; | |
6147 } | |
4285 | 6148 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6149 { |
6150 if (++hisidx[histype] == hislen) | |
6151 hisidx[histype] = 0; | |
6152 hisptr = &history[histype][hisidx[histype]]; | |
6153 vim_free(hisptr->hisstr); | |
6154 | |
6155 /* Store the separator after the NUL of the string. */ | |
835 | 6156 len = (int)STRLEN(new_entry); |
7 | 6157 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6158 if (hisptr->hisstr != NULL) | |
6159 hisptr->hisstr[len + 1] = sep; | |
6160 | |
6161 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6162 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6163 hisptr->time_set = vim_time(); |
7 | 6164 if (histype == HIST_SEARCH && in_map) |
6165 last_maptick = maptick; | |
6166 } | |
6167 } | |
6168 | |
6169 #if defined(FEAT_EVAL) || defined(PROTO) | |
6170 | |
6171 /* | |
6172 * Get identifier of newest history entry. | |
6173 * "histype" may be one of the HIST_ values. | |
6174 */ | |
6175 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6176 get_history_idx(int histype) |
7 | 6177 { |
6178 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6179 || hisidx[histype] < 0) | |
6180 return -1; | |
6181 | |
6182 return history[histype][hisidx[histype]].hisnum; | |
6183 } | |
6184 | |
531 | 6185 /* |
7 | 6186 * Calculate history index from a number: |
6187 * num > 0: seen as identifying number of a history entry | |
6188 * num < 0: relative position in history wrt newest entry | |
6189 * "histype" may be one of the HIST_ values. | |
6190 */ | |
6191 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6192 calc_hist_idx(int histype, int num) |
7 | 6193 { |
6194 int i; | |
6195 histentry_T *hist; | |
6196 int wrapped = FALSE; | |
6197 | |
6198 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6199 || (i = hisidx[histype]) < 0 || num == 0) | |
6200 return -1; | |
6201 | |
6202 hist = history[histype]; | |
6203 if (num > 0) | |
6204 { | |
6205 while (hist[i].hisnum > num) | |
6206 if (--i < 0) | |
6207 { | |
6208 if (wrapped) | |
6209 break; | |
6210 i += hislen; | |
6211 wrapped = TRUE; | |
6212 } | |
6213 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6214 return i; | |
6215 } | |
6216 else if (-num <= hislen) | |
6217 { | |
6218 i += num + 1; | |
6219 if (i < 0) | |
6220 i += hislen; | |
6221 if (hist[i].hisstr != NULL) | |
6222 return i; | |
6223 } | |
6224 return -1; | |
6225 } | |
6226 | |
6227 /* | |
6228 * Get a history entry by its index. | |
6229 * "histype" may be one of the HIST_ values. | |
6230 */ | |
6231 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6232 get_history_entry(int histype, int idx) |
7 | 6233 { |
6234 idx = calc_hist_idx(histype, idx); | |
6235 if (idx >= 0) | |
6236 return history[histype][idx].hisstr; | |
6237 else | |
6238 return (char_u *)""; | |
6239 } | |
6240 | |
6241 /* | |
6242 * Clear all entries of a history. | |
6243 * "histype" may be one of the HIST_ values. | |
6244 */ | |
6245 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6246 clr_history(int histype) |
7 | 6247 { |
6248 int i; | |
6249 histentry_T *hisptr; | |
6250 | |
6251 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6252 { | |
6253 hisptr = history[histype]; | |
6254 for (i = hislen; i--;) | |
6255 { | |
6256 vim_free(hisptr->hisstr); | |
4258 | 6257 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6258 hisptr++; |
7 | 6259 } |
6260 hisidx[histype] = -1; /* mark history as cleared */ | |
6261 hisnum[histype] = 0; /* reset identifier counter */ | |
6262 return OK; | |
6263 } | |
6264 return FAIL; | |
6265 } | |
6266 | |
6267 /* | |
6268 * Remove all entries matching {str} from a history. | |
6269 * "histype" may be one of the HIST_ values. | |
6270 */ | |
6271 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6272 del_history_entry(int histype, char_u *str) |
7 | 6273 { |
6274 regmatch_T regmatch; | |
6275 histentry_T *hisptr; | |
6276 int idx; | |
6277 int i; | |
6278 int last; | |
6279 int found = FALSE; | |
6280 | |
6281 regmatch.regprog = NULL; | |
6282 regmatch.rm_ic = FALSE; /* always match case */ | |
6283 if (hislen != 0 | |
6284 && histype >= 0 | |
6285 && histype < HIST_COUNT | |
6286 && *str != NUL | |
6287 && (idx = hisidx[histype]) >= 0 | |
6288 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6289 != NULL) | |
6290 { | |
6291 i = last = idx; | |
6292 do | |
6293 { | |
6294 hisptr = &history[histype][i]; | |
6295 if (hisptr->hisstr == NULL) | |
6296 break; | |
6297 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6298 { | |
6299 found = TRUE; | |
6300 vim_free(hisptr->hisstr); | |
4258 | 6301 clear_hist_entry(hisptr); |
7 | 6302 } |
6303 else | |
6304 { | |
6305 if (i != last) | |
6306 { | |
6307 history[histype][last] = *hisptr; | |
4258 | 6308 clear_hist_entry(hisptr); |
7 | 6309 } |
6310 if (--last < 0) | |
6311 last += hislen; | |
6312 } | |
6313 if (--i < 0) | |
6314 i += hislen; | |
6315 } while (i != idx); | |
6316 if (history[histype][idx].hisstr == NULL) | |
6317 hisidx[histype] = -1; | |
6318 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6319 vim_regfree(regmatch.regprog); |
7 | 6320 return found; |
6321 } | |
6322 | |
6323 /* | |
6324 * Remove an indexed entry from a history. | |
6325 * "histype" may be one of the HIST_ values. | |
6326 */ | |
6327 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6328 del_history_idx(int histype, int idx) |
7 | 6329 { |
6330 int i, j; | |
6331 | |
6332 i = calc_hist_idx(histype, idx); | |
6333 if (i < 0) | |
6334 return FALSE; | |
6335 idx = hisidx[histype]; | |
6336 vim_free(history[histype][i].hisstr); | |
6337 | |
6338 /* When deleting the last added search string in a mapping, reset | |
6339 * last_maptick, so that the last added search string isn't deleted again. | |
6340 */ | |
6341 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6342 last_maptick = -1; | |
6343 | |
6344 while (i != idx) | |
6345 { | |
6346 j = (i + 1) % hislen; | |
6347 history[histype][i] = history[histype][j]; | |
6348 i = j; | |
6349 } | |
4258 | 6350 clear_hist_entry(&history[histype][i]); |
7 | 6351 if (--i < 0) |
6352 i += hislen; | |
6353 hisidx[histype] = i; | |
6354 return TRUE; | |
6355 } | |
6356 | |
6357 #endif /* FEAT_EVAL */ | |
6358 | |
6359 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6360 /* | |
6361 * Very specific function to remove the value in ":set key=val" from the | |
6362 * history. | |
6363 */ | |
6364 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6365 remove_key_from_history(void) |
7 | 6366 { |
6367 char_u *p; | |
6368 int i; | |
6369 | |
6370 i = hisidx[HIST_CMD]; | |
6371 if (i < 0) | |
6372 return; | |
6373 p = history[HIST_CMD][i].hisstr; | |
6374 if (p != NULL) | |
6375 for ( ; *p; ++p) | |
6376 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6377 { | |
6378 p = vim_strchr(p + 3, '='); | |
6379 if (p == NULL) | |
6380 break; | |
6381 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6382 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6383 if (p[i] == '\\' && p[i + 1]) |
6384 ++i; | |
1621 | 6385 STRMOVE(p, p + i); |
7 | 6386 --p; |
6387 } | |
6388 } | |
6389 #endif | |
6390 | |
6391 #endif /* FEAT_CMDHIST */ | |
6392 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6393 #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
|
6394 /* |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
6395 * Get pointer to the command line info to use. save_ccline() may clear |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6396 * 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
|
6397 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6398 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6399 get_ccline_ptr(void) |
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 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6402 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6403 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6404 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6405 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
|
6406 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6407 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6408 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6409 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6410 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6411 #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
|
6412 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6413 * 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
|
6414 * 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
|
6415 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6416 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6417 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6418 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6419 { |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6420 struct cmdline_info *p; |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6421 |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6422 if (cmdline_star > 0) |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6423 return NULL; |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
6424 p = get_ccline_ptr(); |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6425 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6426 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6427 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
|
6428 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6429 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6430 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6431 * 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
|
6432 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6433 * 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
|
6434 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6435 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6436 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6437 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6438 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6439 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
|
6440 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6441 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6442 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6443 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6444 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6445 |
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 * 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
|
6448 * 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
|
6449 * 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
|
6450 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6451 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6452 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6453 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6454 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6455 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
|
6456 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6457 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6458 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6459 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6460 /* 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
|
6461 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6462 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6463 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6464 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6465 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6466 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6467 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6468 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6469 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6470 #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
|
6471 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6472 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6473 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6474 * 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
|
6475 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6476 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6477 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6478 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6479 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6480 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
|
6481 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6482 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6483 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6484 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6485 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6486 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6487 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6488 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6489 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6490 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6491 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6492 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6493 |
7 | 6494 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6495 /* | |
6496 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6497 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6498 * Returns OK if parsed successfully, otherwise FAIL. | |
6499 */ | |
6500 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6501 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6502 { |
6503 int len; | |
6504 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6505 varnumber_T num; |
7 | 6506 |
6507 *str = skipwhite(*str); | |
6508 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6509 { | |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
6510 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE); |
7 | 6511 *str += len; |
6512 *num1 = (int)num; | |
6513 first = TRUE; | |
6514 } | |
6515 *str = skipwhite(*str); | |
6516 if (**str == ',') /* parse "to" part of range */ | |
6517 { | |
6518 *str = skipwhite(*str + 1); | |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
6519 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE); |
7 | 6520 if (len > 0) |
6521 { | |
6522 *num2 = (int)num; | |
6523 *str = skipwhite(*str + len); | |
6524 } | |
6525 else if (!first) /* no number given at all */ | |
6526 return FAIL; | |
6527 } | |
6528 else if (first) /* only one number given */ | |
6529 *num2 = *num1; | |
6530 return OK; | |
6531 } | |
6532 #endif | |
6533 | |
6534 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6535 /* | |
6536 * :history command - print a history | |
6537 */ | |
6538 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6539 ex_history(exarg_T *eap) |
7 | 6540 { |
6541 histentry_T *hist; | |
6542 int histype1 = HIST_CMD; | |
6543 int histype2 = HIST_CMD; | |
6544 int hisidx1 = 1; | |
6545 int hisidx2 = -1; | |
6546 int idx; | |
6547 int i, j, k; | |
6548 char_u *end; | |
6549 char_u *arg = eap->arg; | |
6550 | |
6551 if (hislen == 0) | |
6552 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6553 msg(_("'history' option is zero")); |
7 | 6554 return; |
6555 } | |
6556 | |
6557 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6558 { | |
6559 end = arg; | |
6560 while (ASCII_ISALPHA(*end) | |
6561 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6562 end++; | |
6563 i = *end; | |
6564 *end = NUL; | |
6565 histype1 = get_histtype(arg); | |
6566 if (histype1 == -1) | |
6567 { | |
1853 | 6568 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6569 { |
6570 histype1 = 0; | |
6571 histype2 = HIST_COUNT-1; | |
6572 } | |
6573 else | |
6574 { | |
6575 *end = i; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
6576 emsg(_(e_trailing)); |
7 | 6577 return; |
6578 } | |
6579 } | |
6580 else | |
6581 histype2 = histype1; | |
6582 *end = i; | |
6583 } | |
6584 else | |
6585 end = arg; | |
6586 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6587 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
6588 emsg(_(e_trailing)); |
7 | 6589 return; |
6590 } | |
6591 | |
6592 for (; !got_int && histype1 <= histype2; ++histype1) | |
6593 { | |
6594 STRCPY(IObuff, "\n # "); | |
6595 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6596 msg_puts_title((char *)IObuff); |
7 | 6597 idx = hisidx[histype1]; |
6598 hist = history[histype1]; | |
6599 j = hisidx1; | |
6600 k = hisidx2; | |
6601 if (j < 0) | |
6602 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6603 if (k < 0) | |
6604 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6605 if (idx >= 0 && j <= k) | |
6606 for (i = idx + 1; !got_int; ++i) | |
6607 { | |
6608 if (i == hislen) | |
6609 i = 0; | |
6610 if (hist[i].hisstr != NULL | |
6611 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6612 { | |
6613 msg_putchar('\n'); | |
6614 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6615 hist[i].hisnum); | |
6616 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6617 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6618 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6619 else |
6620 STRCAT(IObuff, hist[i].hisstr); | |
6621 msg_outtrans(IObuff); | |
6622 out_flush(); | |
6623 } | |
6624 if (i == idx) | |
6625 break; | |
6626 } | |
6627 } | |
6628 } | |
6629 #endif | |
6630 | |
6631 #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
|
6632 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6633 * 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
|
6634 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6635 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
|
6636 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6637 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
|
6638 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6639 static int viminfo_add_at_front = FALSE; |
6640 | |
6641 /* | |
6642 * Translate a history type number to the associated character. | |
6643 */ | |
6644 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6645 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6646 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6647 int use_question) /* use '?' instead of '/' */ |
7 | 6648 { |
6649 if (type == HIST_CMD) | |
6650 return ':'; | |
6651 if (type == HIST_SEARCH) | |
6652 { | |
6653 if (use_question) | |
6654 return '?'; | |
6655 else | |
6656 return '/'; | |
6657 } | |
6658 if (type == HIST_EXPR) | |
6659 return '='; | |
6660 return '@'; | |
6661 } | |
6662 | |
6663 /* | |
6664 * Prepare for reading the history from the viminfo file. | |
6665 * This allocates history arrays to store the read history lines. | |
6666 */ | |
6667 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6668 prepare_viminfo_history(int asklen, int writing) |
7 | 6669 { |
6670 int i; | |
6671 int num; | |
6672 int type; | |
6673 int len; | |
6674 | |
6675 init_history(); | |
4285 | 6676 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6677 if (asklen > hislen) |
6678 asklen = hislen; | |
6679 | |
6680 for (type = 0; type < HIST_COUNT; ++type) | |
6681 { | |
4258 | 6682 /* Count the number of empty spaces in the history list. Entries read |
6683 * from viminfo previously are also considered empty. If there are | |
6684 * more spaces available than we request, then fill them up. */ | |
7 | 6685 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6686 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6687 num++; |
6688 len = asklen; | |
6689 if (num > len) | |
6690 len = num; | |
6691 if (len <= 0) | |
6692 viminfo_history[type] = NULL; | |
6693 else | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6694 viminfo_history[type] = LALLOC_MULT(histentry_T, len); |
7 | 6695 if (viminfo_history[type] == NULL) |
6696 len = 0; | |
6697 viminfo_hislen[type] = len; | |
6698 viminfo_hisidx[type] = 0; | |
6699 } | |
6700 } | |
6701 | |
6702 /* | |
6703 * Accept a line from the viminfo, store it in the history array when it's | |
6704 * new. | |
6705 */ | |
6706 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6707 read_viminfo_history(vir_T *virp, int writing) |
7 | 6708 { |
6709 int type; | |
6710 long_u len; | |
6711 char_u *val; | |
6712 char_u *p; | |
6713 | |
6714 type = hist_char2type(virp->vir_line[0]); | |
6715 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6716 { | |
6717 val = viminfo_readstring(virp, 1, TRUE); | |
6718 if (val != NULL && *val != NUL) | |
6719 { | |
3316 | 6720 int sep = (*val == ' ' ? NUL : *val); |
6721 | |
7 | 6722 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6723 viminfo_add_at_front, sep, writing)) |
7 | 6724 { |
6725 /* Need to re-allocate to append the separator byte. */ | |
6726 len = STRLEN(val); | |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
6727 p = alloc(len + 2); |
7 | 6728 if (p != NULL) |
6729 { | |
6730 if (type == HIST_SEARCH) | |
6731 { | |
6732 /* Search entry: Move the separator from the first | |
6733 * column to after the NUL. */ | |
6734 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6735 p[len] = sep; |
7 | 6736 } |
6737 else | |
6738 { | |
6739 /* Not a search entry: No separator in the viminfo | |
6740 * file, add a NUL separator. */ | |
6741 mch_memmove(p, val, (size_t)len + 1); | |
6742 p[len + 1] = NUL; | |
6743 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6744 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
|
6745 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
|
6746 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
|
6747 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
|
6748 viminfo_hisidx[type]++; |
7 | 6749 } |
6750 } | |
6751 } | |
6752 vim_free(val); | |
6753 } | |
6754 return viminfo_readline(virp); | |
6755 } | |
6756 | |
4285 | 6757 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6758 * 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
|
6759 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6760 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6761 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6762 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6763 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6764 int writing) |
9240
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 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6767 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6768 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6769 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6770 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
|
6771 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6772 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6773 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6774 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6775 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6776 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6777 || (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
|
6778 || 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
|
6779 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6780 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6781 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6782 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6783 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6784 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
|
6785 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6786 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6787 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6788 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6789 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
|
6790 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6791 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6792 int overwrite = FALSE; |
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 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
|
6795 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6796 /* 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
|
6797 * 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
|
6798 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
|
6799 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6800 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6801 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6802 && (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
|
6803 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6804 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6805 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6806 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6807 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6808 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6809 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6810 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6811 /* 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
|
6812 len = vp[3].bv_len; |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
6813 p = alloc(len + 2); |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6814 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6815 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6816 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6817 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6818 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6819 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
|
6820 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6821 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6822 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
|
6823 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6824 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6825 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
|
6826 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6827 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
|
6828 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6829 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6830 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6831 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6832 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6833 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6834 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6835 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6836 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6837 * 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
|
6838 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6839 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6840 concat_history(int type) |
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 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6843 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6844 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6845 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6846 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6847 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6848 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6849 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6850 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6851 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6852 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6853 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6854 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6855 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6856 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6857 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6858 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6859 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6860 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6861 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6862 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6863 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6864 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6865 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6866 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6867 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
|
6868 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6869 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6870 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
|
6871 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6872 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
|
6873 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6874 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6875 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6876 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6877 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6878 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
|
6879 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6880 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6881 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6882 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6883 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6884 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6885 #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
|
6886 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6887 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
|
6888 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6889 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6890 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6891 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6892 if (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
|
6893 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
|
6894 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6895 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6896 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6897 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6898 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6899 * 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
|
6900 * timestamp; |
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 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6903 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6904 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6907 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6908 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6909 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6911 /* 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
|
6912 max_len = hislen + viminfo_hisidx[type]; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6913 tot_hist = ALLOC_MULT(histentry_T *, max_len); |
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6914 new_hist = ALLOC_MULT(histentry_T, hislen ); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6915 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
|
6916 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6920 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6921 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
|
6922 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
|
6923 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6926 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6929 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
|
6930 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6933 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6934 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6935 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6936 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6937 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6938 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6939 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6940 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6942 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6943 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6944 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
|
6945 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6946 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6947 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
|
6948 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
|
6949 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6950 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6951 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6952 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
6953 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6954 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6955 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6956 /* |
4285 | 6957 * Finish reading history lines from viminfo. Not used when writing viminfo. |
6958 */ | |
7 | 6959 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6960 finish_viminfo_history(vir_T *virp) |
7 | 6961 { |
6962 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6963 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 6964 |
6965 for (type = 0; type < HIST_COUNT; ++type) | |
6966 { | |
6967 if (history[type] == NULL) | |
4283 | 6968 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6969 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6970 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6971 merge_history(type); |
7 | 6972 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6973 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6974 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
6975 VIM_CLEAR(viminfo_history[type]); |
4327 | 6976 viminfo_hisidx[type] = 0; |
7 | 6977 } |
6978 } | |
6979 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6980 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6981 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6982 * 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
|
6983 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6984 * 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
|
6985 */ |
7 | 6986 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6987 write_viminfo_history(FILE *fp, int merge) |
7 | 6988 { |
6989 int i; | |
6990 int type; | |
6991 int num_saved; | |
4283 | 6992 int round; |
7 | 6993 |
6994 init_history(); | |
6995 if (hislen == 0) | |
6996 return; | |
6997 for (type = 0; type < HIST_COUNT; ++type) | |
6998 { | |
6999 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
7000 if (num_saved == 0) | |
7001 continue; | |
7002 if (num_saved < 0) /* Use default */ | |
7003 num_saved = hislen; | |
7004 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7005 type == HIST_CMD ? _("Command Line") : | |
7006 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7007 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7008 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7009 _("Debug Line")); |
7 | 7010 if (num_saved > hislen) |
7011 num_saved = hislen; | |
4283 | 7012 |
7013 /* | |
7014 * Merge typed and viminfo history: | |
7015 * round 1: history of typed commands. | |
7016 * round 2: history from recently read viminfo. | |
7017 */ | |
7018 for (round = 1; round <= 2; ++round) | |
7019 { | |
4307 | 7020 if (round == 1) |
7021 /* start at newest entry, somewhere in the list */ | |
7022 i = hisidx[type]; | |
7023 else if (viminfo_hisidx[type] > 0) | |
7024 /* start at newest entry, first in the list */ | |
7025 i = 0; | |
7026 else | |
7027 /* empty list */ | |
7028 i = -1; | |
4283 | 7029 if (i >= 0) |
7030 while (num_saved > 0 | |
7031 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7032 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7033 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7034 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7035 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7036 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7037 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7038 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7039 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7040 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7041 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7042 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7043 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7044 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7045 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7046 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7047 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7048 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7049 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7050 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7051 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7052 || !history[type][i].viminfo)) |
7 | 7053 { |
4283 | 7054 --num_saved; |
7055 fputc(hist_type2char(type, TRUE), fp); | |
7056 /* For the search history: put the separator in the | |
7057 * second column; use a space if there isn't one. */ | |
7058 if (type == HIST_SEARCH) | |
7059 { | |
7060 c = p[STRLEN(p) + 1]; | |
7061 putc(c == NUL ? ' ' : c, fp); | |
7062 } | |
7063 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7064 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7065 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7066 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7067 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7068 /* 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
|
7069 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7070 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7071 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7072 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7073 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7074 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
|
7075 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7076 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7077 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7078 } |
7 | 7079 } |
4283 | 7080 if (round == 1) |
7081 { | |
7082 /* Decrement index, loop around and stop when back at | |
7083 * the start. */ | |
7084 if (--i < 0) | |
7085 i = hislen - 1; | |
7086 if (i == hisidx[type]) | |
7087 break; | |
7088 } | |
7089 else | |
7090 { | |
7091 /* Increment index. Stop at the end in the while. */ | |
7092 ++i; | |
7093 } | |
7 | 7094 } |
4283 | 7095 } |
4285 | 7096 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7097 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7098 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
|
7099 VIM_CLEAR(viminfo_history[type]); |
4311 | 7100 viminfo_hisidx[type] = 0; |
7 | 7101 } |
7102 } | |
7103 #endif /* FEAT_VIMINFO */ | |
7104 | |
7105 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7106 /* | |
7107 * Open a window on the current command line and history. Allow editing in | |
7108 * the window. Returns when the window is closed. | |
7109 * Returns: | |
7110 * CR if the command is to be executed | |
7111 * Ctrl_C if it is to be abandoned | |
7112 * K_IGNORE if editing continues | |
7113 */ | |
7114 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
|
7115 open_cmdwin(void) |
7 | 7116 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7117 bufref_T old_curbuf; |
7 | 7118 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7119 bufref_T bufref; |
7 | 7120 win_T *wp; |
7121 int i; | |
7122 linenr_T lnum; | |
7123 int histtype; | |
7124 garray_T winsizes; | |
7125 int save_restart_edit = restart_edit; | |
7126 int save_State = State; | |
7127 int save_exmode = exmode_active; | |
510 | 7128 #ifdef FEAT_RIGHTLEFT |
7129 int save_cmdmsg_rl = cmdmsg_rl; | |
7130 #endif | |
6145 | 7131 #ifdef FEAT_FOLDING |
7132 int save_KeyTyped; | |
7133 #endif | |
7 | 7134 |
7135 /* Can't do this recursively. Can't do it when typing a password. */ | |
7136 if (cmdwin_type != 0 | |
7137 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7138 || cmdline_star > 0 | |
7139 # endif | |
7140 ) | |
7141 { | |
7142 beep_flush(); | |
7143 return K_IGNORE; | |
7144 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7145 set_bufref(&old_curbuf, curbuf); |
7 | 7146 |
7147 /* Save current window sizes. */ | |
7148 win_size_save(&winsizes); | |
7149 | |
7150 /* Don't execute autocommands while creating the window. */ | |
1410 | 7151 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7152 |
15575
6effd97a0429
patch 8.1.0795: cannot build without popup menu
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
7153 #if defined(FEAT_INS_EXPAND) |
15569
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
7154 // When using completion in Insert mode with <C-R>=<C-F> one can open the |
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
7155 // command line window, but we don't want the popup menu then. |
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
7156 pum_undisplay(); |
15575
6effd97a0429
patch 8.1.0795: cannot build without popup menu
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
7157 #endif |
15569
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
7158 |
683 | 7159 /* don't use a new tab page */ |
7160 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
|
7161 cmdmod.noswapfile = 1; |
683 | 7162 |
7 | 7163 /* Create a window for the command-line buffer. */ |
7164 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7165 { | |
7166 beep_flush(); | |
1410 | 7167 unblock_autocmds(); |
7 | 7168 return K_IGNORE; |
7169 } | |
1831 | 7170 cmdwin_type = get_cmdline_type(); |
7 | 7171 |
7172 /* Create the command-line buffer empty. */ | |
1743 | 7173 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7174 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7175 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7176 curbuf->b_p_ma = TRUE; | |
1865 | 7177 #ifdef FEAT_FOLDING |
7178 curwin->w_p_fen = FALSE; | |
7179 #endif | |
7 | 7180 # ifdef FEAT_RIGHTLEFT |
510 | 7181 curwin->w_p_rl = cmdmsg_rl; |
7182 cmdmsg_rl = FALSE; | |
7 | 7183 # endif |
2583 | 7184 RESET_BINDING(curwin); |
7 | 7185 |
7186 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7187 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7188 /* 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
|
7189 ++curbuf_lock; |
7 | 7190 |
510 | 7191 /* Showing the prompt may have set need_wait_return, reset it. */ |
7192 need_wait_return = FALSE; | |
7193 | |
1831 | 7194 histtype = hist_char2type(cmdwin_type); |
7 | 7195 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7196 { | |
7197 if (p_wc == TAB) | |
7198 { | |
7199 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7200 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7201 } | |
7202 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7203 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7204 --curbuf_lock; |
7 | 7205 |
10 | 7206 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7207 * sets 'textwidth' to 78). */ | |
7208 curbuf->b_p_tw = 0; | |
7209 | |
7 | 7210 /* Fill the buffer with the history. */ |
7211 init_history(); | |
7212 if (hislen > 0) | |
7213 { | |
7214 i = hisidx[histtype]; | |
7215 if (i >= 0) | |
7216 { | |
7217 lnum = 0; | |
7218 do | |
7219 { | |
7220 if (++i == hislen) | |
7221 i = 0; | |
7222 if (history[histtype][i].hisstr != NULL) | |
7223 ml_append(lnum++, history[histtype][i].hisstr, | |
7224 (colnr_T)0, FALSE); | |
7225 } | |
7226 while (i != hisidx[histtype]); | |
7227 } | |
7228 } | |
7229 | |
7230 /* Replace the empty last line with the current command-line and put the | |
7231 * cursor there. */ | |
7232 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7233 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7234 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7235 changed_line_abv_curs(); |
7236 invalidate_botline(); | |
743 | 7237 redraw_later(SOME_VALID); |
7 | 7238 |
7239 /* No Ex mode here! */ | |
7240 exmode_active = 0; | |
7241 | |
7242 State = NORMAL; | |
7243 # ifdef FEAT_MOUSE | |
7244 setmouse(); | |
7245 # endif | |
7246 | |
7247 /* 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
|
7248 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7249 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7250 stuffcharReadbuff(K_NOP); | |
7 | 7251 |
7252 i = RedrawingDisabled; | |
7253 RedrawingDisabled = 0; | |
7254 | |
7255 /* | |
7256 * Call the main loop until <CR> or CTRL-C is typed. | |
7257 */ | |
7258 cmdwin_result = 0; | |
168 | 7259 main_loop(TRUE, FALSE); |
7 | 7260 |
7261 RedrawingDisabled = i; | |
7262 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7263 # ifdef FEAT_FOLDING |
6145 | 7264 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7265 # endif |
6145 | 7266 |
7 | 7267 /* 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
|
7268 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7269 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7270 # ifdef FEAT_FOLDING |
6145 | 7271 /* Restore KeyTyped in case it is modified by autocommands */ |
7272 KeyTyped = save_KeyTyped; | |
7 | 7273 # endif |
7274 | |
7275 cmdwin_type = 0; | |
7276 exmode_active = save_exmode; | |
7277 | |
1612 | 7278 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7279 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7280 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7281 { |
7282 cmdwin_result = Ctrl_C; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
7283 emsg(_("E199: Active window or buffer deleted")); |
7 | 7284 } |
7285 else | |
7286 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7287 # if defined(FEAT_EVAL) |
7 | 7288 /* autocmds may abort script processing */ |
7289 if (aborting() && cmdwin_result != K_IGNORE) | |
7290 cmdwin_result = Ctrl_C; | |
7291 # endif | |
7292 /* Set the new command line from the cmdline buffer. */ | |
7293 vim_free(ccline.cmdbuff); | |
510 | 7294 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7295 { |
510 | 7296 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7297 | |
7298 if (histtype == HIST_CMD) | |
7299 { | |
7300 /* Execute the command directly. */ | |
7301 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7302 cmdwin_result = CAR; | |
7303 } | |
7304 else | |
7305 { | |
7306 /* First need to cancel what we were doing. */ | |
7307 ccline.cmdbuff = NULL; | |
7308 stuffcharReadbuff(':'); | |
7309 stuffReadbuff((char_u *)p); | |
7310 stuffcharReadbuff(CAR); | |
7311 } | |
7 | 7312 } |
7313 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7314 { | |
7315 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7316 cmdwin_result = CAR; | |
7317 } | |
2839 | 7318 else if (cmdwin_result == Ctrl_C) |
7319 { | |
7320 /* :q or :close, don't execute any command | |
7321 * and don't modify the cmd window. */ | |
7322 ccline.cmdbuff = NULL; | |
7323 } | |
7 | 7324 else |
7325 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7326 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
|
7327 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7328 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
|
7329 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
|
7330 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
|
7331 ccline.cmdpos = 0; |
7 | 7332 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
|
7333 } |
7 | 7334 else |
7335 { | |
7336 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7337 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7338 ccline.cmdpos = curwin->w_cursor.col; | |
7339 if (ccline.cmdpos > ccline.cmdlen) | |
7340 ccline.cmdpos = ccline.cmdlen; | |
7341 if (cmdwin_result == K_IGNORE) | |
7342 { | |
7343 set_cmdspos_cursor(); | |
7344 redrawcmd(); | |
7345 } | |
7346 } | |
7347 | |
7348 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7349 block_autocmds(); |
6876 | 7350 # ifdef FEAT_CONCEAL |
7351 /* Avoid command-line window first character being concealed. */ | |
7352 curwin->w_p_cole = 0; | |
7353 # endif | |
7 | 7354 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7355 set_bufref(&bufref, curbuf); |
7 | 7356 win_goto(old_curwin); |
7357 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7358 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7359 /* 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
|
7360 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7361 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7362 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7363 |
7364 /* Restore window sizes. */ | |
7365 win_size_restore(&winsizes); | |
7366 | |
1410 | 7367 unblock_autocmds(); |
7 | 7368 } |
7369 | |
7370 ga_clear(&winsizes); | |
7371 restart_edit = save_restart_edit; | |
510 | 7372 # ifdef FEAT_RIGHTLEFT |
7373 cmdmsg_rl = save_cmdmsg_rl; | |
7374 # endif | |
7 | 7375 |
7376 State = save_State; | |
7377 # ifdef FEAT_MOUSE | |
7378 setmouse(); | |
7379 # endif | |
7380 | |
7381 return cmdwin_result; | |
7382 } | |
7383 #endif /* FEAT_CMDWIN */ | |
7384 | |
7385 /* | |
7386 * Used for commands that either take a simple command string argument, or: | |
7387 * cmd << endmarker | |
7388 * {script} | |
7389 * endmarker | |
7390 * Returns a pointer to allocated memory with {script} or NULL. | |
7391 */ | |
7392 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7393 script_get(exarg_T *eap, char_u *cmd) |
7 | 7394 { |
7395 char_u *theline; | |
7396 char *end_pattern = NULL; | |
7397 char dot[] = "."; | |
7398 garray_T ga; | |
7399 | |
7400 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7401 return NULL; | |
7402 | |
7403 ga_init2(&ga, 1, 0x400); | |
7404 | |
7405 if (cmd[2] != NUL) | |
7406 end_pattern = (char *)skipwhite(cmd + 2); | |
7407 else | |
7408 end_pattern = dot; | |
7409 | |
7410 for (;;) | |
7411 { | |
7412 theline = eap->getline( | |
7413 #ifdef FEAT_EVAL | |
75 | 7414 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7415 #endif |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
7416 NUL, eap->cookie, 0, TRUE); |
7 | 7417 |
7418 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7419 { |
7420 vim_free(theline); | |
7 | 7421 break; |
1694 | 7422 } |
7 | 7423 |
7424 ga_concat(&ga, theline); | |
7425 ga_append(&ga, '\n'); | |
7426 vim_free(theline); | |
7427 } | |
21 | 7428 ga_append(&ga, NUL); |
7 | 7429 |
7430 return (char_u *)ga.ga_data; | |
7431 } |