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