Mercurial > vim
annotate src/ex_getln.c @ 14544:2b2d7ae42fb8 v8.1.0285
patch 8.1.0285: compiler warning for conversion
commit https://github.com/vim/vim/commit/d7cc16357083c4fc4271e25fb36c4fbaee99e0f1
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 14 20:18:26 2018 +0200
patch 8.1.0285: compiler warning for conversion
Problem: Compiler warning for conversion.
Solution: Add a type cast. (Mike Williams)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 14 Aug 2018 20:30:06 +0200 |
parents | 116a01c73fd8 |
children | 35e7ead872db |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 /* | |
17 * Variables shared between getcmdline(), redrawcmdline() and others. | |
18 * These need to be saved when using CTRL-R |, that's why they are in a | |
19 * structure. | |
20 */ | |
21 struct cmdline_info | |
22 { | |
23 char_u *cmdbuff; /* pointer to command line buffer */ | |
24 int cmdbufflen; /* length of cmdbuff */ | |
25 int cmdlen; /* number of chars in command line */ | |
26 int cmdpos; /* current cursor position */ | |
27 int cmdspos; /* cursor column on screen */ | |
3503 | 28 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 29 int cmdindent; /* number of spaces before cmdline */ |
30 char_u *cmdprompt; /* message in front of cmdline */ | |
31 int cmdattr; /* attributes for prompt */ | |
32 int overstrike; /* Typing mode on the command line. Shared by | |
33 getcmdline() and put_on_cmdline(). */ | |
1718 | 34 expand_T *xpc; /* struct being used for expansion, xp_pattern |
35 may point into cmdbuff */ | |
531 | 36 int xp_context; /* type of expansion */ |
37 # ifdef FEAT_EVAL | |
38 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 39 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 40 # endif |
7 | 41 }; |
42 | |
1718 | 43 /* The current cmdline_info. It is initialized in getcmdline() and after that |
44 * used by other functions. When invoking getcmdline() recursively it needs | |
45 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
46 * TODO: make it local to getcmdline() and pass it around. */ | |
47 static struct cmdline_info ccline; | |
7 | 48 |
49 static int cmd_showtail; /* Only show path tail in lists ? */ | |
50 | |
51 #ifdef FEAT_EVAL | |
52 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
53 #endif | |
54 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
55 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
56 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
57 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
58 |
7 | 59 #ifdef FEAT_CMDHIST |
60 typedef struct hist_entry | |
61 { | |
62 int hisnum; /* identifying number */ | |
4258 | 63 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 64 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
65 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 66 } histentry_T; |
67 | |
68 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
69 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
70 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
71 /* identifying (unique) number of newest history entry */ | |
72 static int hislen = 0; /* actual length of history tables */ | |
73 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
74 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
75 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
76 static int in_history(int, char_u *, int, int, int); |
7 | 77 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int calc_hist_idx(int histype, int num); |
7 | 79 # endif |
80 #endif | |
81 | |
82 #ifdef FEAT_RIGHTLEFT | |
83 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
84 #endif | |
85 | |
86 #ifdef FEAT_FKMAP | |
87 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
88 #endif | |
89 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
90 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
91 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
92 static void set_cmdspos_cursor(void); |
7 | 93 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
97 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void draw_cmdline(int start, int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 static void save_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void restore_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 102 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 static void redrawcmd_preedit(void); |
7 | 104 #endif |
105 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
106 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
108 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
109 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 static int nextwild(expand_T *xp, int type, int options, int escape); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void escape_fname(char_u **pp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static int showmatches(expand_T *xp, int wildmenu); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static void set_expand_context(expand_T *xp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
116 static int expand_showtail(expand_T *xp); |
7 | 117 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
119 static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
120 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 121 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 123 # endif |
7 | 124 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
125 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 127 # endif |
128 #endif | |
4265 | 129 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 131 #endif |
7 | 132 |
133 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
134 static int open_cmdwin(void); |
7 | 135 #endif |
136 | |
3164 | 137 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
138 static int | |
139 #ifdef __BORLANDC__ | |
140 _RTLENTRYF | |
141 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
142 sort_func_compare(const void *s1, const void *s2); |
3164 | 143 #endif |
144 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
145 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
146 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
147 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
148 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
150 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
153 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
155 |
7 | 156 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
157 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
158 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
159 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
160 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
162 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
166 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
169 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
171 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
172 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
173 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
174 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
177 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
181 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
185 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
186 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
187 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
188 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
189 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
190 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
223 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
224 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
225 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
226 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 int incsearch_postponed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
238 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 is_state->incsearch_postponed = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
247 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
267 * Sets search_first_line and search_last_line to the address range. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
270 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
271 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
274 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
275 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
276 if (p_is && !cmd_silent) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
278 // by default search all lines |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
279 search_first_line = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
280 search_last_line = MAXLNUM; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
281 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
282 if (firstc == '/' || firstc == '?') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
283 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
284 if (firstc == ':') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
285 { |
14538
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
286 char_u *cmd; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
287 cmdmod_T save_cmdmod = cmdmod; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
288 char_u *p; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
289 int delim; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
290 char_u *end; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
291 char_u *dummy; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
292 exarg_T ea; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
293 |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
294 vim_memset(&ea, 0, sizeof(ea)); |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
295 ea.line1 = 1; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
296 ea.line2 = 1; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
297 ea.cmd = ccline.cmdbuff; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
298 ea.addr_type = ADDR_LINES; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
299 |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
300 parse_command_modifiers(&ea, &dummy, TRUE); |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
301 cmdmod = save_cmdmod; |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
302 |
213f1a519378
patch 8.1.0282: 'incsearch' does not work with command modifiers
Christian Brabandt <cb@256bit.org>
parents:
14534
diff
changeset
|
303 cmd = skip_range(ea.cmd, NULL); |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
304 if (*cmd == 's' || *cmd == 'g' || *cmd == 'v') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
305 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
306 // Skip over "substitute" to find the pattern separator. |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
307 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
308 ; |
14532
58cc47fae12e
patch 8.1.0279: 'incsearch' highlighting does not skip white space
Christian Brabandt <cb@256bit.org>
parents:
14530
diff
changeset
|
309 if (*skipwhite(p) != NUL |
14522
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
310 && (STRNCMP(cmd, "substitute", p - cmd) == 0 |
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
311 || STRNCMP(cmd, "global", p - cmd) == 0 |
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
312 || STRNCMP(cmd, "vglobal", p - cmd) == 0)) |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
313 { |
14534
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
314 // Check for "global!/". |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
315 if (*cmd == 'g' && *p == '!') |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
316 { |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
317 p++; |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
318 if (*skipwhite(p) == NUL) |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
319 return FALSE; |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
320 } |
14532
58cc47fae12e
patch 8.1.0279: 'incsearch' highlighting does not skip white space
Christian Brabandt <cb@256bit.org>
parents:
14530
diff
changeset
|
321 p = skipwhite(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
|
322 delim = *p++; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
323 end = skip_regexp(p, delim, p_magic, NULL); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
324 if (end > p || *end == delim) |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
325 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
326 pos_T save_cursor = curwin->w_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
327 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
328 // found a non-empty pattern |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
329 *skiplen = (int)(p - ccline.cmdbuff); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
330 *patlen = (int)(end - p); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
331 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
332 // parse the address range |
14524
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
333 curwin->w_cursor = is_state->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
|
334 parse_cmd_address(&ea, &dummy); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
335 if (ea.addr_count > 0) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
336 { |
14530
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
337 // Allow for reverse match. |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
338 if (ea.line2 < ea.line1) |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
339 { |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
340 search_first_line = ea.line2; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
341 search_last_line = ea.line1; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
342 } |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
343 else |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
344 { |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
345 search_first_line = ea.line1; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
346 search_last_line = ea.line2; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
347 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
348 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
349 else if (*cmd == 's') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
350 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
351 // :s defaults to the current line |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
352 search_first_line = curwin->w_cursor.lnum; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
353 search_last_line = curwin->w_cursor.lnum; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
354 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
355 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
356 curwin->w_cursor = save_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
357 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
358 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
359 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
360 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
361 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
362 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
363 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
364 return FALSE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
365 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
366 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
367 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
368 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
369 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
370 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
|
371 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
|
372 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
373 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
|
374 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
375 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
|
376 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
377 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
|
378 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
379 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
380 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
|
381 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
382 // 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
|
383 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
|
384 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
385 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
386 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
|
387 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
388 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
|
389 highlight_match = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
390 validate_cursor(); /* needed for TAB */ |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
391 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
|
392 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
|
393 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
394 redraw_all_later(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
395 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
396 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
397 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
398 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
399 * 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
|
400 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
401 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
402 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
|
403 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
404 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
405 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
|
406 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
407 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
|
408 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
409 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
|
410 struct cmdline_info save_ccline; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
411 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
412 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
413 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
414 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
415 int use_last_pat; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
416 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
417 if (!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
|
418 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
419 finish_incsearch_highlighting(FALSE, is_state, TRUE); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
420 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
421 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
422 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
423 // 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
|
424 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
425 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
426 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
|
427 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
428 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
429 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
|
430 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
431 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
|
432 // 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
|
433 curwin->w_cursor = is_state->search_start; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
434 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
435 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
436 // 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
|
437 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
|
438 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
|
439 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
440 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
441 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
442 // 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
|
443 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
|
444 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
|
445 && 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
|
446 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
447 // 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
|
448 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
|
449 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
450 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
451 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
|
452 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
|
453 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
454 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
456 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
|
457 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
458 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
|
459 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
460 ++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
|
461 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
462 // 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
|
463 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
|
464 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
465 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
466 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
|
467 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
|
468 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
|
469 ccline.cmdbuff[skiplen + patlen] = NUL; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
470 i = do_search(NULL, firstc == ':' ? '/' : firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
471 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
|
472 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
473 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
474 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
475 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
476 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
477 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
478 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
|
479 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
480 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
481 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
|
482 || 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
|
483 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
484 // match outside of address range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
485 i = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
486 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
|
487 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
488 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
489 // 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
|
490 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
491 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
492 (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
|
493 got_int = FALSE; // don't abandon the command line |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
494 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
495 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
496 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
|
497 // 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
|
498 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
|
499 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
500 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
501 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
|
502 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
503 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
|
504 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
505 // 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
|
506 // 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
|
507 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
|
508 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
|
509 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
510 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
511 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
512 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
513 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
|
514 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 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
|
516 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
|
517 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
518 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
|
519 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
|
520 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
|
521 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
522 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
523 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
|
524 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
525 // Disable 'hlsearch' highlighting if the pattern matches everything. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 // Avoids a flash when typing "foo\|". |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
527 if (!use_last_pat) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
528 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
529 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
|
530 ccline.cmdbuff[skiplen + patlen] = NUL; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
531 if (empty_pattern(ccline.cmdbuff)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
532 set_no_hlsearch(TRUE); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
533 ccline.cmdbuff[skiplen + patlen] = next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
534 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
535 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
536 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
537 // 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
|
538 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
|
539 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
|
540 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
541 save_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
542 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
|
543 restore_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
544 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
|
545 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
546 // Leave it at the end to make CTRL-R CTRL-W work. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
547 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 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
|
549 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
551 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
552 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
|
553 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
554 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
555 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
556 * 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
|
557 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
558 * 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
|
559 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
560 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
561 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
|
562 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
|
563 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
564 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
|
565 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
566 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
567 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
|
568 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
569 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
570 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
|
571 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
|
572 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
|
573 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
574 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
575 return OK; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
576 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
577 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
578 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
579 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
|
580 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
581 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
|
582 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
583 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
|
584 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
585 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
|
586 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
|
587 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
588 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
589 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
590 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
591 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
|
592 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
593 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
|
594 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
|
595 // 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
|
596 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
597 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
598 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
|
599 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
600 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
601 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
|
602 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
603 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
|
604 ++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
|
605 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
|
606 pat[patlen] = NUL; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
607 i = searchit(curwin, curbuf, &t, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
608 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
|
609 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
|
610 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
|
611 --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
|
612 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
|
613 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 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
|
616 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
|
617 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
|
618 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
|
619 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 // 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
|
621 // 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
|
622 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
|
623 (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
|
624 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
625 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
|
626 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
627 // 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
|
628 // 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
|
629 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
|
630 (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
|
631 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
632 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
|
633 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
634 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
635 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
|
636 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
637 (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
|
638 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
639 (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
|
640 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
641 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
642 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
|
643 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
|
644 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
|
645 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
646 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
647 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
648 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
|
649 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
|
650 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
651 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
652 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
653 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
|
654 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
|
655 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
656 } |
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 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
659 * 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
|
660 * 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
|
661 * 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
|
662 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
663 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
664 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
|
665 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
666 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
|
667 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
668 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
669 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
670 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 // 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
|
672 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
|
673 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
674 curwin->w_cursor = is_state->match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
675 if (!EQUAL_POS(curwin->w_cursor, is_state->search_start)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
676 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
677 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
678 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
679 // 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
|
680 // 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
|
681 // 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
|
682 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
|
683 *c = MB_TOLOWER(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
684 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
685 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
686 if (*c == firstc || vim_strchr((char_u *)( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
687 p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
688 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
689 // put a backslash before special characters |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
690 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
691 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
692 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
693 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
694 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
695 } |
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 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
698 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
699 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
700 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
701 /* |
7 | 702 * getcmdline() - accept a command line starting with firstc. |
703 * | |
704 * firstc == ':' get ":" command line. | |
705 * firstc == '/' or '?' get search pattern | |
706 * firstc == '=' get expression | |
707 * firstc == '@' get text for input() function | |
708 * firstc == '>' get text for debug mode | |
709 * firstc == NUL get text for :insert command | |
710 * firstc == -1 like NUL, and break on CTRL-C | |
711 * | |
712 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
713 * command line. | |
714 * | |
715 * Careful: getcmdline() can be called recursively! | |
716 * | |
717 * Return pointer to allocated string if there is a commandline, NULL | |
718 * otherwise. | |
719 */ | |
720 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
721 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
722 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
723 long count UNUSED, /* only used for incremental search */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
724 int indent) /* indent for inside conditionals */ |
7 | 725 { |
726 int c; | |
727 int i; | |
728 int j; | |
729 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
730 int do_abbr; /* when TRUE check for abbr. */ | |
731 #ifdef FEAT_CMDHIST | |
732 char_u *lookfor = NULL; /* string to match */ | |
733 int hiscnt; /* current history line in use */ | |
734 int histype; /* history type to be used */ | |
735 #endif | |
736 #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
|
737 incsearch_state_T is_state; |
7 | 738 #endif |
739 int did_wild_list = FALSE; /* did wild_list() recently */ | |
740 int wim_index = 0; /* index in wim_flags[] */ | |
741 int res; | |
742 int save_msg_scroll = msg_scroll; | |
743 int save_State = State; /* remember State when called */ | |
744 int some_key_typed = FALSE; /* one of the keys was typed */ | |
745 #ifdef FEAT_MOUSE | |
746 /* mouse drag and release events are ignored, unless they are | |
747 * preceded with a mouse down event */ | |
748 int ignore_drag_release = TRUE; | |
749 #endif | |
750 #ifdef FEAT_EVAL | |
751 int break_ctrl_c = FALSE; | |
752 #endif | |
753 expand_T xpc; | |
754 long *b_im_ptr = NULL; | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
755 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 756 /* Everything that may work recursively should save and restore the |
757 * current command line in save_ccline. That includes update_screen(), a | |
758 * custom status line may invoke ":normal". */ | |
759 struct cmdline_info save_ccline; | |
760 #endif | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
761 int cmdline_type; |
7 | 762 |
763 #ifdef FEAT_EVAL | |
764 if (firstc == -1) | |
765 { | |
766 firstc = NUL; | |
767 break_ctrl_c = TRUE; | |
768 } | |
769 #endif | |
770 #ifdef FEAT_RIGHTLEFT | |
771 /* start without Hebrew mapping for a command line */ | |
772 if (firstc == ':' || firstc == '=' || firstc == '>') | |
773 cmd_hkmap = 0; | |
774 #endif | |
775 | |
776 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
|
777 |
7 | 778 #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
|
779 init_incsearch_state(&is_state); |
7 | 780 #endif |
781 | |
782 /* | |
783 * set some variables for redrawcmd() | |
784 */ | |
785 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 786 ccline.cmdindent = (firstc > 0 ? indent : 0); |
787 | |
788 /* alloc initial ccline.cmdbuff */ | |
789 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 790 if (ccline.cmdbuff == NULL) |
791 return NULL; /* out of memory */ | |
792 ccline.cmdlen = ccline.cmdpos = 0; | |
793 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
|
794 sb_text_start_cmdline(); |
7 | 795 |
164 | 796 /* autoindent for :insert and :append */ |
797 if (firstc <= 0) | |
798 { | |
6929 | 799 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 800 ccline.cmdbuff[indent] = NUL; |
801 ccline.cmdpos = indent; | |
802 ccline.cmdspos = indent; | |
803 ccline.cmdlen = indent; | |
804 } | |
805 | |
7 | 806 ExpandInit(&xpc); |
1718 | 807 ccline.xpc = &xpc; |
7 | 808 |
809 #ifdef FEAT_RIGHTLEFT | |
810 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
811 && (firstc == '/' || firstc == '?')) | |
812 cmdmsg_rl = TRUE; | |
813 else | |
814 cmdmsg_rl = FALSE; | |
815 #endif | |
816 | |
817 redir_off = TRUE; /* don't redirect the typed command */ | |
818 if (!cmd_silent) | |
819 { | |
820 i = msg_scrolled; | |
821 msg_scrolled = 0; /* avoid wait_return message */ | |
822 gotocmdline(TRUE); | |
823 msg_scrolled += i; | |
824 redrawcmdprompt(); /* draw prompt or indent */ | |
825 set_cmdspos(); | |
826 } | |
827 xpc.xp_context = EXPAND_NOTHING; | |
828 xpc.xp_backslash = XP_BS_NONE; | |
632 | 829 #ifndef BACKSLASH_IN_FILENAME |
830 xpc.xp_shell = FALSE; | |
831 #endif | |
7 | 832 |
531 | 833 #if defined(FEAT_EVAL) |
834 if (ccline.input_fn) | |
835 { | |
836 xpc.xp_context = ccline.xp_context; | |
837 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 838 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 839 xpc.xp_arg = ccline.xp_arg; |
1322 | 840 # endif |
531 | 841 } |
842 #endif | |
843 | |
7 | 844 /* |
845 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
846 * doing ":@0" when register 0 doesn't contain a CR. | |
847 */ | |
848 msg_scroll = FALSE; | |
849 | |
850 State = CMDLINE; | |
851 | |
852 if (firstc == '/' || firstc == '?' || firstc == '@') | |
853 { | |
854 /* Use ":lmap" mappings for search pattern and input(). */ | |
855 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
856 b_im_ptr = &curbuf->b_p_iminsert; | |
857 else | |
858 b_im_ptr = &curbuf->b_p_imsearch; | |
859 if (*b_im_ptr == B_IMODE_LMAP) | |
860 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
861 #ifdef HAVE_INPUT_METHOD |
7 | 862 im_set_active(*b_im_ptr == B_IMODE_IM); |
863 #endif | |
864 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
865 #ifdef HAVE_INPUT_METHOD |
7 | 866 else if (p_imcmdline) |
867 im_set_active(TRUE); | |
868 #endif | |
869 | |
870 #ifdef FEAT_MOUSE | |
871 setmouse(); | |
872 #endif | |
873 #ifdef CURSOR_SHAPE | |
874 ui_cursor_shape(); /* may show different cursor shape */ | |
875 #endif | |
876 | |
571 | 877 /* When inside an autocommand for writing "exiting" may be set and |
878 * terminal mode set to cooked. Need to set raw mode here then. */ | |
879 settmode(TMODE_RAW); | |
880 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
881 /* 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
|
882 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
|
883 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
|
884 |
7 | 885 #ifdef FEAT_CMDHIST |
886 init_history(); | |
887 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
888 histype = hist_char2type(firstc); | |
889 #endif | |
890 | |
891 #ifdef FEAT_DIGRAPHS | |
1868 | 892 do_digraph(-1); /* init digraph typeahead */ |
7 | 893 #endif |
894 | |
5993 | 895 /* If something above caused an error, reset the flags, we do want to type |
896 * and execute commands. Display may be messed up a bit. */ | |
897 if (did_emsg) | |
898 redrawcmd(); | |
899 did_emsg = FALSE; | |
900 got_int = FALSE; | |
901 | |
7 | 902 /* |
903 * Collect the command string, handling editing keys. | |
904 */ | |
905 for (;;) | |
906 { | |
972 | 907 redir_off = TRUE; /* Don't redirect the typed command. |
908 Repeated, because a ":redir" inside | |
909 completion may switch it on. */ | |
7 | 910 #ifdef USE_ON_FLY_SCROLL |
911 dont_scroll = FALSE; /* allow scrolling here */ | |
912 #endif | |
913 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
914 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
915 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
|
916 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
|
917 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
|
918 |
7 | 919 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 920 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
921 /* 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
|
922 * anything, such as stop completion. */ |
1472 | 923 do |
924 { | |
925 c = safe_vgetc(); | |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
926 } while (c == K_IGNORE || c == K_NOP); |
1472 | 927 |
7 | 928 if (KeyTyped) |
929 { | |
930 some_key_typed = TRUE; | |
931 #ifdef FEAT_RIGHTLEFT | |
932 if (cmd_hkmap) | |
933 c = hkmap(c); | |
934 # ifdef FEAT_FKMAP | |
935 if (cmd_fkmap) | |
936 c = cmdl_fkmap(c); | |
937 # endif | |
938 if (cmdmsg_rl && !KeyStuffed) | |
939 { | |
940 /* Invert horizontal movements and operations. Only when | |
941 * typed by the user directly, not when the result of a | |
942 * mapping. */ | |
943 switch (c) | |
944 { | |
945 case K_RIGHT: c = K_LEFT; break; | |
946 case K_S_RIGHT: c = K_S_LEFT; break; | |
947 case K_C_RIGHT: c = K_C_LEFT; break; | |
948 case K_LEFT: c = K_RIGHT; break; | |
949 case K_S_LEFT: c = K_S_RIGHT; break; | |
950 case K_C_LEFT: c = K_C_RIGHT; break; | |
951 } | |
952 } | |
953 #endif | |
954 } | |
955 | |
956 /* | |
957 * Ignore got_int when CTRL-C was typed here. | |
958 * Don't ignore it in :global, we really need to break then, e.g., for | |
959 * ":g/pat/normal /pat" (without the <CR>). | |
960 * Don't ignore it for the input() function. | |
961 */ | |
962 if ((c == Ctrl_C | |
963 #ifdef UNIX | |
964 || c == intr_char | |
965 #endif | |
966 ) | |
967 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
968 && firstc != '@' | |
969 #endif | |
970 #ifdef FEAT_EVAL | |
971 && !break_ctrl_c | |
972 #endif | |
973 && !global_busy) | |
974 got_int = FALSE; | |
975 | |
976 #ifdef FEAT_CMDHIST | |
977 /* free old command line when finished moving around in the history | |
978 * list */ | |
979 if (lookfor != NULL | |
180 | 980 && c != K_S_DOWN && c != K_S_UP |
230 | 981 && c != K_DOWN && c != K_UP |
7 | 982 && c != K_PAGEDOWN && c != K_PAGEUP |
983 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 984 && c != K_LEFT && c != K_RIGHT |
7 | 985 && (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
|
986 VIM_CLEAR(lookfor); |
7 | 987 #endif |
988 | |
989 /* | |
1718 | 990 * When there are matching completions to select <S-Tab> works like |
991 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 992 */ |
1718 | 993 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 994 c = Ctrl_P; |
995 | |
996 #ifdef FEAT_WILDMENU | |
997 /* Special translations for 'wildmenu' */ | |
998 if (did_wild_list && p_wmnu) | |
999 { | |
230 | 1000 if (c == K_LEFT) |
7 | 1001 c = Ctrl_P; |
230 | 1002 else if (c == K_RIGHT) |
7 | 1003 c = Ctrl_N; |
1004 } | |
1005 /* Hitting CR after "emenu Name.": complete submenu */ | |
1006 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1007 && ccline.cmdpos > 1 | |
1008 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1009 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1010 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1011 c = K_DOWN; | |
1012 #endif | |
1013 | |
1014 /* free expanded names when finished walking through matches */ | |
1015 if (xpc.xp_numfiles != -1 | |
1016 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1017 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1018 && c != Ctrl_L) | |
1019 { | |
1020 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1021 did_wild_list = FALSE; | |
1022 #ifdef FEAT_WILDMENU | |
230 | 1023 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1024 #endif |
1025 xpc.xp_context = EXPAND_NOTHING; | |
1026 wim_index = 0; | |
1027 #ifdef FEAT_WILDMENU | |
1028 if (p_wmnu && wild_menu_showing != 0) | |
1029 { | |
1030 int skt = KeyTyped; | |
532 | 1031 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1032 |
1033 if (ccline.input_fn) | |
1034 RedrawingDisabled = 0; | |
7 | 1035 |
1036 if (wild_menu_showing == WM_SCROLLED) | |
1037 { | |
1038 /* Entered command line, move it up */ | |
1039 cmdline_row--; | |
1040 redrawcmd(); | |
1041 } | |
1042 else if (save_p_ls != -1) | |
1043 { | |
1044 /* restore 'laststatus' and 'winminheight' */ | |
1045 p_ls = save_p_ls; | |
1046 p_wmh = save_p_wmh; | |
1047 last_status(FALSE); | |
195 | 1048 save_cmdline(&save_ccline); |
7 | 1049 update_screen(VALID); /* redraw the screen NOW */ |
195 | 1050 restore_cmdline(&save_ccline); |
7 | 1051 redrawcmd(); |
1052 save_p_ls = -1; | |
1053 } | |
1054 else | |
1055 { | |
1056 win_redraw_last_status(topframe); | |
1057 redraw_statuslines(); | |
1058 } | |
532 | 1059 KeyTyped = skt; |
1060 wild_menu_showing = 0; | |
531 | 1061 if (ccline.input_fn) |
1062 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1063 } |
1064 #endif | |
1065 } | |
1066 | |
1067 #ifdef FEAT_WILDMENU | |
1068 /* Special translations for 'wildmenu' */ | |
1069 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1070 { | |
1071 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1072 if (c == K_DOWN && ccline.cmdpos > 0 |
1073 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1074 c = p_wc; |
230 | 1075 else if (c == K_UP) |
7 | 1076 { |
1077 /* Hitting <Up>: Remove one submenu name in front of the | |
1078 * cursor */ | |
1079 int found = FALSE; | |
1080 | |
1081 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1082 i = 0; | |
1083 while (--j > 0) | |
1084 { | |
1085 /* check for start of menu name */ | |
1086 if (ccline.cmdbuff[j] == ' ' | |
1087 && ccline.cmdbuff[j - 1] != '\\') | |
1088 { | |
1089 i = j + 1; | |
1090 break; | |
1091 } | |
1092 /* check for start of submenu name */ | |
1093 if (ccline.cmdbuff[j] == '.' | |
1094 && ccline.cmdbuff[j - 1] != '\\') | |
1095 { | |
1096 if (found) | |
1097 { | |
1098 i = j + 1; | |
1099 break; | |
1100 } | |
1101 else | |
1102 found = TRUE; | |
1103 } | |
1104 } | |
1105 if (i > 0) | |
1106 cmdline_del(i); | |
1107 c = p_wc; | |
1108 xpc.xp_context = EXPAND_NOTHING; | |
1109 } | |
1110 } | |
714 | 1111 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1112 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1113 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1114 { |
1115 char_u upseg[5]; | |
1116 | |
1117 upseg[0] = PATHSEP; | |
1118 upseg[1] = '.'; | |
1119 upseg[2] = '.'; | |
1120 upseg[3] = PATHSEP; | |
1121 upseg[4] = NUL; | |
1122 | |
1318 | 1123 if (c == K_DOWN |
1124 && ccline.cmdpos > 0 | |
1125 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1126 && (ccline.cmdpos < 3 | |
1127 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1128 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1129 { | |
1130 /* go down a directory */ | |
1131 c = p_wc; | |
1132 } | |
230 | 1133 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1134 { |
1135 /* If in a direct ancestor, strip off one ../ to go down */ | |
1136 int found = FALSE; | |
1137 | |
1138 j = ccline.cmdpos; | |
1139 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1140 while (--j > i) | |
1141 { | |
39 | 1142 #ifdef FEAT_MBYTE |
1143 if (has_mbyte) | |
1144 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1145 #endif | |
7 | 1146 if (vim_ispathsep(ccline.cmdbuff[j])) |
1147 { | |
1148 found = TRUE; | |
1149 break; | |
1150 } | |
1151 } | |
1152 if (found | |
1153 && ccline.cmdbuff[j - 1] == '.' | |
1154 && ccline.cmdbuff[j - 2] == '.' | |
1155 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1156 { | |
1157 cmdline_del(j - 2); | |
1158 c = p_wc; | |
1159 } | |
1160 } | |
230 | 1161 else if (c == K_UP) |
7 | 1162 { |
1163 /* go up a directory */ | |
1164 int found = FALSE; | |
1165 | |
1166 j = ccline.cmdpos - 1; | |
1167 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1168 while (--j > i) | |
1169 { | |
1170 #ifdef FEAT_MBYTE | |
1171 if (has_mbyte) | |
1172 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1173 #endif | |
1174 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1175 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1176 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1177 ccline.cmdbuff[j + 1]) == NULL |
7 | 1178 #endif |
1179 ) | |
1180 { | |
1181 if (found) | |
1182 { | |
1183 i = j + 1; | |
1184 break; | |
1185 } | |
1186 else | |
1187 found = TRUE; | |
1188 } | |
1189 } | |
1190 | |
1191 if (!found) | |
1192 j = i; | |
1193 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1194 j += 4; | |
1195 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1196 && j == i) | |
1197 j += 3; | |
1198 else | |
1199 j = 0; | |
1200 if (j > 0) | |
1201 { | |
1202 /* TODO this is only for DOS/UNIX systems - need to put in | |
1203 * machine-specific stuff here and in upseg init */ | |
1204 cmdline_del(j); | |
1205 put_on_cmdline(upseg + 1, 3, FALSE); | |
1206 } | |
1207 else if (ccline.cmdpos > i) | |
1208 cmdline_del(i); | |
3204 | 1209 |
1210 /* Now complete in the new directory. Set KeyTyped in case the | |
1211 * Up key came from a mapping. */ | |
7 | 1212 c = p_wc; |
3204 | 1213 KeyTyped = TRUE; |
7 | 1214 } |
1215 } | |
1216 | |
1217 #endif /* FEAT_WILDMENU */ | |
1218 | |
1219 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1220 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1221 if (c == Ctrl_BSL) | |
1222 { | |
1223 ++no_mapping; | |
1224 ++allow_keys; | |
1389 | 1225 c = plain_vgetc(); |
7 | 1226 --no_mapping; |
1227 --allow_keys; | |
3859 | 1228 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1229 * is in a mapping. */ | |
1230 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1231 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1232 { |
1233 vungetc(c); | |
1234 c = Ctrl_BSL; | |
1235 } | |
1236 #ifdef FEAT_EVAL | |
1237 else if (c == 'e') | |
1238 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1239 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1240 int len; |
7 | 1241 |
1242 /* | |
1243 * Replace the command line with the result of an expression. | |
625 | 1244 * Need to save and restore the current command line, to be |
1245 * able to enter a new one... | |
7 | 1246 */ |
1247 if (ccline.cmdpos == ccline.cmdlen) | |
1248 new_cmdpos = 99999; /* keep it at the end */ | |
1249 else | |
1250 new_cmdpos = ccline.cmdpos; | |
95 | 1251 |
1252 save_cmdline(&save_ccline); | |
7 | 1253 c = get_expr_register(); |
95 | 1254 restore_cmdline(&save_ccline); |
7 | 1255 if (c == '=') |
1256 { | |
634 | 1257 /* Need to save and restore ccline. And set "textlock" |
632 | 1258 * to avoid nasty things like going to another buffer when |
1259 * evaluating an expression. */ | |
95 | 1260 save_cmdline(&save_ccline); |
634 | 1261 ++textlock; |
7 | 1262 p = get_expr_line(); |
634 | 1263 --textlock; |
95 | 1264 restore_cmdline(&save_ccline); |
2617 | 1265 |
1266 if (p != NULL) | |
7 | 1267 { |
2617 | 1268 len = (int)STRLEN(p); |
1269 if (realloc_cmdbuff(len + 1) == OK) | |
1270 { | |
1271 ccline.cmdlen = len; | |
1272 STRCPY(ccline.cmdbuff, p); | |
1273 vim_free(p); | |
1274 | |
1275 /* Restore the cursor or use the position set with | |
1276 * set_cmdline_pos(). */ | |
1277 if (new_cmdpos > ccline.cmdlen) | |
1278 ccline.cmdpos = ccline.cmdlen; | |
1279 else | |
1280 ccline.cmdpos = new_cmdpos; | |
1281 | |
1282 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1283 redrawcmd(); | |
1284 goto cmdline_changed; | |
1285 } | |
7 | 1286 } |
1287 } | |
1288 beep_flush(); | |
2636 | 1289 got_int = FALSE; /* don't abandon the command line */ |
1290 did_emsg = FALSE; | |
1291 emsg_on_display = FALSE; | |
1292 redrawcmd(); | |
1293 goto cmdline_not_changed; | |
7 | 1294 } |
1295 #endif | |
1296 else | |
1297 { | |
1298 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1299 restart_edit = 'a'; | |
1300 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1301 in history */ | |
1302 goto returncmd; /* back to Normal mode */ | |
1303 } | |
1304 } | |
1305 | |
1306 #ifdef FEAT_CMDWIN | |
1307 if (c == cedit_key || c == K_CMDWIN) | |
1308 { | |
6211 | 1309 if (ex_normal_busy == 0 && got_int == FALSE) |
1310 { | |
1311 /* | |
1312 * Open a window to edit the command line (and history). | |
1313 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1314 c = open_cmdwin(); |
6211 | 1315 some_key_typed = TRUE; |
1316 } | |
7 | 1317 } |
1318 # ifdef FEAT_DIGRAPHS | |
1319 else | |
1320 # endif | |
1321 #endif | |
1322 #ifdef FEAT_DIGRAPHS | |
1323 c = do_digraph(c); | |
1324 #endif | |
1325 | |
1326 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1327 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1328 { | |
168 | 1329 /* In Ex mode a backslash escapes a newline. */ |
1330 if (exmode_active | |
1331 && c != ESC | |
1318 | 1332 && ccline.cmdpos == ccline.cmdlen |
168 | 1333 && ccline.cmdpos > 0 |
1334 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1335 { | |
1336 if (c == K_KENTER) | |
1337 c = '\n'; | |
1338 } | |
1339 else | |
7 | 1340 { |
168 | 1341 gotesc = FALSE; /* Might have typed ESC previously, don't |
1342 truncate the cmdline now. */ | |
1343 if (ccheck_abbr(c + ABBR_OFF)) | |
1344 goto cmdline_changed; | |
1345 if (!cmd_silent) | |
1346 { | |
1347 windgoto(msg_row, 0); | |
1348 out_flush(); | |
1349 } | |
1350 break; | |
7 | 1351 } |
1352 } | |
1353 | |
1354 /* | |
1355 * Completion for 'wildchar' or 'wildcharm' key. | |
1356 * - hitting <ESC> twice means: abandon command line. | |
1357 * - wildcard expansion is only done when the 'wildchar' key is really | |
1358 * typed, not when it comes from a macro | |
1359 */ | |
1360 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1361 { | |
1362 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1363 { | |
1364 /* if 'wildmode' contains "list" may still need to list */ | |
1365 if (xpc.xp_numfiles > 1 | |
1366 && !did_wild_list | |
1367 && (wim_flags[wim_index] & WIM_LIST)) | |
1368 { | |
1369 (void)showmatches(&xpc, FALSE); | |
1370 redrawcmd(); | |
1371 did_wild_list = TRUE; | |
1372 } | |
1373 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1374 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1375 firstc != '@'); | |
7 | 1376 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1377 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1378 firstc != '@'); | |
7 | 1379 else |
1380 res = OK; /* don't insert 'wildchar' now */ | |
1381 } | |
1382 else /* typed p_wc first time */ | |
1383 { | |
1384 wim_index = 0; | |
1385 j = ccline.cmdpos; | |
1386 /* if 'wildmode' first contains "longest", get longest | |
1387 * common part */ | |
1388 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1389 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1390 firstc != '@'); | |
7 | 1391 else |
3961 | 1392 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1393 firstc != '@'); | |
7 | 1394 |
1395 /* if interrupted while completing, behave like it failed */ | |
1396 if (got_int) | |
1397 { | |
1398 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1399 got_int = FALSE; /* don't abandon the command line */ | |
1400 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1401 #ifdef FEAT_WILDMENU | |
1402 xpc.xp_context = EXPAND_NOTHING; | |
1403 #endif | |
1404 goto cmdline_changed; | |
1405 } | |
1406 | |
1407 /* when more than one match, and 'wildmode' first contains | |
1408 * "list", or no change and 'wildmode' contains "longest,list", | |
1409 * list all matches */ | |
1410 if (res == OK && xpc.xp_numfiles > 1) | |
1411 { | |
1412 /* a "longest" that didn't do anything is skipped (but not | |
1413 * "list:longest") */ | |
1414 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1415 wim_index = 1; | |
1416 if ((wim_flags[wim_index] & WIM_LIST) | |
1417 #ifdef FEAT_WILDMENU | |
1418 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1419 #endif | |
1420 ) | |
1421 { | |
1422 if (!(wim_flags[0] & WIM_LONGEST)) | |
1423 { | |
1424 #ifdef FEAT_WILDMENU | |
1425 int p_wmnu_save = p_wmnu; | |
1426 p_wmnu = 0; | |
1427 #endif | |
3961 | 1428 /* remove match */ |
1429 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1430 #ifdef FEAT_WILDMENU |
1431 p_wmnu = p_wmnu_save; | |
1432 #endif | |
1433 } | |
1434 #ifdef FEAT_WILDMENU | |
1435 (void)showmatches(&xpc, p_wmnu | |
1436 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1437 #else | |
1438 (void)showmatches(&xpc, FALSE); | |
1439 #endif | |
1440 redrawcmd(); | |
1441 did_wild_list = TRUE; | |
1442 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1443 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1444 firstc != '@'); | |
7 | 1445 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1446 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1447 firstc != '@'); | |
7 | 1448 } |
1449 else | |
6949 | 1450 vim_beep(BO_WILD); |
7 | 1451 } |
1452 #ifdef FEAT_WILDMENU | |
1453 else if (xpc.xp_numfiles == -1) | |
1454 xpc.xp_context = EXPAND_NOTHING; | |
1455 #endif | |
1456 } | |
1457 if (wim_index < 3) | |
1458 ++wim_index; | |
1459 if (c == ESC) | |
1460 gotesc = TRUE; | |
1461 if (res == OK) | |
1462 goto cmdline_changed; | |
1463 } | |
1464 | |
1465 gotesc = FALSE; | |
1466 | |
1467 /* <S-Tab> goes to last match, in a clumsy way */ | |
1468 if (c == K_S_TAB && KeyTyped) | |
1469 { | |
3961 | 1470 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1471 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1472 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1473 goto cmdline_changed; |
1474 } | |
1475 | |
1476 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1477 c = NL; | |
1478 | |
1479 do_abbr = TRUE; /* default: check for abbreviation */ | |
1480 | |
1481 /* | |
1482 * Big switch for a typed command line character. | |
1483 */ | |
1484 switch (c) | |
1485 { | |
1486 case K_BS: | |
1487 case Ctrl_H: | |
1488 case K_DEL: | |
1489 case K_KDEL: | |
1490 case Ctrl_W: | |
1491 #ifdef FEAT_FKMAP | |
1492 if (cmd_fkmap && c == K_BS) | |
1493 c = K_DEL; | |
1494 #endif | |
1495 if (c == K_KDEL) | |
1496 c = K_DEL; | |
1497 | |
1498 /* | |
1499 * delete current character is the same as backspace on next | |
1500 * character, except at end of line | |
1501 */ | |
1502 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1503 ++ccline.cmdpos; | |
1504 #ifdef FEAT_MBYTE | |
1505 if (has_mbyte && c == K_DEL) | |
1506 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1507 ccline.cmdbuff + ccline.cmdpos); | |
1508 #endif | |
1509 if (ccline.cmdpos > 0) | |
1510 { | |
1511 char_u *p; | |
1512 | |
1513 j = ccline.cmdpos; | |
1514 p = ccline.cmdbuff + j; | |
1515 #ifdef FEAT_MBYTE | |
1516 if (has_mbyte) | |
1517 { | |
1518 p = mb_prevptr(ccline.cmdbuff, p); | |
1519 if (c == Ctrl_W) | |
1520 { | |
1521 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1522 p = mb_prevptr(ccline.cmdbuff, p); | |
1523 i = mb_get_class(p); | |
1524 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1525 p = mb_prevptr(ccline.cmdbuff, p); | |
1526 if (mb_get_class(p) != i) | |
474 | 1527 p += (*mb_ptr2len)(p); |
7 | 1528 } |
1529 } | |
1530 else | |
1531 #endif | |
1532 if (c == Ctrl_W) | |
1533 { | |
1534 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1535 --p; | |
1536 i = vim_iswordc(p[-1]); | |
1537 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1538 && vim_iswordc(p[-1]) == i) | |
1539 --p; | |
1540 } | |
1541 else | |
1542 --p; | |
1543 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1544 ccline.cmdlen -= j - ccline.cmdpos; | |
1545 i = ccline.cmdpos; | |
1546 while (i < ccline.cmdlen) | |
1547 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1548 | |
1549 /* Truncate at the end, required for multi-byte chars. */ | |
1550 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1551 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1552 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1553 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1554 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
|
1555 /* 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
|
1556 * 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
|
1557 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
|
1558 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1559 #endif |
7 | 1560 redrawcmd(); |
1561 } | |
1562 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1563 && ccline.cmdprompt == NULL && indent == 0) | |
1564 { | |
1565 /* In ex and debug mode it doesn't make sense to return. */ | |
1566 if (exmode_active | |
1567 #ifdef FEAT_EVAL | |
1568 || ccline.cmdfirstc == '>' | |
1569 #endif | |
1570 ) | |
1571 goto cmdline_not_changed; | |
1572 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1573 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1574 if (!cmd_silent) |
1575 { | |
1576 #ifdef FEAT_RIGHTLEFT | |
1577 if (cmdmsg_rl) | |
1578 msg_col = Columns; | |
1579 else | |
1580 #endif | |
1581 msg_col = 0; | |
1582 msg_putchar(' '); /* delete ':' */ | |
1583 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1584 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1585 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
|
1586 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
|
1587 #endif |
7 | 1588 redraw_cmdline = TRUE; |
1589 goto returncmd; /* back to cmd mode */ | |
1590 } | |
1591 goto cmdline_changed; | |
1592 | |
1593 case K_INS: | |
1594 case K_KINS: | |
1595 #ifdef FEAT_FKMAP | |
1596 /* if Farsi mode set, we are in reverse insert mode - | |
1597 Do not change the mode */ | |
1598 if (cmd_fkmap) | |
1599 beep_flush(); | |
1600 else | |
1601 #endif | |
1602 ccline.overstrike = !ccline.overstrike; | |
1603 #ifdef CURSOR_SHAPE | |
1604 ui_cursor_shape(); /* may show different cursor shape */ | |
1605 #endif | |
1606 goto cmdline_not_changed; | |
1607 | |
1608 case Ctrl_HAT: | |
782 | 1609 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1610 { |
1611 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1612 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1613 #ifdef HAVE_INPUT_METHOD |
7 | 1614 im_set_active(FALSE); /* Disable input method */ |
1615 #endif | |
1616 if (b_im_ptr != NULL) | |
1617 { | |
1618 if (State & LANGMAP) | |
1619 *b_im_ptr = B_IMODE_LMAP; | |
1620 else | |
1621 *b_im_ptr = B_IMODE_NONE; | |
1622 } | |
1623 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1624 #ifdef HAVE_INPUT_METHOD |
7 | 1625 else |
1626 { | |
1627 /* There are no ":lmap" mappings, toggle IM. When | |
1628 * 'imdisable' is set don't try getting the status, it's | |
1629 * always off. */ | |
1630 if ((p_imdisable && b_im_ptr != NULL) | |
1631 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1632 { | |
1633 im_set_active(FALSE); /* Disable input method */ | |
1634 if (b_im_ptr != NULL) | |
1635 *b_im_ptr = B_IMODE_NONE; | |
1636 } | |
1637 else | |
1638 { | |
1639 im_set_active(TRUE); /* Enable input method */ | |
1640 if (b_im_ptr != NULL) | |
1641 *b_im_ptr = B_IMODE_IM; | |
1642 } | |
1643 } | |
1644 #endif | |
1645 if (b_im_ptr != NULL) | |
1646 { | |
1647 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1648 set_iminsert_global(); | |
1649 else | |
1650 set_imsearch_global(); | |
1651 } | |
1652 #ifdef CURSOR_SHAPE | |
1653 ui_cursor_shape(); /* may show different cursor shape */ | |
1654 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1655 #if defined(FEAT_KEYMAP) |
7 | 1656 /* Show/unshow value of 'keymap' in status lines later. */ |
1657 status_redraw_curbuf(); | |
1658 #endif | |
1659 goto cmdline_not_changed; | |
1660 | |
1661 /* case '@': only in very old vi */ | |
1662 case Ctrl_U: | |
1663 /* delete all characters left of the cursor */ | |
1664 j = ccline.cmdpos; | |
1665 ccline.cmdlen -= j; | |
1666 i = ccline.cmdpos = 0; | |
1667 while (i < ccline.cmdlen) | |
1668 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1669 /* Truncate at the end, required for multi-byte chars. */ | |
1670 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1671 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1672 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
|
1673 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
|
1674 #endif |
7 | 1675 redrawcmd(); |
1676 goto cmdline_changed; | |
1677 | |
1678 #ifdef FEAT_CLIPBOARD | |
1679 case Ctrl_Y: | |
1680 /* Copy the modeless selection, if there is one. */ | |
1681 if (clip_star.state != SELECT_CLEARED) | |
1682 { | |
1683 if (clip_star.state == SELECT_DONE) | |
1684 clip_copy_modeless_selection(TRUE); | |
1685 goto cmdline_not_changed; | |
1686 } | |
1687 break; | |
1688 #endif | |
1689 | |
1690 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1691 case Ctrl_C: | |
571 | 1692 /* In exmode it doesn't make sense to return. Except when |
161 | 1693 * ":normal" runs out of characters. */ |
1694 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1695 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1696 goto cmdline_not_changed; |
1697 | |
1698 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1699 putting it in history */ | |
1700 goto returncmd; /* back to cmd mode */ | |
1701 | |
1702 case Ctrl_R: /* insert register */ | |
1703 #ifdef USE_ON_FLY_SCROLL | |
1704 dont_scroll = TRUE; /* disallow scrolling here */ | |
1705 #endif | |
1706 putcmdline('"', TRUE); | |
1707 ++no_mapping; | |
1389 | 1708 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1709 if (i == Ctrl_O) |
1710 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1711 if (i == Ctrl_R) | |
1389 | 1712 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
|
1713 extra_char = NUL; |
7 | 1714 --no_mapping; |
1715 #ifdef FEAT_EVAL | |
1716 /* | |
1717 * Insert the result of an expression. | |
1718 * Need to save the current command line, to be able to enter | |
1719 * a new one... | |
1720 */ | |
1721 new_cmdpos = -1; | |
1722 if (c == '=') | |
1723 { | |
1724 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1725 { | |
1726 beep_flush(); | |
1727 c = ESC; | |
1728 } | |
1729 else | |
1730 { | |
95 | 1731 save_cmdline(&save_ccline); |
7 | 1732 c = get_expr_register(); |
95 | 1733 restore_cmdline(&save_ccline); |
7 | 1734 } |
1735 } | |
1736 #endif | |
1737 if (c != ESC) /* use ESC to cancel inserting register */ | |
1738 { | |
1015 | 1739 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1740 |
613 | 1741 #ifdef FEAT_EVAL |
606 | 1742 /* When there was a serious error abort getting the |
1743 * command line. */ | |
1744 if (aborting()) | |
1745 { | |
1746 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1747 putting it in history */ | |
1748 goto returncmd; /* back to cmd mode */ | |
1749 } | |
613 | 1750 #endif |
7 | 1751 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1752 #ifdef FEAT_EVAL | |
1753 if (new_cmdpos >= 0) | |
1754 { | |
1755 /* set_cmdline_pos() was used */ | |
1756 if (new_cmdpos > ccline.cmdlen) | |
1757 ccline.cmdpos = ccline.cmdlen; | |
1758 else | |
1759 ccline.cmdpos = new_cmdpos; | |
1760 } | |
1761 #endif | |
1762 } | |
1763 redrawcmd(); | |
1764 goto cmdline_changed; | |
1765 | |
1766 case Ctrl_D: | |
1767 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1768 break; /* Use ^D as normal char instead */ | |
1769 | |
1770 redrawcmd(); | |
1771 continue; /* don't do incremental search now */ | |
1772 | |
1773 case K_RIGHT: | |
1774 case K_S_RIGHT: | |
1775 case K_C_RIGHT: | |
1776 do | |
1777 { | |
1778 if (ccline.cmdpos >= ccline.cmdlen) | |
1779 break; | |
1780 i = cmdline_charsize(ccline.cmdpos); | |
1781 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1782 break; | |
1783 ccline.cmdspos += i; | |
1784 #ifdef FEAT_MBYTE | |
1785 if (has_mbyte) | |
474 | 1786 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1787 + ccline.cmdpos); |
1788 else | |
1789 #endif | |
1790 ++ccline.cmdpos; | |
1791 } | |
180 | 1792 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1793 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1794 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1795 #ifdef FEAT_MBYTE | |
1796 if (has_mbyte) | |
1797 set_cmdspos_cursor(); | |
1798 #endif | |
1799 goto cmdline_not_changed; | |
1800 | |
1801 case K_LEFT: | |
1802 case K_S_LEFT: | |
1803 case K_C_LEFT: | |
1456 | 1804 if (ccline.cmdpos == 0) |
1805 goto cmdline_not_changed; | |
7 | 1806 do |
1807 { | |
1808 --ccline.cmdpos; | |
1809 #ifdef FEAT_MBYTE | |
1810 if (has_mbyte) /* move to first byte of char */ | |
1811 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1812 ccline.cmdbuff + ccline.cmdpos); | |
1813 #endif | |
1814 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1815 } | |
1456 | 1816 while (ccline.cmdpos > 0 |
1817 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1818 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1819 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1820 #ifdef FEAT_MBYTE | |
1821 if (has_mbyte) | |
1822 set_cmdspos_cursor(); | |
1823 #endif | |
1824 goto cmdline_not_changed; | |
1825 | |
1826 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
|
1827 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1828 goto cmdline_not_changed; |
7 | 1829 |
625 | 1830 #ifdef FEAT_GUI_W32 |
1831 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1832 * cancelled. */ | |
1833 case K_F4: | |
1834 if (mod_mask == MOD_MASK_ALT) | |
1835 { | |
1836 redrawcmd(); /* somehow the cmdline is cleared */ | |
1837 goto cmdline_not_changed; | |
1838 } | |
1839 break; | |
1840 #endif | |
1841 | |
7 | 1842 #ifdef FEAT_MOUSE |
1843 case K_MIDDLEDRAG: | |
1844 case K_MIDDLERELEASE: | |
1845 goto cmdline_not_changed; /* Ignore mouse */ | |
1846 | |
1847 case K_MIDDLEMOUSE: | |
1848 # ifdef FEAT_GUI | |
1849 /* When GUI is active, also paste when 'mouse' is empty */ | |
1850 if (!gui.in_use) | |
1851 # endif | |
1852 if (!mouse_has(MOUSE_COMMAND)) | |
1853 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1854 # ifdef FEAT_CLIPBOARD |
7 | 1855 if (clip_star.available) |
1015 | 1856 cmdline_paste('*', TRUE, TRUE); |
7 | 1857 else |
692 | 1858 # endif |
1015 | 1859 cmdline_paste(0, TRUE, TRUE); |
7 | 1860 redrawcmd(); |
1861 goto cmdline_changed; | |
1862 | |
692 | 1863 # ifdef FEAT_DND |
7 | 1864 case K_DROP: |
1015 | 1865 cmdline_paste('~', TRUE, FALSE); |
7 | 1866 redrawcmd(); |
1867 goto cmdline_changed; | |
692 | 1868 # endif |
7 | 1869 |
1870 case K_LEFTDRAG: | |
1871 case K_LEFTRELEASE: | |
1872 case K_RIGHTDRAG: | |
1873 case K_RIGHTRELEASE: | |
1874 /* Ignore drag and release events when the button-down wasn't | |
1875 * seen before. */ | |
1876 if (ignore_drag_release) | |
1877 goto cmdline_not_changed; | |
1878 /* FALLTHROUGH */ | |
1879 case K_LEFTMOUSE: | |
1880 case K_RIGHTMOUSE: | |
1881 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1882 ignore_drag_release = TRUE; | |
1883 else | |
1884 ignore_drag_release = FALSE; | |
1885 # ifdef FEAT_GUI | |
1886 /* When GUI is active, also move when 'mouse' is empty */ | |
1887 if (!gui.in_use) | |
1888 # endif | |
1889 if (!mouse_has(MOUSE_COMMAND)) | |
1890 goto cmdline_not_changed; /* Ignore mouse */ | |
1891 # ifdef FEAT_CLIPBOARD | |
1892 if (mouse_row < cmdline_row && clip_star.available) | |
1893 { | |
1894 int button, is_click, is_drag; | |
1895 | |
1896 /* | |
1897 * Handle modeless selection. | |
1898 */ | |
1899 button = get_mouse_button(KEY2TERMCAP1(c), | |
1900 &is_click, &is_drag); | |
1901 if (mouse_model_popup() && button == MOUSE_LEFT | |
1902 && (mod_mask & MOD_MASK_SHIFT)) | |
1903 { | |
1904 /* Translate shift-left to right button. */ | |
1905 button = MOUSE_RIGHT; | |
1906 mod_mask &= ~MOD_MASK_SHIFT; | |
1907 } | |
1908 clip_modeless(button, is_click, is_drag); | |
1909 goto cmdline_not_changed; | |
1910 } | |
1911 # endif | |
1912 | |
1913 set_cmdspos(); | |
1914 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1915 ++ccline.cmdpos) | |
1916 { | |
1917 i = cmdline_charsize(ccline.cmdpos); | |
1918 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1919 && mouse_col < ccline.cmdspos % Columns + i) | |
1920 break; | |
692 | 1921 # ifdef FEAT_MBYTE |
7 | 1922 if (has_mbyte) |
1923 { | |
1924 /* Count ">" for double-wide char that doesn't fit. */ | |
1925 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1926 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1927 + ccline.cmdpos) - 1; |
1928 } | |
692 | 1929 # endif |
7 | 1930 ccline.cmdspos += i; |
1931 } | |
1932 goto cmdline_not_changed; | |
1933 | |
1934 /* Mouse scroll wheel: ignored here */ | |
1935 case K_MOUSEDOWN: | |
1936 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1937 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1938 case K_MOUSERIGHT: |
7 | 1939 /* Alternate buttons ignored here */ |
1940 case K_X1MOUSE: | |
1941 case K_X1DRAG: | |
1942 case K_X1RELEASE: | |
1943 case K_X2MOUSE: | |
1944 case K_X2DRAG: | |
1945 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1946 case K_MOUSEMOVE: |
7 | 1947 goto cmdline_not_changed; |
1948 | |
1949 #endif /* FEAT_MOUSE */ | |
1950 | |
1951 #ifdef FEAT_GUI | |
1952 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
1953 case K_LEFTRELEASE_NM: | |
1954 goto cmdline_not_changed; | |
1955 | |
1956 case K_VER_SCROLLBAR: | |
540 | 1957 if (msg_scrolled == 0) |
7 | 1958 { |
1959 gui_do_scroll(); | |
1960 redrawcmd(); | |
1961 } | |
1962 goto cmdline_not_changed; | |
1963 | |
1964 case K_HOR_SCROLLBAR: | |
540 | 1965 if (msg_scrolled == 0) |
7 | 1966 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1967 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 1968 redrawcmd(); |
1969 } | |
1970 goto cmdline_not_changed; | |
1971 #endif | |
692 | 1972 #ifdef FEAT_GUI_TABLINE |
1973 case K_TABLINE: | |
1974 case K_TABMENU: | |
1975 /* Don't want to change any tabs here. Make sure the same tab | |
1976 * is still selected. */ | |
1977 if (gui_use_tabline()) | |
1978 gui_mch_set_curtab(tabpage_index(curtab)); | |
1979 goto cmdline_not_changed; | |
1980 #endif | |
1981 | |
7 | 1982 case K_SELECT: /* end of Select mode mapping - ignore */ |
1983 goto cmdline_not_changed; | |
1984 | |
1985 case Ctrl_B: /* begin of command line */ | |
1986 case K_HOME: | |
1987 case K_KHOME: | |
1988 case K_S_HOME: | |
1989 case K_C_HOME: | |
1990 ccline.cmdpos = 0; | |
1991 set_cmdspos(); | |
1992 goto cmdline_not_changed; | |
1993 | |
1994 case Ctrl_E: /* end of command line */ | |
1995 case K_END: | |
1996 case K_KEND: | |
1997 case K_S_END: | |
1998 case K_C_END: | |
1999 ccline.cmdpos = ccline.cmdlen; | |
2000 set_cmdspos_cursor(); | |
2001 goto cmdline_not_changed; | |
2002 | |
2003 case Ctrl_A: /* all matches */ | |
3961 | 2004 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2005 break; |
2006 goto cmdline_changed; | |
2007 | |
772 | 2008 case Ctrl_L: |
2009 #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
|
2010 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2011 goto cmdline_not_changed; |
2012 #endif | |
2013 | |
2014 /* completion: longest common part */ | |
3961 | 2015 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2016 break; |
2017 goto cmdline_changed; | |
2018 | |
2019 case Ctrl_N: /* next match */ | |
2020 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2021 if (xpc.xp_numfiles > 0) |
7 | 2022 { |
3961 | 2023 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2024 0, firstc != '@') == FAIL) | |
7 | 2025 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2026 goto cmdline_not_changed; |
7 | 2027 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2028 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2029 /* FALLTHROUGH */ |
7 | 2030 case K_UP: |
2031 case K_DOWN: | |
2032 case K_S_UP: | |
2033 case K_S_DOWN: | |
2034 case K_PAGEUP: | |
2035 case K_KPAGEUP: | |
2036 case K_PAGEDOWN: | |
2037 case K_KPAGEDOWN: | |
2038 if (hislen == 0 || firstc == NUL) /* no history */ | |
2039 goto cmdline_not_changed; | |
2040 | |
2041 i = hiscnt; | |
2042 | |
2043 /* save current command string so it can be restored later */ | |
2044 if (lookfor == NULL) | |
2045 { | |
2046 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2047 goto cmdline_not_changed; | |
2048 lookfor[ccline.cmdpos] = NUL; | |
2049 } | |
2050 | |
2051 j = (int)STRLEN(lookfor); | |
2052 for (;;) | |
2053 { | |
2054 /* one step backwards */ | |
230 | 2055 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2056 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2057 { |
2058 if (hiscnt == hislen) /* first time */ | |
2059 hiscnt = hisidx[histype]; | |
2060 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2061 hiscnt = hislen - 1; | |
2062 else if (hiscnt != hisidx[histype] + 1) | |
2063 --hiscnt; | |
2064 else /* at top of list */ | |
2065 { | |
2066 hiscnt = i; | |
2067 break; | |
2068 } | |
2069 } | |
2070 else /* one step forwards */ | |
2071 { | |
2072 /* on last entry, clear the line */ | |
2073 if (hiscnt == hisidx[histype]) | |
2074 { | |
2075 hiscnt = hislen; | |
2076 break; | |
2077 } | |
2078 | |
2079 /* not on a history line, nothing to do */ | |
2080 if (hiscnt == hislen) | |
2081 break; | |
2082 if (hiscnt == hislen - 1) /* wrap around */ | |
2083 hiscnt = 0; | |
2084 else | |
2085 ++hiscnt; | |
2086 } | |
2087 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2088 { | |
2089 hiscnt = i; | |
2090 break; | |
2091 } | |
230 | 2092 if ((c != K_UP && c != K_DOWN) |
180 | 2093 || hiscnt == i |
7 | 2094 || STRNCMP(history[histype][hiscnt].hisstr, |
2095 lookfor, (size_t)j) == 0) | |
2096 break; | |
2097 } | |
2098 | |
2099 if (hiscnt != i) /* jumped to other entry */ | |
2100 { | |
2101 char_u *p; | |
2102 int len; | |
2103 int old_firstc; | |
2104 | |
2105 vim_free(ccline.cmdbuff); | |
1718 | 2106 xpc.xp_context = EXPAND_NOTHING; |
7 | 2107 if (hiscnt == hislen) |
2108 p = lookfor; /* back to the old one */ | |
2109 else | |
2110 p = history[histype][hiscnt].hisstr; | |
2111 | |
2112 if (histype == HIST_SEARCH | |
2113 && p != lookfor | |
2114 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2115 { | |
2116 /* Correct for the separator character used when | |
2117 * adding the history entry vs the one used now. | |
2118 * First loop: count length. | |
2119 * Second loop: copy the characters. */ | |
2120 for (i = 0; i <= 1; ++i) | |
2121 { | |
2122 len = 0; | |
2123 for (j = 0; p[j] != NUL; ++j) | |
2124 { | |
2125 /* Replace old sep with new sep, unless it is | |
2126 * escaped. */ | |
2127 if (p[j] == old_firstc | |
2128 && (j == 0 || p[j - 1] != '\\')) | |
2129 { | |
2130 if (i > 0) | |
2131 ccline.cmdbuff[len] = firstc; | |
2132 } | |
2133 else | |
2134 { | |
2135 /* Escape new sep, unless it is already | |
2136 * escaped. */ | |
2137 if (p[j] == firstc | |
2138 && (j == 0 || p[j - 1] != '\\')) | |
2139 { | |
2140 if (i > 0) | |
2141 ccline.cmdbuff[len] = '\\'; | |
2142 ++len; | |
2143 } | |
2144 if (i > 0) | |
2145 ccline.cmdbuff[len] = p[j]; | |
2146 } | |
2147 ++len; | |
2148 } | |
2149 if (i == 0) | |
2150 { | |
2151 alloc_cmdbuff(len); | |
2152 if (ccline.cmdbuff == NULL) | |
2153 goto returncmd; | |
2154 } | |
2155 } | |
2156 ccline.cmdbuff[len] = NUL; | |
2157 } | |
2158 else | |
2159 { | |
2160 alloc_cmdbuff((int)STRLEN(p)); | |
2161 if (ccline.cmdbuff == NULL) | |
2162 goto returncmd; | |
2163 STRCPY(ccline.cmdbuff, p); | |
2164 } | |
2165 | |
2166 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2167 redrawcmd(); | |
2168 goto cmdline_changed; | |
2169 } | |
2170 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2171 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2172 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2173 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2174 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2175 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2176 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
|
2177 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
|
2178 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
|
2179 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2180 break; |
7 | 2181 #endif |
2182 | |
2183 case Ctrl_V: | |
2184 case Ctrl_Q: | |
2185 #ifdef FEAT_MOUSE | |
2186 ignore_drag_release = TRUE; | |
2187 #endif | |
2188 putcmdline('^', TRUE); | |
2189 c = get_literal(); /* get next (two) character(s) */ | |
2190 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
|
2191 extra_char = NUL; |
7 | 2192 #ifdef FEAT_MBYTE |
2193 /* may need to remove ^ when composing char was typed */ | |
2194 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2195 { | |
2196 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2197 msg_putchar(' '); | |
2198 cursorcmd(); | |
2199 } | |
2200 #endif | |
2201 break; | |
2202 | |
2203 #ifdef FEAT_DIGRAPHS | |
2204 case Ctrl_K: | |
2205 #ifdef FEAT_MOUSE | |
2206 ignore_drag_release = TRUE; | |
2207 #endif | |
2208 putcmdline('?', TRUE); | |
2209 #ifdef USE_ON_FLY_SCROLL | |
2210 dont_scroll = TRUE; /* disallow scrolling here */ | |
2211 #endif | |
2212 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
|
2213 extra_char = NUL; |
7 | 2214 if (c != NUL) |
2215 break; | |
2216 | |
2217 redrawcmd(); | |
2218 goto cmdline_not_changed; | |
2219 #endif /* FEAT_DIGRAPHS */ | |
2220 | |
2221 #ifdef FEAT_RIGHTLEFT | |
2222 case Ctrl__: /* CTRL-_: switch language mode */ | |
2223 if (!p_ari) | |
2224 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2225 # ifdef FEAT_FKMAP |
7 | 2226 if (p_altkeymap) |
2227 { | |
2228 cmd_fkmap = !cmd_fkmap; | |
2229 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2230 ccline.overstrike = FALSE; | |
2231 } | |
2232 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2233 # endif |
7 | 2234 cmd_hkmap = !cmd_hkmap; |
2235 goto cmdline_not_changed; | |
2236 #endif | |
2237 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2238 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
|
2239 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
|
2240 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
|
2241 |
7 | 2242 default: |
2243 #ifdef UNIX | |
2244 if (c == intr_char) | |
2245 { | |
2246 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2247 putting it in history */ | |
2248 goto returncmd; /* back to Normal mode */ | |
2249 } | |
2250 #endif | |
2251 /* | |
2252 * Normal character with no special meaning. Just set mod_mask | |
2253 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2254 * the string <S-Space>. This should only happen after ^V. | |
2255 */ | |
2256 if (!IS_SPECIAL(c)) | |
2257 mod_mask = 0x0; | |
2258 break; | |
2259 } | |
2260 /* | |
2261 * End of switch on command line character. | |
2262 * We come here if we have a normal character. | |
2263 */ | |
2264 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2265 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2266 #ifdef FEAT_MBYTE |
2267 /* Add ABBR_OFF for characters above 0x100, this is | |
2268 * what check_abbr() expects. */ | |
2269 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2270 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2271 c) || c == Ctrl_RSB)) |
7 | 2272 goto cmdline_changed; |
2273 | |
2274 /* | |
2275 * put the character in the command line | |
2276 */ | |
2277 if (IS_SPECIAL(c) || mod_mask != 0) | |
2278 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2279 else | |
2280 { | |
2281 #ifdef FEAT_MBYTE | |
2282 if (has_mbyte) | |
2283 { | |
2284 j = (*mb_char2bytes)(c, IObuff); | |
2285 IObuff[j] = NUL; /* exclude composing chars */ | |
2286 put_on_cmdline(IObuff, j, TRUE); | |
2287 } | |
2288 else | |
2289 #endif | |
2290 { | |
2291 IObuff[0] = c; | |
2292 put_on_cmdline(IObuff, 1, TRUE); | |
2293 } | |
2294 } | |
2295 goto cmdline_changed; | |
2296 | |
2297 /* | |
2298 * This part implements incremental searches for "/" and "?" | |
2299 * Jump to cmdline_not_changed when a character has been read but the command | |
2300 * line did not change. Then we only search and redraw if something changed in | |
2301 * the past. | |
2302 * Jump to cmdline_changed when the command line did change. | |
2303 * (Sorry for the goto's, I know it is ugly). | |
2304 */ | |
2305 cmdline_not_changed: | |
2306 #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
|
2307 if (!is_state.incsearch_postponed) |
7 | 2308 continue; |
2309 #endif | |
2310 | |
2311 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
|
2312 /* 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
|
2313 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
|
2314 |
7 | 2315 #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
|
2316 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2317 #endif |
2318 | |
2319 #ifdef FEAT_RIGHTLEFT | |
2320 if (cmdmsg_rl | |
2321 # ifdef FEAT_ARABIC | |
534 | 2322 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2323 # endif |
2324 ) | |
2325 /* Always redraw the whole command line to fix shaping and | |
3374 | 2326 * right-left typing. Not efficient, but it works. |
2327 * Do it only when there are no characters left to read | |
2328 * to avoid useless intermediate redraws. */ | |
2329 if (vpeekc() == NUL) | |
2330 redrawcmd(); | |
7 | 2331 #endif |
2332 } | |
2333 | |
2334 returncmd: | |
2335 | |
2336 #ifdef FEAT_RIGHTLEFT | |
2337 cmdmsg_rl = FALSE; | |
2338 #endif | |
2339 | |
2340 #ifdef FEAT_FKMAP | |
2341 cmd_fkmap = 0; | |
2342 #endif | |
2343 | |
2344 ExpandCleanup(&xpc); | |
1718 | 2345 ccline.xpc = NULL; |
7 | 2346 |
2347 #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
|
2348 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2349 #endif |
2350 | |
2351 if (ccline.cmdbuff != NULL) | |
2352 { | |
2353 /* | |
2354 * Put line in history buffer (":" and "=" only when it was typed). | |
2355 */ | |
2356 #ifdef FEAT_CMDHIST | |
2357 if (ccline.cmdlen && firstc != NUL | |
2358 && (some_key_typed || histype == HIST_SEARCH)) | |
2359 { | |
2360 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2361 histype == HIST_SEARCH ? firstc : NUL); | |
2362 if (firstc == ':') | |
2363 { | |
2364 vim_free(new_last_cmdline); | |
2365 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2366 } | |
2367 } | |
2368 #endif | |
2369 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2370 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
|
2371 abandon_cmdline(); |
7 | 2372 } |
2373 | |
2374 /* | |
2375 * If the screen was shifted up, redraw the whole screen (later). | |
2376 * If the line is too long, clear it, so ruler and shown command do | |
2377 * not get printed in the middle of it. | |
2378 */ | |
2379 msg_check(); | |
2380 msg_scroll = save_msg_scroll; | |
2381 redir_off = FALSE; | |
2382 | |
2383 /* When the command line was typed, no need for a wait-return prompt. */ | |
2384 if (some_key_typed) | |
2385 need_wait_return = FALSE; | |
2386 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2387 /* 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
|
2388 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
|
2389 |
7 | 2390 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2391 #ifdef HAVE_INPUT_METHOD |
7 | 2392 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2393 im_save_status(b_im_ptr); | |
2394 im_set_active(FALSE); | |
2395 #endif | |
2396 #ifdef FEAT_MOUSE | |
2397 setmouse(); | |
2398 #endif | |
2399 #ifdef CURSOR_SHAPE | |
2400 ui_cursor_shape(); /* may show different cursor shape */ | |
2401 #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
|
2402 sb_text_end_cmdline(); |
7 | 2403 |
95 | 2404 { |
2405 char_u *p = ccline.cmdbuff; | |
2406 | |
2407 /* Make ccline empty, getcmdline() may try to use it. */ | |
2408 ccline.cmdbuff = NULL; | |
2409 return p; | |
2410 } | |
7 | 2411 } |
2412 | |
2413 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2414 /* | |
2415 * Get a command line with a prompt. | |
2416 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2417 * f_input() when evaluating an expression from CTRL-R =). | |
2418 * Returns the command line in allocated memory, or NULL. | |
2419 */ | |
2420 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2421 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2422 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2423 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2424 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2425 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2426 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2427 { |
2428 char_u *s; | |
2429 struct cmdline_info save_ccline; | |
2430 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
|
2431 int msg_silent_save = msg_silent; |
7 | 2432 |
95 | 2433 save_cmdline(&save_ccline); |
7 | 2434 ccline.cmdprompt = prompt; |
2435 ccline.cmdattr = attr; | |
531 | 2436 # ifdef FEAT_EVAL |
2437 ccline.xp_context = xp_context; | |
2438 ccline.xp_arg = xp_arg; | |
2439 ccline.input_fn = (firstc == '@'); | |
2440 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2441 msg_silent = 0; |
7 | 2442 s = getcmdline(firstc, 1L, 0); |
95 | 2443 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2444 msg_silent = msg_silent_save; |
3020 | 2445 /* Restore msg_col, the prompt from input() may have changed it. |
2446 * But only if called recursively and the commandline is therefore being | |
2447 * restored to an old one; if not, the input() prompt stays on the screen, | |
2448 * so we need its modified msg_col left intact. */ | |
2449 if (ccline.cmdbuff != NULL) | |
2450 msg_col = msg_col_save; | |
7 | 2451 |
2452 return s; | |
2453 } | |
2454 #endif | |
2455 | |
632 | 2456 /* |
634 | 2457 * Return TRUE when the text must not be changed and we can't switch to |
2458 * another window or buffer. Used when editing the command line, evaluating | |
2459 * 'balloonexpr', etc. | |
632 | 2460 */ |
2461 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2462 text_locked(void) |
632 | 2463 { |
2464 #ifdef FEAT_CMDWIN | |
2465 if (cmdwin_type != 0) | |
2466 return TRUE; | |
2467 #endif | |
634 | 2468 return textlock != 0; |
632 | 2469 } |
2470 | |
2471 /* | |
2472 * Give an error message for a command that isn't allowed while the cmdline | |
2473 * window is open or editing the cmdline in another way. | |
2474 */ | |
2475 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2476 text_locked_msg(void) |
632 | 2477 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2478 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2479 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2480 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2481 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2482 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2483 { |
632 | 2484 #ifdef FEAT_CMDWIN |
2485 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2486 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2487 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2488 return e_secure; |
632 | 2489 } |
2490 | |
819 | 2491 /* |
1834 | 2492 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2493 * and give an error message. | |
819 | 2494 */ |
2495 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2496 curbuf_locked(void) |
819 | 2497 { |
2498 if (curbuf_lock > 0) | |
2499 { | |
2500 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2501 return TRUE; | |
2502 } | |
1834 | 2503 return allbuf_locked(); |
2504 } | |
2505 | |
2506 /* | |
2507 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2508 * message. | |
2509 */ | |
2510 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2511 allbuf_locked(void) |
1834 | 2512 { |
2513 if (allbuf_lock > 0) | |
2514 { | |
2515 EMSG(_("E811: Not allowed to change buffer information now")); | |
2516 return TRUE; | |
2517 } | |
819 | 2518 return FALSE; |
2519 } | |
2520 | |
7 | 2521 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2522 cmdline_charsize(int idx) |
7 | 2523 { |
2524 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2525 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2526 return 1; | |
2527 #endif | |
2528 return ptr2cells(ccline.cmdbuff + idx); | |
2529 } | |
2530 | |
2531 /* | |
2532 * Compute the offset of the cursor on the command line for the prompt and | |
2533 * indent. | |
2534 */ | |
2535 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2536 set_cmdspos(void) |
7 | 2537 { |
531 | 2538 if (ccline.cmdfirstc != NUL) |
7 | 2539 ccline.cmdspos = 1 + ccline.cmdindent; |
2540 else | |
2541 ccline.cmdspos = 0 + ccline.cmdindent; | |
2542 } | |
2543 | |
2544 /* | |
2545 * Compute the screen position for the cursor on the command line. | |
2546 */ | |
2547 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2548 set_cmdspos_cursor(void) |
7 | 2549 { |
2550 int i, m, c; | |
2551 | |
2552 set_cmdspos(); | |
2553 if (KeyTyped) | |
534 | 2554 { |
7 | 2555 m = Columns * Rows; |
534 | 2556 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2557 m = MAXCOL; | |
2558 } | |
7 | 2559 else |
2560 m = MAXCOL; | |
2561 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2562 { | |
2563 c = cmdline_charsize(i); | |
2564 #ifdef FEAT_MBYTE | |
2565 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2566 if (has_mbyte) | |
2567 correct_cmdspos(i, c); | |
2568 #endif | |
1612 | 2569 /* If the cmdline doesn't fit, show cursor on last visible char. |
2570 * Don't move the cursor itself, so we can still append. */ | |
7 | 2571 if ((ccline.cmdspos += c) >= m) |
2572 { | |
2573 ccline.cmdspos -= c; | |
2574 break; | |
2575 } | |
2576 #ifdef FEAT_MBYTE | |
2577 if (has_mbyte) | |
474 | 2578 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2579 #endif |
2580 } | |
2581 } | |
2582 | |
2583 #ifdef FEAT_MBYTE | |
2584 /* | |
2585 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2586 * character that doesn't fit, so that a ">" must be displayed. | |
2587 */ | |
2588 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2589 correct_cmdspos(int idx, int cells) |
7 | 2590 { |
474 | 2591 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2592 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2593 && ccline.cmdspos % Columns + cells > Columns) | |
2594 ccline.cmdspos++; | |
2595 } | |
2596 #endif | |
2597 | |
2598 /* | |
2599 * Get an Ex command line for the ":" command. | |
2600 */ | |
2601 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2602 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2603 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2604 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2605 int indent) /* indent for inside conditionals */ |
7 | 2606 { |
2607 /* When executing a register, remove ':' that's in front of each line. */ | |
2608 if (exec_from_reg && vpeekc() == ':') | |
2609 (void)vgetc(); | |
2610 return getcmdline(c, 1L, indent); | |
2611 } | |
2612 | |
2613 /* | |
2614 * Get an Ex command line for Ex mode. | |
2615 * In Ex mode we only use the OS supplied line editing features and no | |
2616 * mappings or abbreviations. | |
168 | 2617 * Returns a string in allocated memory or NULL. |
7 | 2618 */ |
2619 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2620 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2621 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2622 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2623 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2624 int indent) /* indent for inside conditionals */ |
7 | 2625 { |
168 | 2626 garray_T line_ga; |
2627 char_u *pend; | |
2628 int startcol = 0; | |
1329 | 2629 int c1 = 0; |
168 | 2630 int escaped = FALSE; /* CTRL-V typed */ |
2631 int vcol = 0; | |
2632 char_u *p; | |
1329 | 2633 int prev_char; |
5966 | 2634 int len; |
7 | 2635 |
2636 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2637 * confuses the system function that computes tabstops. */ | |
2638 cursor_on(); | |
2639 | |
2640 /* always start in column 0; write a newline if necessary */ | |
2641 compute_cmdrow(); | |
168 | 2642 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2643 msg_putchar('\n'); |
168 | 2644 if (promptc == ':') |
7 | 2645 { |
164 | 2646 /* indent that is only displayed, not in the line itself */ |
168 | 2647 if (p_prompt) |
2648 msg_putchar(':'); | |
7 | 2649 while (indent-- > 0) |
2650 msg_putchar(' '); | |
2651 startcol = msg_col; | |
2652 } | |
2653 | |
2654 ga_init2(&line_ga, 1, 30); | |
2655 | |
164 | 2656 /* autoindent for :insert and :append is in the line itself */ |
168 | 2657 if (promptc <= 0) |
164 | 2658 { |
2659 vcol = indent; | |
2660 while (indent >= 8) | |
2661 { | |
2662 ga_append(&line_ga, TAB); | |
2663 msg_puts((char_u *)" "); | |
2664 indent -= 8; | |
2665 } | |
2666 while (indent-- > 0) | |
2667 { | |
2668 ga_append(&line_ga, ' '); | |
2669 msg_putchar(' '); | |
2670 } | |
2671 } | |
168 | 2672 ++no_mapping; |
2673 ++allow_keys; | |
164 | 2674 |
7 | 2675 /* |
2676 * Get the line, one character at a time. | |
2677 */ | |
2678 got_int = FALSE; | |
168 | 2679 while (!got_int) |
7 | 2680 { |
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
|
2681 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
|
2682 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
|
2683 |
7 | 2684 if (ga_grow(&line_ga, 40) == FAIL) |
2685 break; | |
2686 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2687 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2688 * 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
|
2689 */ |
1329 | 2690 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
|
2691 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2692 /* 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
|
2693 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
|
2694 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
|
2695 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2696 c1 = vgetc(); |
7 | 2697 |
2698 /* | |
168 | 2699 * Handle line editing. |
2700 * Previously this was left to the system, putting the terminal in | |
2701 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2702 */ |
168 | 2703 if (got_int) |
2704 { | |
2705 msg_putchar('\n'); | |
2706 break; | |
2707 } | |
2708 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2709 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
|
2710 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2711 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
|
2712 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
|
2713 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2714 |
168 | 2715 if (!escaped) |
7 | 2716 { |
168 | 2717 /* CR typed means "enter", which is NL */ |
2718 if (c1 == '\r') | |
2719 c1 = '\n'; | |
2720 | |
2721 if (c1 == BS || c1 == K_BS | |
2722 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2723 { |
168 | 2724 if (line_ga.ga_len > 0) |
2725 { | |
5966 | 2726 #ifdef FEAT_MBYTE |
2727 if (has_mbyte) | |
2728 { | |
2729 p = (char_u *)line_ga.ga_data; | |
2730 p[line_ga.ga_len] = NUL; | |
2731 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2732 line_ga.ga_len -= len; | |
2733 } | |
2734 else | |
2735 #endif | |
2736 --line_ga.ga_len; | |
168 | 2737 goto redraw; |
2738 } | |
2739 continue; | |
7 | 2740 } |
2741 | |
168 | 2742 if (c1 == Ctrl_U) |
7 | 2743 { |
168 | 2744 msg_col = startcol; |
2745 msg_clr_eos(); | |
2746 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
|
2747 goto redraw; |
168 | 2748 } |
2749 | |
2750 if (c1 == Ctrl_T) | |
2751 { | |
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
|
2752 sw = get_sw_value(curbuf); |
168 | 2753 p = (char_u *)line_ga.ga_data; |
2754 p[line_ga.ga_len] = NUL; | |
5995 | 2755 indent = get_indent_str(p, 8, FALSE); |
3740 | 2756 indent += sw - indent % sw; |
168 | 2757 add_indent: |
5995 | 2758 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2759 { |
7009 | 2760 (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
|
2761 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
|
2762 s = skipwhite(p); |
168 | 2763 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2764 *s = ' '; | |
2765 ++line_ga.ga_len; | |
7 | 2766 } |
168 | 2767 redraw: |
2768 /* redraw the line */ | |
2769 msg_col = startcol; | |
2770 vcol = 0; | |
5966 | 2771 p = (char_u *)line_ga.ga_data; |
2772 p[line_ga.ga_len] = NUL; | |
2773 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2774 { |
168 | 2775 if (*p == TAB) |
7 | 2776 { |
168 | 2777 do |
7 | 2778 { |
168 | 2779 msg_putchar(' '); |
2780 } while (++vcol % 8); | |
5966 | 2781 ++p; |
7 | 2782 } |
168 | 2783 else |
164 | 2784 { |
5966 | 2785 len = MB_PTR2LEN(p); |
2786 msg_outtrans_len(p, len); | |
2787 vcol += ptr2cells(p); | |
2788 p += len; | |
7 | 2789 } |
2790 } | |
168 | 2791 msg_clr_eos(); |
1329 | 2792 windgoto(msg_row, msg_col); |
168 | 2793 continue; |
2794 } | |
2795 | |
2796 if (c1 == Ctrl_D) | |
2797 { | |
2798 /* Delete one shiftwidth. */ | |
2799 p = (char_u *)line_ga.ga_data; | |
2800 if (prev_char == '0' || prev_char == '^') | |
7 | 2801 { |
168 | 2802 if (prev_char == '^') |
2803 ex_keep_indent = TRUE; | |
2804 indent = 0; | |
2805 p[--line_ga.ga_len] = NUL; | |
7 | 2806 } |
2807 else | |
2808 { | |
168 | 2809 p[line_ga.ga_len] = NUL; |
5995 | 2810 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
|
2811 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
|
2812 { |
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
|
2813 --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
|
2814 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
|
2815 } |
168 | 2816 } |
5995 | 2817 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2818 { |
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
|
2819 s = skipwhite(p); |
168 | 2820 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2821 --line_ga.ga_len; | |
7 | 2822 } |
168 | 2823 goto add_indent; |
2824 } | |
2825 | |
2826 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2827 { | |
2828 escaped = TRUE; | |
2829 continue; | |
7 | 2830 } |
168 | 2831 |
2832 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2833 if (IS_SPECIAL(c1)) | |
2834 continue; | |
7 | 2835 } |
168 | 2836 |
2837 if (IS_SPECIAL(c1)) | |
2838 c1 = '?'; | |
5966 | 2839 #ifdef FEAT_MBYTE |
2840 if (has_mbyte) | |
2841 len = (*mb_char2bytes)(c1, | |
2842 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2843 else | |
2844 #endif | |
2845 { | |
2846 len = 1; | |
2847 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2848 } | |
168 | 2849 if (c1 == '\n') |
2850 msg_putchar('\n'); | |
2851 else if (c1 == TAB) | |
2852 { | |
2853 /* Don't use chartabsize(), 'ts' can be different */ | |
2854 do | |
2855 { | |
2856 msg_putchar(' '); | |
2857 } while (++vcol % 8); | |
2858 } | |
7 | 2859 else |
2860 { | |
168 | 2861 msg_outtrans_len( |
5966 | 2862 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2863 vcol += char2cells(c1); |
7 | 2864 } |
5966 | 2865 line_ga.ga_len += len; |
168 | 2866 escaped = FALSE; |
2867 | |
2868 windgoto(msg_row, msg_col); | |
164 | 2869 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2870 |
2590 | 2871 /* We are done when a NL is entered, but not when it comes after an |
2872 * odd number of backslashes, that results in a NUL. */ | |
2873 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2874 { |
2590 | 2875 int bcount = 0; |
2876 | |
2877 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2878 ++bcount; | |
2879 | |
2880 if (bcount > 0) | |
2881 { | |
2882 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2883 * "\NL", etc. */ | |
2884 line_ga.ga_len -= (bcount + 1) / 2; | |
2885 pend -= (bcount + 1) / 2; | |
2886 pend[-1] = '\n'; | |
2887 } | |
2888 | |
2889 if ((bcount & 1) == 0) | |
2890 { | |
2891 --line_ga.ga_len; | |
2892 --pend; | |
2893 *pend = NUL; | |
2894 break; | |
2895 } | |
7 | 2896 } |
2897 } | |
2898 | |
168 | 2899 --no_mapping; |
2900 --allow_keys; | |
2901 | |
7 | 2902 /* make following messages go to the next line */ |
2903 msg_didout = FALSE; | |
2904 msg_col = 0; | |
2905 if (msg_row < Rows - 1) | |
2906 ++msg_row; | |
2907 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2908 | |
2909 if (got_int) | |
2910 ga_clear(&line_ga); | |
2911 | |
2912 return (char_u *)line_ga.ga_data; | |
2913 } | |
2914 | |
502 | 2915 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2916 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2917 /* |
2918 * Return TRUE if ccline.overstrike is on. | |
2919 */ | |
2920 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2921 cmdline_overstrike(void) |
7 | 2922 { |
2923 return ccline.overstrike; | |
2924 } | |
2925 | |
2926 /* | |
2927 * Return TRUE if the cursor is at the end of the cmdline. | |
2928 */ | |
2929 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2930 cmdline_at_end(void) |
7 | 2931 { |
2932 return (ccline.cmdpos >= ccline.cmdlen); | |
2933 } | |
2934 #endif | |
2935 | |
574 | 2936 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2937 /* |
2938 * Return the virtual column number at the current cursor position. | |
2939 * This is used by the IM code to obtain the start of the preedit string. | |
2940 */ | |
2941 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2942 cmdline_getvcol_cursor(void) |
7 | 2943 { |
2944 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2945 return MAXCOL; | |
2946 | |
2947 # ifdef FEAT_MBYTE | |
2948 if (has_mbyte) | |
2949 { | |
2950 colnr_T col; | |
2951 int i = 0; | |
2952 | |
2953 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 2954 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 2955 |
2956 return col; | |
2957 } | |
2958 else | |
2959 # endif | |
2960 return ccline.cmdpos; | |
2961 } | |
2962 #endif | |
2963 | |
2964 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
2965 /* | |
2966 * If part of the command line is an IM preedit string, redraw it with | |
2967 * IM feedback attributes. The cursor position is restored after drawing. | |
2968 */ | |
2969 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2970 redrawcmd_preedit(void) |
7 | 2971 { |
2972 if ((State & CMDLINE) | |
2973 && xic != NULL | |
976 | 2974 /* && im_get_status() doesn't work when using SCIM */ |
7 | 2975 && !p_imdisable |
2976 && im_is_preediting()) | |
2977 { | |
2978 int cmdpos = 0; | |
2979 int cmdspos; | |
2980 int old_row; | |
2981 int old_col; | |
2982 colnr_T col; | |
2983 | |
2984 old_row = msg_row; | |
2985 old_col = msg_col; | |
531 | 2986 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 2987 |
2988 # ifdef FEAT_MBYTE | |
2989 if (has_mbyte) | |
2990 { | |
2991 for (col = 0; col < preedit_start_col | |
2992 && cmdpos < ccline.cmdlen; ++col) | |
2993 { | |
2994 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 2995 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2996 } |
2997 } | |
2998 else | |
2999 # endif | |
3000 { | |
3001 cmdspos += preedit_start_col; | |
3002 cmdpos += preedit_start_col; | |
3003 } | |
3004 | |
3005 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3006 msg_col = cmdspos % (int)Columns; | |
3007 if (msg_row >= Rows) | |
3008 msg_row = Rows - 1; | |
3009 | |
3010 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3011 { | |
3012 int char_len; | |
3013 int char_attr; | |
3014 | |
3015 char_attr = im_get_feedback_attr(col); | |
3016 if (char_attr < 0) | |
3017 break; /* end of preedit string */ | |
3018 | |
3019 # ifdef FEAT_MBYTE | |
3020 if (has_mbyte) | |
474 | 3021 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3022 else |
3023 # endif | |
3024 char_len = 1; | |
3025 | |
3026 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3027 cmdpos += char_len; | |
3028 } | |
3029 | |
3030 msg_row = old_row; | |
3031 msg_col = old_col; | |
3032 } | |
3033 } | |
3034 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3035 | |
3036 /* | |
3037 * Allocate a new command line buffer. | |
3038 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3039 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
3040 */ | |
3041 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3042 alloc_cmdbuff(int len) |
7 | 3043 { |
3044 /* | |
3045 * give some extra space to avoid having to allocate all the time | |
3046 */ | |
3047 if (len < 80) | |
3048 len = 100; | |
3049 else | |
3050 len += 20; | |
3051 | |
3052 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3053 ccline.cmdbufflen = len; | |
3054 } | |
3055 | |
3056 /* | |
3057 * Re-allocate the command line to length len + something extra. | |
3058 * return FAIL for failure, OK otherwise | |
3059 */ | |
3060 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3061 realloc_cmdbuff(int len) |
7 | 3062 { |
3063 char_u *p; | |
3064 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3065 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3066 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
|
3067 |
7 | 3068 p = ccline.cmdbuff; |
3069 alloc_cmdbuff(len); /* will get some more */ | |
3070 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3071 { | |
3072 ccline.cmdbuff = p; /* keep the old one */ | |
3073 return FAIL; | |
3074 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3075 /* 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
|
3076 * 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
|
3077 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
|
3078 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3079 vim_free(p); |
1718 | 3080 |
3081 if (ccline.xpc != NULL | |
3082 && ccline.xpc->xp_pattern != NULL | |
3083 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3084 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3085 { | |
1754 | 3086 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3087 |
3088 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3089 * to point into the newly allocated memory. */ | |
3090 if (i >= 0 && i <= ccline.cmdlen) | |
3091 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3092 } | |
3093 | |
7 | 3094 return OK; |
3095 } | |
3096 | |
359 | 3097 #if defined(FEAT_ARABIC) || defined(PROTO) |
3098 static char_u *arshape_buf = NULL; | |
3099 | |
3100 # if defined(EXITFREE) || defined(PROTO) | |
3101 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3102 free_cmdline_buf(void) |
359 | 3103 { |
3104 vim_free(arshape_buf); | |
3105 } | |
3106 # endif | |
3107 #endif | |
3108 | |
7 | 3109 /* |
3110 * Draw part of the cmdline at the current cursor position. But draw stars | |
3111 * when cmdline_star is TRUE. | |
3112 */ | |
3113 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3114 draw_cmdline(int start, int len) |
7 | 3115 { |
3116 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3117 int i; | |
3118 | |
3119 if (cmdline_star > 0) | |
3120 for (i = 0; i < len; ++i) | |
3121 { | |
3122 msg_putchar('*'); | |
3123 # ifdef FEAT_MBYTE | |
3124 if (has_mbyte) | |
474 | 3125 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3126 # endif |
3127 } | |
3128 else | |
3129 #endif | |
3130 #ifdef FEAT_ARABIC | |
3131 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3132 { | |
3133 static int buflen = 0; | |
3134 char_u *p; | |
3135 int j; | |
3136 int newlen = 0; | |
3137 int mb_l; | |
719 | 3138 int pc, pc1 = 0; |
7 | 3139 int prev_c = 0; |
3140 int prev_c1 = 0; | |
714 | 3141 int u8c; |
3142 int u8cc[MAX_MCO]; | |
7 | 3143 int nc = 0; |
3144 | |
3145 /* | |
3146 * Do arabic shaping into a temporary buffer. This is very | |
3147 * inefficient! | |
3148 */ | |
507 | 3149 if (len * 2 + 2 > buflen) |
7 | 3150 { |
3151 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3152 * alloc()/free() calls. */ | |
359 | 3153 vim_free(arshape_buf); |
507 | 3154 buflen = len * 2 + 2; |
359 | 3155 arshape_buf = alloc(buflen); |
3156 if (arshape_buf == NULL) | |
7 | 3157 return; /* out of memory */ |
3158 } | |
3159 | |
507 | 3160 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3161 { | |
3162 /* Prepend a space to draw the leading composing char on. */ | |
3163 arshape_buf[0] = ' '; | |
3164 newlen = 1; | |
3165 } | |
3166 | |
7 | 3167 for (j = start; j < start + len; j += mb_l) |
3168 { | |
3169 p = ccline.cmdbuff + j; | |
714 | 3170 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3171 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3172 if (ARABIC_CHAR(u8c)) |
3173 { | |
3174 /* Do Arabic shaping. */ | |
3175 if (cmdmsg_rl) | |
3176 { | |
3177 /* displaying from right to left */ | |
3178 pc = prev_c; | |
3179 pc1 = prev_c1; | |
714 | 3180 prev_c1 = u8cc[0]; |
7 | 3181 if (j + mb_l >= start + len) |
3182 nc = NUL; | |
3183 else | |
3184 nc = utf_ptr2char(p + mb_l); | |
3185 } | |
3186 else | |
3187 { | |
3188 /* displaying from left to right */ | |
3189 if (j + mb_l >= start + len) | |
3190 pc = NUL; | |
3191 else | |
714 | 3192 { |
3193 int pcc[MAX_MCO]; | |
3194 | |
3195 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3196 start + len - j - mb_l); |
714 | 3197 pc1 = pcc[0]; |
3198 } | |
7 | 3199 nc = prev_c; |
3200 } | |
3201 prev_c = u8c; | |
3202 | |
714 | 3203 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3204 |
359 | 3205 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3206 if (u8cc[0] != 0) |
7 | 3207 { |
714 | 3208 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3209 if (u8cc[1] != 0) | |
3210 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3211 arshape_buf + newlen); |
7 | 3212 } |
3213 } | |
3214 else | |
3215 { | |
3216 prev_c = u8c; | |
359 | 3217 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3218 newlen += mb_l; |
3219 } | |
3220 } | |
3221 | |
359 | 3222 msg_outtrans_len(arshape_buf, newlen); |
7 | 3223 } |
3224 else | |
3225 #endif | |
3226 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3227 } | |
3228 | |
3229 /* | |
3230 * Put a character on the command line. Shifts the following text to the | |
3231 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3232 * "c" must be printable (fit in one display cell)! | |
3233 */ | |
3234 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3235 putcmdline(int c, int shift) |
7 | 3236 { |
3237 if (cmd_silent) | |
3238 return; | |
3239 msg_no_more = TRUE; | |
3240 msg_putchar(c); | |
3241 if (shift) | |
3242 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3243 msg_no_more = FALSE; | |
3244 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3245 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3246 extra_char_shift = shift; |
7 | 3247 } |
3248 | |
3249 /* | |
3250 * Undo a putcmdline(c, FALSE). | |
3251 */ | |
3252 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3253 unputcmdline(void) |
7 | 3254 { |
3255 if (cmd_silent) | |
3256 return; | |
3257 msg_no_more = TRUE; | |
3258 if (ccline.cmdlen == ccline.cmdpos) | |
3259 msg_putchar(' '); | |
3558 | 3260 #ifdef FEAT_MBYTE |
3261 else if (has_mbyte) | |
3262 draw_cmdline(ccline.cmdpos, | |
3263 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3264 #endif | |
7 | 3265 else |
3266 draw_cmdline(ccline.cmdpos, 1); | |
3267 msg_no_more = FALSE; | |
3268 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3269 extra_char = NUL; |
7 | 3270 } |
3271 | |
3272 /* | |
3273 * Put the given string, of the given length, onto the command line. | |
3274 * If len is -1, then STRLEN() is used to calculate the length. | |
3275 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3276 * part will be redrawn, otherwise it will not. If this function is called | |
3277 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3278 * called afterwards. | |
3279 */ | |
3280 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3281 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3282 { |
3283 int retval; | |
3284 int i; | |
3285 int m; | |
3286 int c; | |
3287 | |
3288 if (len < 0) | |
3289 len = (int)STRLEN(str); | |
3290 | |
3291 /* Check if ccline.cmdbuff needs to be longer */ | |
3292 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
|
3293 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3294 else |
3295 retval = OK; | |
3296 if (retval == OK) | |
3297 { | |
3298 if (!ccline.overstrike) | |
3299 { | |
3300 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3301 ccline.cmdbuff + ccline.cmdpos, | |
3302 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3303 ccline.cmdlen += len; | |
3304 } | |
3305 else | |
3306 { | |
3307 #ifdef FEAT_MBYTE | |
3308 if (has_mbyte) | |
3309 { | |
3310 /* Count nr of characters in the new string. */ | |
3311 m = 0; | |
474 | 3312 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3313 ++m; |
3314 /* Count nr of bytes in cmdline that are overwritten by these | |
3315 * characters. */ | |
3316 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3317 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3318 --m; |
3319 if (i < ccline.cmdlen) | |
3320 { | |
3321 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3322 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3323 ccline.cmdlen += ccline.cmdpos + len - i; | |
3324 } | |
3325 else | |
3326 ccline.cmdlen = ccline.cmdpos + len; | |
3327 } | |
3328 else | |
3329 #endif | |
3330 if (ccline.cmdpos + len > ccline.cmdlen) | |
3331 ccline.cmdlen = ccline.cmdpos + len; | |
3332 } | |
3333 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3334 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3335 | |
3336 #ifdef FEAT_MBYTE | |
3337 if (enc_utf8) | |
3338 { | |
3339 /* When the inserted text starts with a composing character, | |
3340 * backup to the character before it. There could be two of them. | |
3341 */ | |
3342 i = 0; | |
3343 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3344 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3345 { | |
3346 i = (*mb_head_off)(ccline.cmdbuff, | |
3347 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3348 ccline.cmdpos -= i; | |
3349 len += i; | |
3350 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3351 } | |
3352 # ifdef FEAT_ARABIC | |
3353 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3354 { | |
3355 /* Check the previous character for Arabic combining pair. */ | |
3356 i = (*mb_head_off)(ccline.cmdbuff, | |
3357 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3358 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3359 + ccline.cmdpos - i), c)) | |
3360 { | |
3361 ccline.cmdpos -= i; | |
3362 len += i; | |
3363 } | |
3364 else | |
3365 i = 0; | |
3366 } | |
3367 # endif | |
3368 if (i != 0) | |
3369 { | |
3370 /* Also backup the cursor position. */ | |
3371 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3372 ccline.cmdspos -= i; | |
3373 msg_col -= i; | |
3374 if (msg_col < 0) | |
3375 { | |
3376 msg_col += Columns; | |
3377 --msg_row; | |
3378 } | |
3379 } | |
3380 } | |
3381 #endif | |
3382 | |
3383 if (redraw && !cmd_silent) | |
3384 { | |
3385 msg_no_more = TRUE; | |
3386 i = cmdline_row; | |
3114 | 3387 cursorcmd(); |
7 | 3388 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3389 /* Avoid clearing the rest of the line too often. */ | |
3390 if (cmdline_row != i || ccline.overstrike) | |
3391 msg_clr_eos(); | |
3392 msg_no_more = FALSE; | |
3393 } | |
3394 #ifdef FEAT_FKMAP | |
3395 /* | |
3396 * If we are in Farsi command mode, the character input must be in | |
3397 * Insert mode. So do not advance the cmdpos. | |
3398 */ | |
3399 if (!cmd_fkmap) | |
3400 #endif | |
3401 { | |
3402 if (KeyTyped) | |
534 | 3403 { |
7 | 3404 m = Columns * Rows; |
534 | 3405 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3406 m = MAXCOL; | |
3407 } | |
7 | 3408 else |
3409 m = MAXCOL; | |
3410 for (i = 0; i < len; ++i) | |
3411 { | |
3412 c = cmdline_charsize(ccline.cmdpos); | |
3413 #ifdef FEAT_MBYTE | |
3414 /* count ">" for a double-wide char that doesn't fit. */ | |
3415 if (has_mbyte) | |
3416 correct_cmdspos(ccline.cmdpos, c); | |
3417 #endif | |
1612 | 3418 /* Stop cursor at the end of the screen, but do increment the |
3419 * insert position, so that entering a very long command | |
3420 * works, even though you can't see it. */ | |
3421 if (ccline.cmdspos + c < m) | |
3422 ccline.cmdspos += c; | |
7 | 3423 #ifdef FEAT_MBYTE |
3424 if (has_mbyte) | |
3425 { | |
474 | 3426 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3427 if (c > len - i - 1) |
3428 c = len - i - 1; | |
3429 ccline.cmdpos += c; | |
3430 i += c; | |
3431 } | |
3432 #endif | |
3433 ++ccline.cmdpos; | |
3434 } | |
3435 } | |
3436 } | |
3437 if (redraw) | |
3438 msg_check(); | |
3439 return retval; | |
3440 } | |
3441 | |
95 | 3442 static struct cmdline_info prev_ccline; |
3443 static int prev_ccline_used = FALSE; | |
3444 | |
3445 /* | |
3446 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3447 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3448 * available globally in prev_ccline. | |
3449 */ | |
3450 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3451 save_cmdline(struct cmdline_info *ccp) |
95 | 3452 { |
3453 if (!prev_ccline_used) | |
3454 { | |
3455 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3456 prev_ccline_used = TRUE; | |
3457 } | |
3458 *ccp = prev_ccline; | |
3459 prev_ccline = ccline; | |
3460 ccline.cmdbuff = NULL; | |
3461 ccline.cmdprompt = NULL; | |
1718 | 3462 ccline.xpc = NULL; |
95 | 3463 } |
3464 | |
3465 /* | |
1214 | 3466 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3467 */ |
3468 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3469 restore_cmdline(struct cmdline_info *ccp) |
95 | 3470 { |
3471 ccline = prev_ccline; | |
3472 prev_ccline = *ccp; | |
3473 } | |
3474 | |
849 | 3475 #if defined(FEAT_EVAL) || defined(PROTO) |
3476 /* | |
3477 * Save the command line into allocated memory. Returns a pointer to be | |
3478 * passed to restore_cmdline_alloc() later. | |
3479 * Returns NULL when failed. | |
3480 */ | |
3481 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3482 save_cmdline_alloc(void) |
849 | 3483 { |
3484 struct cmdline_info *p; | |
3485 | |
3486 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3487 if (p != NULL) | |
3488 save_cmdline(p); | |
3489 return (char_u *)p; | |
3490 } | |
3491 | |
3492 /* | |
3493 * Restore the command line from the return value of save_cmdline_alloc(). | |
3494 */ | |
3495 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3496 restore_cmdline_alloc(char_u *p) |
849 | 3497 { |
3498 if (p != NULL) | |
3499 { | |
3500 restore_cmdline((struct cmdline_info *)p); | |
3501 vim_free(p); | |
3502 } | |
3503 } | |
3504 #endif | |
3505 | |
15 | 3506 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3507 * 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
|
3508 * Used by CTRL-R command in command-line mode. |
15 | 3509 * insert_reg() can't be used here, because special characters from the |
3510 * register contents will be interpreted as commands. | |
3511 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3512 * Return FAIL for failure, OK otherwise. |
15 | 3513 */ |
3514 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3515 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3516 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3517 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
|
3518 int remcr) /* remove trailing CR */ |
15 | 3519 { |
3520 long i; | |
3521 char_u *arg; | |
772 | 3522 char_u *p; |
15 | 3523 int allocated; |
3524 struct cmdline_info save_ccline; | |
3525 | |
3526 /* check for valid regname; also accept special characters for CTRL-R in | |
3527 * the command line */ | |
3528 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
|
3529 && 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
|
3530 && !valid_yank_reg(regname, FALSE)) |
15 | 3531 return FAIL; |
3532 | |
3533 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3534 * CTRL-C to break the loop. */ | |
3535 line_breakcheck(); | |
3536 if (got_int) | |
3537 return FAIL; | |
3538 | |
3539 #ifdef FEAT_CLIPBOARD | |
3540 regname = may_get_selection(regname); | |
3541 #endif | |
3542 | |
634 | 3543 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3544 * things like going to another buffer when evaluating an expression. */ |
95 | 3545 save_cmdline(&save_ccline); |
634 | 3546 ++textlock; |
15 | 3547 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3548 --textlock; |
95 | 3549 restore_cmdline(&save_ccline); |
15 | 3550 |
3551 if (i) | |
3552 { | |
3553 /* Got the value of a special register in "arg". */ | |
3554 if (arg == NULL) | |
3555 return FAIL; | |
772 | 3556 |
3557 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3558 * part of the word. */ | |
3559 p = arg; | |
3560 if (p_is && regname == Ctrl_W) | |
3561 { | |
3562 char_u *w; | |
3563 int len; | |
3564 | |
3565 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3566 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3567 { |
3568 #ifdef FEAT_MBYTE | |
3569 if (has_mbyte) | |
3570 { | |
3571 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3572 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3573 break; | |
3574 w -= len; | |
3575 } | |
3576 else | |
3577 #endif | |
3578 { | |
3579 if (!vim_iswordc(w[-1])) | |
3580 break; | |
3581 --w; | |
3582 } | |
3583 } | |
2937 | 3584 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3585 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3586 p += len; | |
3587 } | |
3588 | |
3589 cmdline_paste_str(p, literally); | |
15 | 3590 if (allocated) |
3591 vim_free(arg); | |
3592 return OK; | |
3593 } | |
3594 | |
1015 | 3595 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3596 } |
3597 | |
3598 /* | |
3599 * Put a string on the command line. | |
3600 * When "literally" is TRUE, insert literally. | |
3601 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3602 * line. | |
3603 */ | |
3604 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3605 cmdline_paste_str(char_u *s, int literally) |
15 | 3606 { |
3607 int c, cv; | |
3608 | |
3609 if (literally) | |
3610 put_on_cmdline(s, -1, TRUE); | |
3611 else | |
3612 while (*s != NUL) | |
3613 { | |
3614 cv = *s; | |
3615 if (cv == Ctrl_V && s[1]) | |
3616 ++s; | |
3617 #ifdef FEAT_MBYTE | |
3618 if (has_mbyte) | |
1606 | 3619 c = mb_cptr2char_adv(&s); |
15 | 3620 else |
3621 #endif | |
3622 c = *s++; | |
3628 | 3623 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3624 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3625 #ifdef UNIX |
3626 || c == intr_char | |
3627 #endif | |
3628 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3629 stuffcharReadbuff(Ctrl_V); | |
3630 stuffcharReadbuff(c); | |
3631 } | |
3632 } | |
3633 | |
7 | 3634 #ifdef FEAT_WILDMENU |
3635 /* | |
3636 * Delete characters on the command line, from "from" to the current | |
3637 * position. | |
3638 */ | |
3639 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3640 cmdline_del(int from) |
7 | 3641 { |
3642 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3643 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3644 ccline.cmdlen -= ccline.cmdpos - from; | |
3645 ccline.cmdpos = from; | |
3646 } | |
3647 #endif | |
3648 | |
3649 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3650 * 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
|
3651 * 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
|
3652 * overwritten. |
7 | 3653 */ |
3654 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3655 redrawcmdline(void) |
7 | 3656 { |
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
|
3657 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
|
3658 } |
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
|
3659 |
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
|
3660 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
|
3661 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
|
3662 { |
7 | 3663 if (cmd_silent) |
3664 return; | |
3665 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
|
3666 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
|
3667 compute_cmdrow(); |
7 | 3668 redrawcmd(); |
3669 cursorcmd(); | |
3670 } | |
3671 | |
3672 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3673 redrawcmdprompt(void) |
7 | 3674 { |
3675 int i; | |
3676 | |
3677 if (cmd_silent) | |
3678 return; | |
531 | 3679 if (ccline.cmdfirstc != NUL) |
7 | 3680 msg_putchar(ccline.cmdfirstc); |
3681 if (ccline.cmdprompt != NULL) | |
3682 { | |
3683 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3684 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3685 /* do the reverse of set_cmdspos() */ | |
531 | 3686 if (ccline.cmdfirstc != NUL) |
7 | 3687 --ccline.cmdindent; |
3688 } | |
3689 else | |
3690 for (i = ccline.cmdindent; i > 0; --i) | |
3691 msg_putchar(' '); | |
3692 } | |
3693 | |
3694 /* | |
3695 * Redraw what is currently on the command line. | |
3696 */ | |
3697 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3698 redrawcmd(void) |
7 | 3699 { |
3700 if (cmd_silent) | |
3701 return; | |
3702 | |
683 | 3703 /* when 'incsearch' is set there may be no command line while redrawing */ |
3704 if (ccline.cmdbuff == NULL) | |
3705 { | |
3706 windgoto(cmdline_row, 0); | |
3707 msg_clr_eos(); | |
3708 return; | |
3709 } | |
3710 | |
7 | 3711 msg_start(); |
3712 redrawcmdprompt(); | |
3713 | |
3714 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3715 msg_no_more = TRUE; | |
3716 draw_cmdline(0, ccline.cmdlen); | |
3717 msg_clr_eos(); | |
3718 msg_no_more = FALSE; | |
3719 | |
3720 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
|
3721 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
|
3722 putcmdline(extra_char, extra_char_shift); |
7 | 3723 |
3724 /* | |
3725 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3726 * in cmdline mode we can reset them now. | |
3727 */ | |
3728 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3729 | |
3730 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3731 * in cmdline mode */ | |
3732 skip_redraw = FALSE; | |
3733 } | |
3734 | |
3735 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3736 compute_cmdrow(void) |
7 | 3737 { |
540 | 3738 if (exmode_active || msg_scrolled != 0) |
7 | 3739 cmdline_row = Rows - 1; |
3740 else | |
3741 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
|
3742 + lastwin->w_status_height; |
7 | 3743 } |
3744 | |
3745 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3746 cursorcmd(void) |
7 | 3747 { |
3748 if (cmd_silent) | |
3749 return; | |
3750 | |
3751 #ifdef FEAT_RIGHTLEFT | |
3752 if (cmdmsg_rl) | |
3753 { | |
3754 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3755 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3756 if (msg_row <= 0) | |
3757 msg_row = Rows - 1; | |
3758 } | |
3759 else | |
3760 #endif | |
3761 { | |
3762 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3763 msg_col = ccline.cmdspos % (int)Columns; | |
3764 if (msg_row >= Rows) | |
3765 msg_row = Rows - 1; | |
3766 } | |
3767 | |
3768 windgoto(msg_row, msg_col); | |
3769 #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
|
3770 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
|
3771 redrawcmd_preedit(); |
7 | 3772 #endif |
3773 #ifdef MCH_CURSOR_SHAPE | |
3774 mch_update_cursor(); | |
3775 #endif | |
3776 } | |
3777 | |
3778 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3779 gotocmdline(int clr) |
7 | 3780 { |
3781 msg_start(); | |
3782 #ifdef FEAT_RIGHTLEFT | |
3783 if (cmdmsg_rl) | |
3784 msg_col = Columns - 1; | |
3785 else | |
3786 #endif | |
3787 msg_col = 0; /* always start in column 0 */ | |
3788 if (clr) /* clear the bottom line(s) */ | |
3789 msg_clr_eos(); /* will reset clear_cmdline */ | |
3790 windgoto(cmdline_row, 0); | |
3791 } | |
3792 | |
3793 /* | |
3794 * Check the word in front of the cursor for an abbreviation. | |
3795 * Called when the non-id character "c" has been entered. | |
3796 * When an abbreviation is recognized it is removed from the text with | |
3797 * backspaces and the replacement string is inserted, followed by "c". | |
3798 */ | |
3799 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3800 ccheck_abbr(int c) |
7 | 3801 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3802 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3803 |
7 | 3804 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3805 return FALSE; | |
3806 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3807 /* 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
|
3808 * 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
|
3809 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
|
3810 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3811 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
|
3812 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3813 && 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
|
3814 && 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
|
3815 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3816 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3817 /* 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
|
3818 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3819 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3820 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3821 } |
3822 | |
3164 | 3823 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3824 static int | |
3825 #ifdef __BORLANDC__ | |
3826 _RTLENTRYF | |
3827 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3828 sort_func_compare(const void *s1, const void *s2) |
3164 | 3829 { |
3830 char_u *p1 = *(char_u **)s1; | |
3831 char_u *p2 = *(char_u **)s2; | |
3832 | |
3833 if (*p1 != '<' && *p2 == '<') return -1; | |
3834 if (*p1 == '<' && *p2 != '<') return 1; | |
3835 return STRCMP(p1, p2); | |
3836 } | |
3837 #endif | |
3838 | |
7 | 3839 /* |
3840 * Return FAIL if this is not an appropriate context in which to do | |
3841 * completion of anything, return OK if it is (even if there are no matches). | |
3842 * For the caller, this means that the character is just passed through like a | |
3843 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3844 */ | |
3845 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3846 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3847 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3848 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3849 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3850 int escape) /* if TRUE, escape the returned matches */ |
7 | 3851 { |
3852 int i, j; | |
3853 char_u *p1; | |
3854 char_u *p2; | |
3855 int difflen; | |
3856 int v; | |
3857 | |
3858 if (xp->xp_numfiles == -1) | |
3859 { | |
3860 set_expand_context(xp); | |
3861 cmd_showtail = expand_showtail(xp); | |
3862 } | |
3863 | |
3864 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3865 { | |
3866 beep_flush(); | |
3867 return OK; /* Something illegal on command line */ | |
3868 } | |
3869 if (xp->xp_context == EXPAND_NOTHING) | |
3870 { | |
3871 /* Caller can use the character as a normal char instead */ | |
3872 return FAIL; | |
3873 } | |
3874 | |
3875 MSG_PUTS("..."); /* show that we are busy */ | |
3876 out_flush(); | |
3877 | |
3878 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3879 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3880 |
3881 if (type == WILD_NEXT || type == WILD_PREV) | |
3882 { | |
3883 /* | |
3884 * Get next/previous match for a previous expanded pattern. | |
3885 */ | |
3886 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3887 } | |
3888 else | |
3889 { | |
3890 /* | |
3891 * Translate string into pattern and expand it. | |
3892 */ | |
1965 | 3893 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3894 xp->xp_context)) == NULL) | |
7 | 3895 p2 = NULL; |
3896 else | |
3897 { | |
2652 | 3898 int use_options = options | |
3961 | 3899 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3900 if (escape) | |
3901 use_options |= WILD_ESCAPE; | |
2652 | 3902 |
3903 if (p_wic) | |
3904 use_options += WILD_ICASE; | |
1965 | 3905 p2 = ExpandOne(xp, p1, |
3906 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3907 use_options, type); |
7 | 3908 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3909 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3910 if (p2 != NULL && type == WILD_LONGEST) |
3911 { | |
1965 | 3912 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3913 if (ccline.cmdbuff[i + j] == '*' |
3914 || ccline.cmdbuff[i + j] == '?') | |
3915 break; | |
3916 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
|
3917 VIM_CLEAR(p2); |
7 | 3918 } |
3919 } | |
3920 } | |
3921 | |
3922 if (p2 != NULL && !got_int) | |
3923 { | |
1965 | 3924 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
|
3925 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3926 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3927 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3928 xp->xp_pattern = ccline.cmdbuff + i; |
3929 } | |
3930 else | |
3931 v = OK; | |
3932 if (v == OK) | |
3933 { | |
323 | 3934 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3935 &ccline.cmdbuff[ccline.cmdpos], | |
3936 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3937 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3938 ccline.cmdlen += difflen; |
3939 ccline.cmdpos += difflen; | |
3940 } | |
3941 } | |
3942 vim_free(p2); | |
3943 | |
3944 redrawcmd(); | |
33 | 3945 cursorcmd(); |
7 | 3946 |
3947 /* When expanding a ":map" command and no matches are found, assume that | |
3948 * the key is supposed to be inserted literally */ | |
3949 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3950 return FAIL; | |
3951 | |
3952 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
3953 beep_flush(); | |
3954 else if (xp->xp_numfiles == 1) | |
3955 /* free expanded pattern */ | |
3956 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
3957 | |
3958 return OK; | |
3959 } | |
3960 | |
3961 /* | |
3962 * Do wildcard expansion on the string 'str'. | |
3963 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 3964 * Return a pointer to allocated memory containing the new string. |
7 | 3965 * Return NULL for failure. |
3966 * | |
1412 | 3967 * "orig" is the originally expanded string, copied to allocated memory. It |
3968 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
3969 * WILD_PREV "orig" should be NULL. | |
3970 * | |
838 | 3971 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
3972 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 3973 * |
3974 * mode = WILD_FREE: just free previously expanded matches | |
3975 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
3976 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
3977 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
3978 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
3979 * mode = WILD_ALL: return all matches concatenated | |
3980 * mode = WILD_LONGEST: return longest matched part | |
3398 | 3981 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 3982 * |
3983 * options = WILD_LIST_NOTFOUND: list entries without a match | |
3984 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
3985 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
3986 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
3987 * options = WILD_ADD_SLASH: add a slash after directory names | |
3988 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
3989 * options = WILD_SILENT: don't print warning messages | |
3990 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 3991 * options = WILD_ICASE: ignore case for files |
7 | 3992 * |
3993 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
3994 */ | |
3995 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3996 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3997 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3998 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3999 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
|
4000 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4001 int mode) |
7 | 4002 { |
4003 char_u *ss = NULL; | |
4004 static int findex; | |
4005 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 4006 int orig_saved = FALSE; |
7 | 4007 int i; |
4008 long_u len; | |
4009 int non_suf_match; /* number without matching suffix */ | |
4010 | |
4011 /* | |
4012 * first handle the case of using an old match | |
4013 */ | |
4014 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4015 { | |
4016 if (xp->xp_numfiles > 0) | |
4017 { | |
4018 if (mode == WILD_PREV) | |
4019 { | |
4020 if (findex == -1) | |
4021 findex = xp->xp_numfiles; | |
4022 --findex; | |
4023 } | |
4024 else /* mode == WILD_NEXT */ | |
4025 ++findex; | |
4026 | |
4027 /* | |
4028 * When wrapping around, return the original string, set findex to | |
4029 * -1. | |
4030 */ | |
4031 if (findex < 0) | |
4032 { | |
4033 if (orig_save == NULL) | |
4034 findex = xp->xp_numfiles - 1; | |
4035 else | |
4036 findex = -1; | |
4037 } | |
4038 if (findex >= xp->xp_numfiles) | |
4039 { | |
4040 if (orig_save == NULL) | |
4041 findex = 0; | |
4042 else | |
4043 findex = -1; | |
4044 } | |
4045 #ifdef FEAT_WILDMENU | |
4046 if (p_wmnu) | |
4047 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4048 findex, cmd_showtail); | |
4049 #endif | |
4050 if (findex == -1) | |
4051 return vim_strsave(orig_save); | |
4052 return vim_strsave(xp->xp_files[findex]); | |
4053 } | |
4054 else | |
4055 return NULL; | |
4056 } | |
4057 | |
1412 | 4058 /* free old names */ |
7 | 4059 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4060 { | |
4061 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4062 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
|
4063 VIM_CLEAR(orig_save); |
7 | 4064 } |
4065 findex = 0; | |
4066 | |
4067 if (mode == WILD_FREE) /* only release file name */ | |
4068 return NULL; | |
4069 | |
4070 if (xp->xp_numfiles == -1) | |
4071 { | |
4072 vim_free(orig_save); | |
4073 orig_save = orig; | |
1432 | 4074 orig_saved = TRUE; |
7 | 4075 |
4076 /* | |
4077 * Do the expansion. | |
4078 */ | |
4079 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4080 options) == FAIL) | |
4081 { | |
4082 #ifdef FNAME_ILLEGAL | |
4083 /* Illegal file name has been silently skipped. But when there | |
4084 * are wildcards, the real problem is that there was no match, | |
4085 * causing the pattern to be added, which has illegal characters. | |
4086 */ | |
4087 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4088 EMSG2(_(e_nomatch2), str); | |
4089 #endif | |
4090 } | |
4091 else if (xp->xp_numfiles == 0) | |
4092 { | |
4093 if (!(options & WILD_SILENT)) | |
4094 EMSG2(_(e_nomatch2), str); | |
4095 } | |
4096 else | |
4097 { | |
4098 /* Escape the matches for use on the command line. */ | |
4099 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4100 | |
4101 /* | |
4102 * Check for matching suffixes in file names. | |
4103 */ | |
3398 | 4104 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4105 && mode != WILD_LONGEST) | |
7 | 4106 { |
4107 if (xp->xp_numfiles) | |
4108 non_suf_match = xp->xp_numfiles; | |
4109 else | |
4110 non_suf_match = 1; | |
4111 if ((xp->xp_context == EXPAND_FILES | |
4112 || xp->xp_context == EXPAND_DIRECTORIES) | |
4113 && xp->xp_numfiles > 1) | |
4114 { | |
4115 /* | |
4116 * More than one match; check suffix. | |
4117 * The files will have been sorted on matching suffix in | |
4118 * expand_wildcards, only need to check the first two. | |
4119 */ | |
4120 non_suf_match = 0; | |
4121 for (i = 0; i < 2; ++i) | |
4122 if (match_suffix(xp->xp_files[i])) | |
4123 ++non_suf_match; | |
4124 } | |
4125 if (non_suf_match != 1) | |
4126 { | |
4127 /* Can we ever get here unless it's while expanding | |
4128 * interactively? If not, we can get rid of this all | |
4129 * together. Don't really want to wait for this message | |
4130 * (and possibly have to hit return to continue!). | |
4131 */ | |
4132 if (!(options & WILD_SILENT)) | |
4133 EMSG(_(e_toomany)); | |
4134 else if (!(options & WILD_NO_BEEP)) | |
4135 beep_flush(); | |
4136 } | |
4137 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4138 ss = vim_strsave(xp->xp_files[0]); | |
4139 } | |
4140 } | |
4141 } | |
4142 | |
4143 /* Find longest common part */ | |
4144 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4145 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4146 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4147 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4148 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4149 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4150 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4151 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4152 if (has_mbyte) |
7 | 4153 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4154 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
|
4155 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
|
4156 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4157 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4158 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4159 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
|
4160 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
|
4161 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4162 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4163 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4164 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
|
4165 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4166 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4167 ci = xp->xp_files[i][len]; |
4242 | 4168 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4169 || xp->xp_context == EXPAND_FILES |
714 | 4170 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4171 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4172 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4173 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4174 break; |
4175 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4176 else if (c0 != ci) |
7 | 4177 break; |
4178 } | |
4179 if (i < xp->xp_numfiles) | |
4180 { | |
4181 if (!(options & WILD_NO_BEEP)) | |
6949 | 4182 vim_beep(BO_WILD); |
7 | 4183 break; |
4184 } | |
4185 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4186 |
7 | 4187 ss = alloc((unsigned)len + 1); |
4188 if (ss) | |
419 | 4189 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4190 findex = -1; /* next p_wc gets first one */ |
4191 } | |
4192 | |
4193 /* Concatenate all matching names */ | |
4194 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4195 { | |
4196 len = 0; | |
4197 for (i = 0; i < xp->xp_numfiles; ++i) | |
4198 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4199 ss = lalloc(len, TRUE); | |
4200 if (ss != NULL) | |
4201 { | |
4202 *ss = NUL; | |
4203 for (i = 0; i < xp->xp_numfiles; ++i) | |
4204 { | |
4205 STRCAT(ss, xp->xp_files[i]); | |
4206 if (i != xp->xp_numfiles - 1) | |
4207 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4208 } | |
4209 } | |
4210 } | |
4211 | |
4212 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4213 ExpandCleanup(xp); | |
4214 | |
1412 | 4215 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4216 if (!orig_saved) |
1412 | 4217 vim_free(orig); |
4218 | |
7 | 4219 return ss; |
4220 } | |
4221 | |
4222 /* | |
4223 * Prepare an expand structure for use. | |
4224 */ | |
4225 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4226 ExpandInit(expand_T *xp) |
7 | 4227 { |
1718 | 4228 xp->xp_pattern = NULL; |
1965 | 4229 xp->xp_pattern_len = 0; |
7 | 4230 xp->xp_backslash = XP_BS_NONE; |
632 | 4231 #ifndef BACKSLASH_IN_FILENAME |
4232 xp->xp_shell = FALSE; | |
4233 #endif | |
7 | 4234 xp->xp_numfiles = -1; |
4235 xp->xp_files = NULL; | |
632 | 4236 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4237 xp->xp_arg = NULL; | |
4238 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4239 xp->xp_line = NULL; |
7 | 4240 } |
4241 | |
4242 /* | |
4243 * Cleanup an expand structure after use. | |
4244 */ | |
4245 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4246 ExpandCleanup(expand_T *xp) |
7 | 4247 { |
4248 if (xp->xp_numfiles >= 0) | |
4249 { | |
4250 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4251 xp->xp_numfiles = -1; | |
4252 } | |
4253 } | |
4254 | |
4255 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4256 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4257 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4258 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4259 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4260 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4261 int options) |
7 | 4262 { |
4263 int i; | |
4264 char_u *p; | |
4265 | |
4266 /* | |
4267 * May change home directory back to "~" | |
4268 */ | |
4269 if (options & WILD_HOME_REPLACE) | |
4270 tilde_replace(str, numfiles, files); | |
4271 | |
4272 if (options & WILD_ESCAPE) | |
4273 { | |
4274 if (xp->xp_context == EXPAND_FILES | |
2778 | 4275 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4276 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4277 || xp->xp_context == EXPAND_BUFFERS |
4278 || xp->xp_context == EXPAND_DIRECTORIES) | |
4279 { | |
4280 /* | |
4281 * Insert a backslash into a file name before a space, \, %, # | |
4282 * and wildmatch characters, except '~'. | |
4283 */ | |
4284 for (i = 0; i < numfiles; ++i) | |
4285 { | |
4286 /* for ":set path=" we need to escape spaces twice */ | |
4287 if (xp->xp_backslash == XP_BS_THREE) | |
4288 { | |
4289 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4290 if (p != NULL) | |
4291 { | |
4292 vim_free(files[i]); | |
4293 files[i] = p; | |
719 | 4294 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4295 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4296 if (p != NULL) | |
4297 { | |
4298 vim_free(files[i]); | |
4299 files[i] = p; | |
4300 } | |
4301 #endif | |
4302 } | |
4303 } | |
1589 | 4304 #ifdef BACKSLASH_IN_FILENAME |
4305 p = vim_strsave_fnameescape(files[i], FALSE); | |
4306 #else | |
1586 | 4307 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4308 #endif |
7 | 4309 if (p != NULL) |
4310 { | |
4311 vim_free(files[i]); | |
4312 files[i] = p; | |
4313 } | |
4314 | |
4315 /* If 'str' starts with "\~", replace "~" at start of | |
4316 * files[i] with "\~". */ | |
4317 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4318 escape_fname(&files[i]); |
7 | 4319 } |
4320 xp->xp_backslash = XP_BS_NONE; | |
435 | 4321 |
4322 /* If the first file starts with a '+' escape it. Otherwise it | |
4323 * could be seen as "+cmd". */ | |
4324 if (*files[0] == '+') | |
4325 escape_fname(&files[0]); | |
7 | 4326 } |
4327 else if (xp->xp_context == EXPAND_TAGS) | |
4328 { | |
4329 /* | |
4330 * Insert a backslash before characters in a tag name that | |
4331 * would terminate the ":tag" command. | |
4332 */ | |
4333 for (i = 0; i < numfiles; ++i) | |
4334 { | |
4335 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4336 if (p != NULL) | |
4337 { | |
4338 vim_free(files[i]); | |
4339 files[i] = p; | |
4340 } | |
4341 } | |
4342 } | |
4343 } | |
4344 } | |
4345 | |
4346 /* | |
1586 | 4347 * Escape special characters in "fname" for when used as a file name argument |
4348 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4349 * Returns the result in allocated memory. | |
4350 */ | |
4351 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4352 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4353 { |
1685 | 4354 char_u *p; |
1586 | 4355 #ifdef BACKSLASH_IN_FILENAME |
4356 char_u buf[20]; | |
4357 int j = 0; | |
4358 | |
5481 | 4359 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4360 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4361 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4362 buf[j++] = *p; |
4363 buf[j] = NUL; | |
1700 | 4364 p = vim_strsave_escaped(fname, buf); |
1586 | 4365 #else |
1685 | 4366 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4367 if (shell && csh_like_shell() && p != NULL) | |
4368 { | |
4369 char_u *s; | |
4370 | |
4371 /* For csh and similar shells need to put two backslashes before '!'. | |
4372 * One is taken by Vim, one by the shell. */ | |
4373 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4374 vim_free(p); | |
4375 p = s; | |
4376 } | |
1700 | 4377 #endif |
4378 | |
4379 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4380 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4381 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4382 escape_fname(&p); |
4383 | |
1685 | 4384 return p; |
1586 | 4385 } |
4386 | |
4387 /* | |
435 | 4388 * Put a backslash before the file name in "pp", which is in allocated memory. |
4389 */ | |
4390 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4391 escape_fname(char_u **pp) |
435 | 4392 { |
4393 char_u *p; | |
4394 | |
4395 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4396 if (p != NULL) | |
4397 { | |
4398 p[0] = '\\'; | |
4399 STRCPY(p + 1, *pp); | |
4400 vim_free(*pp); | |
4401 *pp = p; | |
4402 } | |
4403 } | |
4404 | |
4405 /* | |
7 | 4406 * For each file name in files[num_files]: |
4407 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4408 */ | |
4409 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4410 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4411 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4412 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4413 char_u **files) |
7 | 4414 { |
4415 int i; | |
4416 char_u *p; | |
4417 | |
4418 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4419 { | |
4420 for (i = 0; i < num_files; ++i) | |
4421 { | |
4422 p = home_replace_save(NULL, files[i]); | |
4423 if (p != NULL) | |
4424 { | |
4425 vim_free(files[i]); | |
4426 files[i] = p; | |
4427 } | |
4428 } | |
4429 } | |
4430 } | |
4431 | |
4432 /* | |
4433 * Show all matches for completion on the command line. | |
4434 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4435 * be inserted like a normal character. | |
4436 */ | |
4437 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4438 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4439 { |
4440 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4441 int num_files; | |
4442 char_u **files_found; | |
4443 int i, j, k; | |
4444 int maxlen; | |
4445 int lines; | |
4446 int columns; | |
4447 char_u *p; | |
4448 int lastlen; | |
4449 int attr; | |
4450 int showtail; | |
4451 | |
4452 if (xp->xp_numfiles == -1) | |
4453 { | |
4454 set_expand_context(xp); | |
4455 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4456 &num_files, &files_found); | |
4457 showtail = expand_showtail(xp); | |
4458 if (i != EXPAND_OK) | |
4459 return i; | |
4460 | |
4461 } | |
4462 else | |
4463 { | |
4464 num_files = xp->xp_numfiles; | |
4465 files_found = xp->xp_files; | |
4466 showtail = cmd_showtail; | |
4467 } | |
4468 | |
4469 #ifdef FEAT_WILDMENU | |
4470 if (!wildmenu) | |
4471 { | |
4472 #endif | |
4473 msg_didany = FALSE; /* lines_left will be set */ | |
4474 msg_start(); /* prepare for paging */ | |
4475 msg_putchar('\n'); | |
4476 out_flush(); | |
4477 cmdline_row = msg_row; | |
4478 msg_didany = FALSE; /* lines_left will be set again */ | |
4479 msg_start(); /* prepare for paging */ | |
4480 #ifdef FEAT_WILDMENU | |
4481 } | |
4482 #endif | |
4483 | |
4484 if (got_int) | |
4485 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4486 #ifdef FEAT_WILDMENU | |
4487 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
|
4488 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4489 #endif |
4490 else | |
4491 { | |
4492 /* find the length of the longest file name */ | |
4493 maxlen = 0; | |
4494 for (i = 0; i < num_files; ++i) | |
4495 { | |
4496 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4497 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4498 || xp->xp_context == EXPAND_BUFFERS)) |
4499 { | |
4500 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4501 j = vim_strsize(NameBuff); | |
4502 } | |
4503 else | |
4504 j = vim_strsize(L_SHOWFILE(i)); | |
4505 if (j > maxlen) | |
4506 maxlen = j; | |
4507 } | |
4508 | |
4509 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4510 lines = num_files; | |
4511 else | |
4512 { | |
4513 /* compute the number of columns and lines for the listing */ | |
4514 maxlen += 2; /* two spaces between file names */ | |
4515 columns = ((int)Columns + 2) / maxlen; | |
4516 if (columns < 1) | |
4517 columns = 1; | |
4518 lines = (num_files + columns - 1) / columns; | |
4519 } | |
4520 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4521 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4522 |
4523 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4524 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4525 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4526 msg_clr_eos(); |
4527 msg_advance(maxlen - 3); | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4528 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4529 } |
4530 | |
4531 /* list the files line by line */ | |
4532 for (i = 0; i < lines; ++i) | |
4533 { | |
4534 lastlen = 999; | |
4535 for (k = i; k < num_files; k += lines) | |
4536 { | |
4537 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4538 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4539 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4540 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4541 msg_advance(maxlen + 1); | |
4542 msg_puts(p); | |
4543 msg_advance(maxlen + 3); | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4544 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4545 break; |
4546 } | |
4547 for (j = maxlen - lastlen; --j >= 0; ) | |
4548 msg_putchar(' '); | |
4549 if (xp->xp_context == EXPAND_FILES | |
714 | 4550 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4551 || xp->xp_context == EXPAND_BUFFERS) |
4552 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4553 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4554 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4555 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4556 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4557 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4558 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4559 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4560 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4561 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4562 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
|
4563 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4564 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4565 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4566 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4567 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4568 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4569 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4570 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4571 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4572 j = mch_isdir(files_found[k]); |
7 | 4573 if (showtail) |
4574 p = L_SHOWFILE(k); | |
4575 else | |
4576 { | |
4577 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4578 TRUE); | |
4579 p = NameBuff; | |
4580 } | |
4581 } | |
4582 else | |
4583 { | |
4584 j = FALSE; | |
4585 p = L_SHOWFILE(k); | |
4586 } | |
4587 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4588 } | |
4589 if (msg_col > 0) /* when not wrapped around */ | |
4590 { | |
4591 msg_clr_eos(); | |
4592 msg_putchar('\n'); | |
4593 } | |
4594 out_flush(); /* show one line at a time */ | |
4595 if (got_int) | |
4596 { | |
4597 got_int = FALSE; | |
4598 break; | |
4599 } | |
4600 } | |
4601 | |
4602 /* | |
4603 * we redraw the command below the lines that we have just listed | |
4604 * This is a bit tricky, but it saves a lot of screen updating. | |
4605 */ | |
4606 cmdline_row = msg_row; /* will put it back later */ | |
4607 } | |
4608 | |
4609 if (xp->xp_numfiles == -1) | |
4610 FreeWild(num_files, files_found); | |
4611 | |
4612 return EXPAND_OK; | |
4613 } | |
4614 | |
4615 /* | |
4616 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4617 * Find tail of file name path, but ignore trailing "/". | |
4618 */ | |
4619 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4620 sm_gettail(char_u *s) |
7 | 4621 { |
4622 char_u *p; | |
4623 char_u *t = s; | |
4624 int had_sep = FALSE; | |
4625 | |
4626 for (p = s; *p != NUL; ) | |
4627 { | |
4628 if (vim_ispathsep(*p) | |
4629 #ifdef BACKSLASH_IN_FILENAME | |
4630 && !rem_backslash(p) | |
4631 #endif | |
4632 ) | |
4633 had_sep = TRUE; | |
4634 else if (had_sep) | |
4635 { | |
4636 t = p; | |
4637 had_sep = FALSE; | |
4638 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4639 MB_PTR_ADV(p); |
7 | 4640 } |
4641 return t; | |
4642 } | |
4643 | |
4644 /* | |
4645 * Return TRUE if we only need to show the tail of completion matches. | |
4646 * When not completing file names or there is a wildcard in the path FALSE is | |
4647 * returned. | |
4648 */ | |
4649 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4650 expand_showtail(expand_T *xp) |
7 | 4651 { |
4652 char_u *s; | |
4653 char_u *end; | |
4654 | |
4655 /* When not completing file names a "/" may mean something different. */ | |
714 | 4656 if (xp->xp_context != EXPAND_FILES |
4657 && xp->xp_context != EXPAND_SHELLCMD | |
4658 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4659 return FALSE; |
4660 | |
4661 end = gettail(xp->xp_pattern); | |
4662 if (end == xp->xp_pattern) /* there is no path separator */ | |
4663 return FALSE; | |
4664 | |
4665 for (s = xp->xp_pattern; s < end; s++) | |
4666 { | |
4667 /* Skip escaped wildcards. Only when the backslash is not a path | |
4668 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4669 if (rem_backslash(s)) | |
4670 ++s; | |
4671 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4672 return FALSE; | |
4673 } | |
4674 return TRUE; | |
4675 } | |
4676 | |
4677 /* | |
4678 * Prepare a string for expansion. | |
4679 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4680 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4681 * When expanding other names: The string will be used with regcomp(). Copy |
4682 * the name into allocated memory and prepend "^". | |
4683 */ | |
4684 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4685 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4686 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4687 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4688 int context) /* EXPAND_FILES etc. */ |
7 | 4689 { |
4690 char_u *retval; | |
4691 int i, j; | |
4692 int new_len; | |
4693 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4694 int ends_in_star; |
7 | 4695 |
714 | 4696 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4697 && context != EXPAND_FILES_IN_PATH |
714 | 4698 && context != EXPAND_SHELLCMD |
4699 && context != EXPAND_DIRECTORIES) | |
7 | 4700 { |
4701 /* | |
4702 * Matching will be done internally (on something other than files). | |
4703 * So we convert the file-matching-type wildcards into our kind for | |
4704 * use with vim_regcomp(). First work out how long it will be: | |
4705 */ | |
4706 | |
4707 /* For help tags the translation is done in find_help_tags(). | |
4708 * For a tag pattern starting with "/" no translation is needed. */ | |
4709 if (context == EXPAND_HELP | |
4710 || context == EXPAND_COLORS | |
4711 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4712 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4713 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4714 || 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
|
4715 || ((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
|
4716 || 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
|
4717 && fname[0] == '/')) |
7 | 4718 retval = vim_strnsave(fname, len); |
4719 else | |
4720 { | |
4721 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4722 for (i = 0; i < len; i++) | |
4723 { | |
4724 if (fname[i] == '*' || fname[i] == '~') | |
4725 new_len++; /* '*' needs to be replaced by ".*" | |
4726 '~' needs to be replaced by "\~" */ | |
4727 | |
4728 /* Buffer names are like file names. "." should be literal */ | |
4729 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4730 new_len++; /* "." becomes "\." */ | |
4731 | |
4732 /* Custom expansion takes care of special things, match | |
4733 * backslashes literally (perhaps also for other types?) */ | |
634 | 4734 if ((context == EXPAND_USER_DEFINED |
4735 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4736 new_len++; /* '\' becomes "\\" */ |
4737 } | |
4738 retval = alloc(new_len); | |
4739 if (retval != NULL) | |
4740 { | |
4741 retval[0] = '^'; | |
4742 j = 1; | |
4743 for (i = 0; i < len; i++, j++) | |
4744 { | |
4745 /* Skip backslash. But why? At least keep it for custom | |
4746 * expansion. */ | |
4747 if (context != EXPAND_USER_DEFINED | |
407 | 4748 && context != EXPAND_USER_LIST |
4749 && fname[i] == '\\' | |
4750 && ++i == len) | |
7 | 4751 break; |
4752 | |
4753 switch (fname[i]) | |
4754 { | |
4755 case '*': retval[j++] = '.'; | |
4756 break; | |
4757 case '~': retval[j++] = '\\'; | |
4758 break; | |
4759 case '?': retval[j] = '.'; | |
4760 continue; | |
4761 case '.': if (context == EXPAND_BUFFERS) | |
4762 retval[j++] = '\\'; | |
4763 break; | |
407 | 4764 case '\\': if (context == EXPAND_USER_DEFINED |
4765 || context == EXPAND_USER_LIST) | |
7 | 4766 retval[j++] = '\\'; |
4767 break; | |
4768 } | |
4769 retval[j] = fname[i]; | |
4770 } | |
4771 retval[j] = NUL; | |
4772 } | |
4773 } | |
4774 } | |
4775 else | |
4776 { | |
4777 retval = alloc(len + 4); | |
4778 if (retval != NULL) | |
4779 { | |
419 | 4780 vim_strncpy(retval, fname, len); |
7 | 4781 |
4782 /* | |
831 | 4783 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4784 * * would become **, which walks the whole tree. | |
7 | 4785 * ~ would be at the start of the file name, but not the tail. |
4786 * $ could be anywhere in the tail. | |
4787 * ` could be anywhere in the file name. | |
1484 | 4788 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4789 */ |
4790 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4791 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
|
4792 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4793 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4794 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4795 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4796 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4797 ends_in_star = !ends_in_star; |
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 #endif |
7 | 4800 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4801 && !ends_in_star |
7 | 4802 && vim_strchr(tail, '$') == NULL |
4803 && vim_strchr(retval, '`') == NULL) | |
4804 retval[len++] = '*'; | |
1484 | 4805 else if (len > 0 && retval[len - 1] == '$') |
4806 --len; | |
7 | 4807 retval[len] = NUL; |
4808 } | |
4809 } | |
4810 return retval; | |
4811 } | |
4812 | |
4813 /* | |
4814 * Must parse the command line so far to work out what context we are in. | |
4815 * Completion can then be done based on that context. | |
4816 * This routine sets the variables: | |
4817 * xp->xp_pattern The start of the pattern to be expanded within | |
4818 * the command line (ends at the cursor). | |
4819 * xp->xp_context The type of thing to expand. Will be one of: | |
4820 * | |
4821 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4822 * the command line, like an unknown command. Caller | |
4823 * should beep. | |
4824 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4825 * a normal char, rather than for completion. eg | |
4826 * :s/^I/ | |
4827 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4828 * it. | |
4829 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4830 * EXPAND_FILES After command with XFILE set, or after setting | |
4831 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4832 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4833 * when we know only directories are of interest. eg | |
4834 * :set dir=^I | |
714 | 4835 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4836 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4837 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4838 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4839 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4840 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4841 * EXPAND_EVENTS Complete event names | |
4842 * EXPAND_SYNTAX Complete :syntax command arguments | |
4843 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4844 * EXPAND_AUGROUP Complete autocommand group names | |
4845 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4846 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4847 * eg :unmap a^I , :cunab x^I | |
4848 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4849 * eg :call sub^I | |
4850 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4851 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4852 * names in expressions, eg :while s^I | |
4853 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4854 * EXPAND_USER Complete user names |
7 | 4855 */ |
4856 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4857 set_expand_context(expand_T *xp) |
7 | 4858 { |
168 | 4859 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4860 if (ccline.cmdfirstc != ':' |
4861 #ifdef FEAT_EVAL | |
168 | 4862 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4863 && !ccline.input_fn |
7 | 4864 #endif |
4865 ) | |
4866 { | |
4867 xp->xp_context = EXPAND_NOTHING; | |
4868 return; | |
4869 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4870 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4871 } |
4872 | |
4873 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4874 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4875 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4876 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
|
4877 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
|
4878 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4879 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4880 { |
4881 int old_char = NUL; | |
4882 char_u *nextcomm; | |
4883 | |
4884 /* | |
4885 * Avoid a UMR warning from Purify, only save the character if it has been | |
4886 * written before. | |
4887 */ | |
4888 if (col < len) | |
4889 old_char = str[col]; | |
4890 str[col] = NUL; | |
4891 nextcomm = str; | |
168 | 4892 |
4893 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4894 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4895 { |
4896 # ifdef FEAT_CMDL_COMPL | |
168 | 4897 /* pass CMD_SIZE because there is no real command */ |
4898 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4899 # endif |
4900 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4901 else if (use_ccline && ccline.input_fn) |
531 | 4902 { |
4903 xp->xp_context = ccline.xp_context; | |
4904 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4905 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4906 xp->xp_arg = ccline.xp_arg; |
1322 | 4907 # endif |
531 | 4908 } |
168 | 4909 else |
4910 #endif | |
4911 while (nextcomm != NULL) | |
4912 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4913 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4914 /* 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
|
4915 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4916 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4917 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4918 |
7 | 4919 str[col] = old_char; |
4920 } | |
4921 | |
4922 /* | |
4923 * Expand the command line "str" from context "xp". | |
4924 * "xp" must have been set by set_cmd_context(). | |
4925 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4926 * starts. | |
4927 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4928 * cursor. | |
4929 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4930 * key that triggered expansion literally. | |
4931 * Returns EXPAND_OK otherwise. | |
4932 */ | |
4933 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4934 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4935 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4936 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
|
4937 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4938 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4939 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4940 { |
4941 char_u *file_str = NULL; | |
2652 | 4942 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4943 |
4944 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4945 { | |
4946 beep_flush(); | |
4947 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4948 } | |
4949 if (xp->xp_context == EXPAND_NOTHING) | |
4950 { | |
4951 /* Caller can use the character as a normal char instead */ | |
4952 return EXPAND_NOTHING; | |
4953 } | |
4954 | |
4955 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 4956 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
4957 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 4958 if (file_str == NULL) |
4959 return EXPAND_UNSUCCESSFUL; | |
4960 | |
2652 | 4961 if (p_wic) |
4962 options += WILD_ICASE; | |
4963 | |
7 | 4964 /* find all files that match the description */ |
2652 | 4965 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 4966 { |
4967 *matchcount = 0; | |
4968 *matches = NULL; | |
4969 } | |
4970 vim_free(file_str); | |
4971 | |
4972 return EXPAND_OK; | |
4973 } | |
4974 | |
4975 #ifdef FEAT_MULTI_LANG | |
4976 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4977 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4978 * 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
|
4979 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 4980 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
4981 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 4982 |
4983 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4984 cleanup_help_tags(int num_file, char_u **file) |
7 | 4985 { |
4986 int i, j; | |
4987 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4988 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4989 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4990 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4991 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
|
4992 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4993 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4994 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4995 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4996 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4997 *p = NUL; |
7 | 4998 |
4999 for (i = 0; i < num_file; ++i) | |
5000 { | |
5001 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
|
5002 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
5003 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5004 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 5005 { |
5006 /* Sorting on priority means the same item in another language may | |
5007 * be anywhere. Search all items for a match up to the "@en". */ | |
5008 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
|
5009 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
|
5010 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5011 break; |
5012 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5013 /* item only exists with @en, remove it */ |
7 | 5014 file[i][len] = NUL; |
5015 } | |
5016 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5017 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5018 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5019 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
|
5020 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5021 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5022 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5023 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5024 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
|
5025 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5026 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5027 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5028 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5029 } |
7 | 5030 } |
5031 #endif | |
5032 | |
5033 /* | |
5034 * Do the expansion based on xp->xp_context and "pat". | |
5035 */ | |
5036 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5037 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5038 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5039 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5040 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5041 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5042 int options) /* EW_ flags */ |
7 | 5043 { |
5044 #ifdef FEAT_CMDL_COMPL | |
5045 regmatch_T regmatch; | |
5046 #endif | |
5047 int ret; | |
5048 int flags; | |
5049 | |
5050 flags = EW_DIR; /* include directories */ | |
5051 if (options & WILD_LIST_NOTFOUND) | |
5052 flags |= EW_NOTFOUND; | |
5053 if (options & WILD_ADD_SLASH) | |
5054 flags |= EW_ADDSLASH; | |
5055 if (options & WILD_KEEP_ALL) | |
5056 flags |= EW_KEEPALL; | |
5057 if (options & WILD_SILENT) | |
5058 flags |= EW_SILENT; | |
6659 | 5059 if (options & WILD_ALLLINKS) |
5060 flags |= EW_ALLLINKS; | |
7 | 5061 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5062 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5063 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5064 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5065 { |
5066 /* | |
5067 * Expand file or directory names. | |
5068 */ | |
5069 int free_pat = FALSE; | |
5070 int i; | |
5071 | |
5072 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5073 * space */ | |
5074 if (xp->xp_backslash != XP_BS_NONE) | |
5075 { | |
5076 free_pat = TRUE; | |
5077 pat = vim_strsave(pat); | |
5078 for (i = 0; pat[i]; ++i) | |
5079 if (pat[i] == '\\') | |
5080 { | |
5081 if (xp->xp_backslash == XP_BS_THREE | |
5082 && pat[i + 1] == '\\' | |
5083 && pat[i + 2] == '\\' | |
5084 && pat[i + 3] == ' ') | |
1621 | 5085 STRMOVE(pat + i, pat + i + 3); |
7 | 5086 if (xp->xp_backslash == XP_BS_ONE |
5087 && pat[i + 1] == ' ') | |
1621 | 5088 STRMOVE(pat + i, pat + i + 1); |
7 | 5089 } |
5090 } | |
5091 | |
5092 if (xp->xp_context == EXPAND_FILES) | |
5093 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5094 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
|
5095 flags |= (EW_FILE | EW_PATH); |
7 | 5096 else |
5097 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5098 if (options & WILD_ICASE) |
5099 flags |= EW_ICASE; | |
5100 | |
2016 | 5101 /* Expand wildcards, supporting %:h and the like. */ |
5102 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5103 if (free_pat) |
5104 vim_free(pat); | |
5105 return ret; | |
5106 } | |
5107 | |
5108 *file = (char_u **)""; | |
5109 *num_file = 0; | |
5110 if (xp->xp_context == EXPAND_HELP) | |
5111 { | |
1696 | 5112 /* With an empty argument we would get all the help tags, which is |
5113 * very slow. Get matches for "help" instead. */ | |
5114 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5115 num_file, file, FALSE) == OK) | |
7 | 5116 { |
5117 #ifdef FEAT_MULTI_LANG | |
5118 cleanup_help_tags(*num_file, *file); | |
5119 #endif | |
5120 return OK; | |
5121 } | |
5122 return FAIL; | |
5123 } | |
5124 | |
5125 #ifndef FEAT_CMDL_COMPL | |
5126 return FAIL; | |
5127 #else | |
716 | 5128 if (xp->xp_context == EXPAND_SHELLCMD) |
5129 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5130 if (xp->xp_context == EXPAND_OLD_SETTING) |
5131 return ExpandOldSetting(num_file, file); | |
5132 if (xp->xp_context == EXPAND_BUFFERS) | |
5133 return ExpandBufnames(pat, num_file, file, options); | |
5134 if (xp->xp_context == EXPAND_TAGS | |
5135 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5136 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5137 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5138 { |
5139 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5140 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
|
5141 directories); |
2929 | 5142 } |
7 | 5143 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5144 { |
3106 | 5145 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5146 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5147 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5148 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5149 { |
5150 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5151 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5152 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5153 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5154 { |
5155 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
|
5156 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5157 } |
407 | 5158 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5159 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5160 return ExpandUserList(xp, num_file, file); |
407 | 5161 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5162 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5163 return ExpandPackAddDir(pat, num_file, file); |
7 | 5164 |
5165 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5166 if (regmatch.regprog == NULL) | |
5167 return FAIL; | |
5168 | |
5169 /* set ignore-case according to p_ic, p_scs and pat */ | |
5170 regmatch.rm_ic = ignorecase(pat); | |
5171 | |
5172 if (xp->xp_context == EXPAND_SETTINGS | |
5173 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5174 ret = ExpandSettings(xp, ®match, num_file, file); | |
5175 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5176 ret = ExpandMappings(®match, num_file, file); | |
5177 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5178 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5179 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5180 # endif | |
5181 else | |
5182 { | |
5183 static struct expgen | |
5184 { | |
5185 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5186 char_u *((*func)(expand_T *, int)); |
7 | 5187 int ic; |
2849 | 5188 int escaped; |
7 | 5189 } tab[] = |
5190 { | |
2849 | 5191 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5192 {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
|
5193 {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
|
5194 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5195 #ifdef FEAT_CMDHIST |
5196 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5197 #endif | |
7 | 5198 #ifdef FEAT_USR_CMDS |
2849 | 5199 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5200 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5201 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5202 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5203 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5204 #endif |
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 |
7 | 5233 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5234 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5235 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5236 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5237 #endif | |
5238 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5239 {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
|
5240 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5241 }; |
5242 int i; | |
5243 | |
5244 /* | |
5245 * Find a context in the table and call the ExpandGeneric() with the | |
5246 * right function to do the expansion. | |
5247 */ | |
5248 ret = FAIL; | |
1880 | 5249 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5250 if (xp->xp_context == tab[i].context) |
5251 { | |
5252 if (tab[i].ic) | |
5253 regmatch.rm_ic = TRUE; | |
2849 | 5254 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5255 tab[i].func, tab[i].escaped); |
7 | 5256 break; |
5257 } | |
5258 } | |
5259 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5260 vim_regfree(regmatch.regprog); |
7 | 5261 |
5262 return ret; | |
5263 #endif /* FEAT_CMDL_COMPL */ | |
5264 } | |
5265 | |
5266 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5267 /* | |
5268 * Expand a list of names. | |
5269 * | |
5270 * Generic function for command line completion. It calls a function to | |
5271 * obtain strings, one by one. The strings are matched against a regexp | |
5272 * program. Matching strings are copied into an array, which is returned. | |
5273 * | |
5274 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5275 */ | |
5276 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5277 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5278 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5279 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5280 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5281 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5282 char_u *((*func)(expand_T *, int)), |
7 | 5283 /* 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
|
5284 int escaped) |
7 | 5285 { |
5286 int i; | |
5287 int count = 0; | |
480 | 5288 int round; |
7 | 5289 char_u *str; |
5290 | |
5291 /* do this loop twice: | |
480 | 5292 * round == 0: count the number of matching names |
5293 * round == 1: copy the matching names into allocated memory | |
7 | 5294 */ |
480 | 5295 for (round = 0; round <= 1; ++round) |
7 | 5296 { |
5297 for (i = 0; ; ++i) | |
5298 { | |
5299 str = (*func)(xp, i); | |
5300 if (str == NULL) /* end of list */ | |
5301 break; | |
5302 if (*str == NUL) /* skip empty strings */ | |
5303 continue; | |
5304 | |
5305 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5306 { | |
480 | 5307 if (round) |
7 | 5308 { |
2849 | 5309 if (escaped) |
5310 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5311 else | |
5312 str = vim_strsave(str); | |
7 | 5313 (*file)[count] = str; |
5314 #ifdef FEAT_MENU | |
5315 if (func == get_menu_names && str != NULL) | |
5316 { | |
5317 /* test for separator added by get_menu_names() */ | |
5318 str += STRLEN(str) - 1; | |
5319 if (*str == '\001') | |
5320 *str = '.'; | |
5321 } | |
5322 #endif | |
5323 } | |
5324 ++count; | |
5325 } | |
5326 } | |
480 | 5327 if (round == 0) |
7 | 5328 { |
5329 if (count == 0) | |
5330 return OK; | |
5331 *num_file = count; | |
5332 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5333 if (*file == NULL) | |
5334 { | |
5335 *file = (char_u **)""; | |
5336 return FAIL; | |
5337 } | |
5338 count = 0; | |
5339 } | |
5340 } | |
480 | 5341 |
828 | 5342 /* Sort the results. Keep menu's in the specified order. */ |
5343 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5344 { |
5345 if (xp->xp_context == EXPAND_EXPRESSION | |
5346 || xp->xp_context == EXPAND_FUNCTIONS | |
5347 || xp->xp_context == EXPAND_USER_FUNC) | |
5348 /* <SNR> functions should be sorted to the end. */ | |
5349 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5350 sort_func_compare); | |
5351 else | |
5352 sort_strings(*file, *num_file); | |
5353 } | |
480 | 5354 |
1322 | 5355 #ifdef FEAT_CMDL_COMPL |
5356 /* Reset the variables used for special highlight names expansion, so that | |
5357 * they don't show up when getting normal highlight names by ID. */ | |
5358 reset_expand_highlight(); | |
5359 #endif | |
5360 | |
7 | 5361 return OK; |
5362 } | |
5363 | |
716 | 5364 /* |
5365 * Complete a shell command. | |
5366 * Returns FAIL or OK; | |
5367 */ | |
5368 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5369 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5370 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
|
5371 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
|
5372 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
|
5373 int flagsarg) /* EW_ flags */ |
716 | 5374 { |
5375 char_u *pat; | |
5376 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5377 char_u *path = NULL; |
716 | 5378 int mustfree = FALSE; |
5379 garray_T ga; | |
5380 char_u *buf = alloc(MAXPATHL); | |
5381 size_t l; | |
5382 char_u *s, *e; | |
5383 int flags = flagsarg; | |
5384 int ret; | |
6695 | 5385 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5386 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5387 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5388 hash_T hash; |
716 | 5389 |
5390 if (buf == NULL) | |
5391 return FAIL; | |
5392 | |
5393 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5394 * space */ | |
5395 pat = vim_strsave(filepat); | |
5396 for (i = 0; pat[i]; ++i) | |
5397 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5398 STRMOVE(pat + i, pat + i + 1); |
716 | 5399 |
6695 | 5400 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5401 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5402 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
|
5403 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5404 path = (char_u *)"."; |
5405 else | |
2630 | 5406 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5407 /* 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
|
5408 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5409 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5410 if (path == NULL) |
5411 path = (char_u *)""; | |
5412 } | |
716 | 5413 |
5414 /* | |
5415 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5416 * collect them in "ga". When "." is not in $PATH also expand for the |
5417 * current directory, to find "subdir/cmd". | |
716 | 5418 */ |
5419 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
|
5420 hash_init(&found_ht); |
6695 | 5421 for (s = path; ; s = e) |
716 | 5422 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5423 #if defined(MSWIN) |
716 | 5424 e = vim_strchr(s, ';'); |
5425 #else | |
5426 e = vim_strchr(s, ':'); | |
5427 #endif | |
5428 if (e == NULL) | |
5429 e = s + STRLEN(s); | |
5430 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5431 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
|
5432 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5433 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
|
5434 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5435 // 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
|
5436 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
|
5437 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
|
5438 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5439 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
|
5440 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5441 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
|
5442 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
|
5443 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5444 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5445 // 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
|
5446 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
|
5447 |
716 | 5448 l = e - s; |
5449 if (l > MAXPATHL - 5) | |
5450 break; | |
5451 vim_strncpy(buf, s, l); | |
5452 add_pathsep(buf); | |
5453 l = STRLEN(buf); | |
5454 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5455 | |
5456 /* Expand matches in one directory of $PATH. */ | |
5457 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5458 if (ret == OK) | |
5459 { | |
5460 if (ga_grow(&ga, *num_file) == FAIL) | |
5461 FreeWild(*num_file, *file); | |
5462 else | |
5463 { | |
5464 for (i = 0; i < *num_file; ++i) | |
5465 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5466 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5467 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5468 if (STRLEN(name) > l) |
716 | 5469 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5470 // 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
|
5471 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5472 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
|
5473 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5474 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5475 // 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
|
5476 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5477 ((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
|
5478 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
|
5479 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5480 } |
716 | 5481 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5482 vim_free(name); |
716 | 5483 } |
5484 vim_free(*file); | |
5485 } | |
5486 } | |
5487 if (*e != NUL) | |
5488 ++e; | |
5489 } | |
5490 *file = ga.ga_data; | |
5491 *num_file = ga.ga_len; | |
5492 | |
5493 vim_free(buf); | |
5494 vim_free(pat); | |
5495 if (mustfree) | |
5496 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5497 hash_clear(&found_ht); |
716 | 5498 return OK; |
5499 } | |
5500 | |
5501 | |
7 | 5502 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5503 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5504 * 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
|
5505 * return the result (either a string or a List). |
7 | 5506 */ |
407 | 5507 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5508 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
|
5509 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
|
5510 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5511 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5512 char_u ***file) |
7 | 5513 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5514 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
|
5515 typval_T args[4]; |
7 | 5516 int save_current_SID = current_SID; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5517 char_u *pat = NULL; |
407 | 5518 void *ret; |
13 | 5519 struct cmdline_info save_ccline; |
7 | 5520 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5521 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5522 return NULL; |
7 | 5523 *num_file = 0; |
5524 *file = NULL; | |
5525 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5526 if (ccline.cmdbuff != NULL) |
1518 | 5527 { |
5528 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5529 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5530 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5531 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5532 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
|
5533 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5534 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
|
5535 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
|
5536 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
|
5537 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
|
5538 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
|
5539 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
|
5540 args[3].v_type = VAR_UNKNOWN; |
7 | 5541 |
13 | 5542 /* Save the cmdline, we don't know what the function may do. */ |
5543 save_ccline = ccline; | |
5544 ccline.cmdbuff = NULL; | |
5545 ccline.cmdprompt = NULL; | |
7 | 5546 current_SID = xp->xp_scriptID; |
13 | 5547 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5548 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5549 |
5550 ccline = save_ccline; | |
7 | 5551 current_SID = save_current_SID; |
1518 | 5552 if (ccline.cmdbuff != NULL) |
5553 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5554 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5555 vim_free(pat); |
407 | 5556 return ret; |
5557 } | |
5558 | |
5559 /* | |
5560 * Expand names with a function defined by the user. | |
5561 */ | |
5562 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5563 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5564 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5565 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5566 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5567 char_u ***file) |
407 | 5568 { |
5569 char_u *retstr; | |
5570 char_u *s; | |
5571 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
|
5572 int keep; |
407 | 5573 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
|
5574 int skip; |
407 | 5575 |
5576 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5577 if (retstr == NULL) | |
7 | 5578 return FAIL; |
5579 | |
5580 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5581 for (s = retstr; *s != NUL; s = e) |
7 | 5582 { |
5583 e = vim_strchr(s, '\n'); | |
5584 if (e == NULL) | |
5585 e = s + STRLEN(s); | |
5586 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
|
5587 *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
|
5588 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5589 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
|
5590 *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
|
5591 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5592 if (!skip) |
7 | 5593 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5594 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
|
5595 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5596 ((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
|
5597 ++ga.ga_len; |
7 | 5598 } |
5599 | |
5600 if (*e != NUL) | |
5601 ++e; | |
5602 } | |
407 | 5603 vim_free(retstr); |
5604 *file = ga.ga_data; | |
5605 *num_file = ga.ga_len; | |
5606 return OK; | |
5607 } | |
5608 | |
5609 /* | |
5610 * Expand names with a list returned by a function defined by the user. | |
5611 */ | |
5612 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5613 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5614 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5615 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5616 char_u ***file) |
407 | 5617 { |
5618 list_T *retlist; | |
5619 listitem_T *li; | |
5620 garray_T ga; | |
5621 | |
5622 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5623 if (retlist == NULL) | |
5624 return FAIL; | |
5625 | |
5626 ga_init2(&ga, (int)sizeof(char *), 3); | |
5627 /* Loop over the items in the list. */ | |
5628 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5629 { | |
1917 | 5630 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5631 continue; /* Skip non-string items and empty strings */ | |
407 | 5632 |
5633 if (ga_grow(&ga, 1) == FAIL) | |
5634 break; | |
5635 | |
5636 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5637 vim_strsave(li->li_tv.vval.v_string); |
407 | 5638 ++ga.ga_len; |
5639 } | |
5640 list_unref(retlist); | |
5641 | |
7 | 5642 *file = ga.ga_data; |
5643 *num_file = ga.ga_len; | |
5644 return OK; | |
5645 } | |
5646 #endif | |
5647 | |
5648 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5649 * 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
|
5650 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5651 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5652 * 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
|
5653 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5654 * 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
|
5655 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5656 * "dirnames" is an array with one or more directory names. |
7 | 5657 */ |
5658 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5659 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5660 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5661 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5662 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5663 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5664 char *dirnames[]) |
7 | 5665 { |
5666 char_u *s; | |
5667 char_u *e; | |
5873 | 5668 char_u *match; |
7 | 5669 garray_T ga; |
2929 | 5670 int i; |
5671 int pat_len; | |
7 | 5672 |
5673 *num_file = 0; | |
5674 *file = NULL; | |
2931 | 5675 pat_len = (int)STRLEN(pat); |
2929 | 5676 ga_init2(&ga, (int)sizeof(char *), 10); |
5677 | |
5678 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5679 { |
2929 | 5680 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5681 if (s == NULL) | |
5682 { | |
5683 ga_clear_strings(&ga); | |
5684 return FAIL; | |
5685 } | |
5686 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5687 globpath(p_rtp, s, &ga, 0); |
2929 | 5688 vim_free(s); |
5873 | 5689 } |
5690 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5691 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5692 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
|
5693 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5694 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 22)); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5695 if (s == NULL) |
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 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5698 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5699 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5700 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
|
5701 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5702 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5703 } |
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 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5706 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5707 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
|
5708 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5709 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 20)); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5710 if (s == NULL) |
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 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5713 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5714 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5715 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
|
5716 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5717 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5718 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5719 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5720 |
5873 | 5721 for (i = 0; i < ga.ga_len; ++i) |
5722 { | |
5723 match = ((char_u **)ga.ga_data)[i]; | |
5724 s = match; | |
5725 e = s + STRLEN(s); | |
5726 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5727 { |
5873 | 5728 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5729 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5730 if (s < match || vim_ispathsep(*s)) |
5731 break; | |
5732 ++s; | |
5733 *e = NUL; | |
5734 mch_memmove(match, s, e - s + 1); | |
7 | 5735 } |
5736 } | |
5873 | 5737 |
2929 | 5738 if (ga.ga_len == 0) |
3628 | 5739 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5740 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5741 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5742 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5743 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5744 |
7 | 5745 *file = ga.ga_data; |
5746 *num_file = ga.ga_len; | |
5747 return OK; | |
5748 } | |
5749 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5750 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5751 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5752 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5753 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5754 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5755 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5756 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5757 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5758 char_u ***file) |
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 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5761 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5762 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5763 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5764 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5765 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5766 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5767 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5768 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5769 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5770 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
|
5771 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5772 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5773 if (s == NULL) |
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 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5776 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5777 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5778 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
|
5779 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5780 vim_free(s); |
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 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
|
5783 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5784 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
|
5785 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5786 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5787 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
|
5788 } |
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 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5791 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5792 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5793 /* 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
|
5794 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5795 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5796 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5797 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5798 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5799 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5800 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5801 |
7 | 5802 #endif |
5803 | |
5804 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5805 /* | |
5806 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5807 * Adds the matches to "ga". Caller must init "ga". |
7 | 5808 */ |
5873 | 5809 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5810 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5811 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5812 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5813 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5814 int expand_options) |
7 | 5815 { |
5816 expand_T xpc; | |
5817 char_u *buf; | |
5818 int i; | |
5819 int num_p; | |
5820 char_u **p; | |
5821 | |
5822 buf = alloc(MAXPATHL); | |
5823 if (buf == NULL) | |
5873 | 5824 return; |
7 | 5825 |
632 | 5826 ExpandInit(&xpc); |
7 | 5827 xpc.xp_context = EXPAND_FILES; |
632 | 5828 |
7 | 5829 /* Loop over all entries in {path}. */ |
5830 while (*path != NUL) | |
5831 { | |
5832 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5833 copy_option_part(&path, buf, MAXPATHL, ","); | |
5834 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5835 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5836 # 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
|
5837 /* 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
|
5838 * 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
|
5839 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
|
5840 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5841 # else |
7 | 5842 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
|
5843 # endif |
7 | 5844 STRCAT(buf, file); |
1754 | 5845 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5846 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5847 { |
1754 | 5848 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5849 |
5850 if (ga_grow(ga, num_p) == OK) | |
7 | 5851 { |
5852 for (i = 0; i < num_p; ++i) | |
5853 { | |
5873 | 5854 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5855 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5856 ++ga->ga_len; |
7 | 5857 } |
5858 } | |
5873 | 5859 |
7 | 5860 FreeWild(num_p, p); |
5861 } | |
5862 } | |
5863 } | |
5864 | |
5865 vim_free(buf); | |
5866 } | |
5867 | |
5868 #endif | |
5869 | |
5870 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5871 | |
5872 /********************************* | |
5873 * Command line history stuff * | |
5874 *********************************/ | |
5875 | |
5876 /* | |
5877 * Translate a history character to the associated type number. | |
5878 */ | |
5879 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5880 hist_char2type(int c) |
7 | 5881 { |
5882 if (c == ':') | |
5883 return HIST_CMD; | |
5884 if (c == '=') | |
5885 return HIST_EXPR; | |
5886 if (c == '@') | |
5887 return HIST_INPUT; | |
5888 if (c == '>') | |
5889 return HIST_DEBUG; | |
5890 return HIST_SEARCH; /* must be '?' or '/' */ | |
5891 } | |
5892 | |
5893 /* | |
5894 * Table of history names. | |
5895 * These names are used in :history and various hist...() functions. | |
5896 * It is sufficient to give the significant prefix of a history name. | |
5897 */ | |
5898 | |
5899 static char *(history_names[]) = | |
5900 { | |
5901 "cmd", | |
5902 "search", | |
5903 "expr", | |
5904 "input", | |
5905 "debug", | |
5906 NULL | |
5907 }; | |
5908 | |
3503 | 5909 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5910 /* | |
5911 * Function given to ExpandGeneric() to obtain the possible first | |
5912 * arguments of the ":history command. | |
5913 */ | |
5914 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5915 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5916 { |
5917 static char_u compl[2] = { NUL, NUL }; | |
5918 char *short_names = ":=@>?/"; | |
3529 | 5919 int short_names_count = (int)STRLEN(short_names); |
3503 | 5920 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5921 | |
5922 if (idx < short_names_count) | |
5923 { | |
5924 compl[0] = (char_u)short_names[idx]; | |
5925 return compl; | |
5926 } | |
5927 if (idx < short_names_count + history_name_count) | |
5928 return (char_u *)history_names[idx - short_names_count]; | |
5929 if (idx == short_names_count + history_name_count) | |
5930 return (char_u *)"all"; | |
5931 return NULL; | |
5932 } | |
5933 #endif | |
5934 | |
7 | 5935 /* |
5936 * init_history() - Initialize the command line history. | |
5937 * Also used to re-allocate the history when the size changes. | |
5938 */ | |
356 | 5939 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5940 init_history(void) |
7 | 5941 { |
5942 int newlen; /* new length of history table */ | |
5943 histentry_T *temp; | |
5944 int i; | |
5945 int j; | |
5946 int type; | |
5947 | |
5948 /* | |
5949 * If size of history table changed, reallocate it | |
5950 */ | |
5951 newlen = (int)p_hi; | |
5952 if (newlen != hislen) /* history length changed */ | |
5953 { | |
5954 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
5955 { | |
5956 if (newlen) | |
5957 { | |
5958 temp = (histentry_T *)lalloc( | |
5959 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
5960 if (temp == NULL) /* out of memory! */ | |
5961 { | |
5962 if (type == 0) /* first one: just keep the old length */ | |
5963 { | |
5964 newlen = hislen; | |
5965 break; | |
5966 } | |
5967 /* Already changed one table, now we can only have zero | |
5968 * length for all tables. */ | |
5969 newlen = 0; | |
5970 type = -1; | |
5971 continue; | |
5972 } | |
5973 } | |
5974 else | |
5975 temp = NULL; | |
5976 if (newlen == 0 || temp != NULL) | |
5977 { | |
5978 if (hisidx[type] < 0) /* there are no entries yet */ | |
5979 { | |
5980 for (i = 0; i < newlen; ++i) | |
4258 | 5981 clear_hist_entry(&temp[i]); |
7 | 5982 } |
5983 else if (newlen > hislen) /* array becomes bigger */ | |
5984 { | |
5985 for (i = 0; i <= hisidx[type]; ++i) | |
5986 temp[i] = history[type][i]; | |
5987 j = i; | |
5988 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 5989 clear_hist_entry(&temp[i]); |
7 | 5990 for ( ; j < hislen; ++i, ++j) |
5991 temp[i] = history[type][j]; | |
5992 } | |
5993 else /* array becomes smaller or 0 */ | |
5994 { | |
5995 j = hisidx[type]; | |
5996 for (i = newlen - 1; ; --i) | |
5997 { | |
5998 if (i >= 0) /* copy newest entries */ | |
5999 temp[i] = history[type][j]; | |
6000 else /* remove older entries */ | |
6001 vim_free(history[type][j].hisstr); | |
6002 if (--j < 0) | |
6003 j = hislen - 1; | |
6004 if (j == hisidx[type]) | |
6005 break; | |
6006 } | |
6007 hisidx[type] = newlen - 1; | |
6008 } | |
6009 vim_free(history[type]); | |
6010 history[type] = temp; | |
6011 } | |
6012 } | |
6013 hislen = newlen; | |
6014 } | |
6015 } | |
6016 | |
4258 | 6017 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6018 clear_hist_entry(histentry_T *hisptr) |
4258 | 6019 { |
6020 hisptr->hisnum = 0; | |
6021 hisptr->viminfo = FALSE; | |
6022 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6023 hisptr->time_set = 0; |
4258 | 6024 } |
6025 | |
7 | 6026 /* |
6027 * Check if command line 'str' is already in history. | |
6028 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6029 */ | |
6030 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6031 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6032 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6033 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6034 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
|
6035 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6036 int writing) /* ignore entries read from viminfo */ |
7 | 6037 { |
6038 int i; | |
6039 int last_i = -1; | |
2986 | 6040 char_u *p; |
7 | 6041 |
6042 if (hisidx[type] < 0) | |
6043 return FALSE; | |
6044 i = hisidx[type]; | |
6045 do | |
6046 { | |
6047 if (history[type][i].hisstr == NULL) | |
6048 return FALSE; | |
2986 | 6049 |
6050 /* For search history, check that the separator character matches as | |
6051 * well. */ | |
6052 p = history[type][i].hisstr; | |
6053 if (STRCMP(str, p) == 0 | |
4285 | 6054 && !(writing && history[type][i].viminfo) |
2986 | 6055 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6056 { |
6057 if (!move_to_front) | |
6058 return TRUE; | |
6059 last_i = i; | |
6060 break; | |
6061 } | |
6062 if (--i < 0) | |
6063 i = hislen - 1; | |
6064 } while (i != hisidx[type]); | |
6065 | |
6066 if (last_i >= 0) | |
6067 { | |
6068 str = history[type][i].hisstr; | |
6069 while (i != hisidx[type]) | |
6070 { | |
6071 if (++i >= hislen) | |
6072 i = 0; | |
6073 history[type][last_i] = history[type][i]; | |
6074 last_i = i; | |
6075 } | |
4258 | 6076 history[type][i].hisnum = ++hisnum[type]; |
6077 history[type][i].viminfo = FALSE; | |
7 | 6078 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6079 history[type][i].time_set = vim_time(); |
7 | 6080 return TRUE; |
6081 } | |
6082 return FALSE; | |
6083 } | |
6084 | |
6085 /* | |
6086 * Convert history name (from table above) to its HIST_ equivalent. | |
6087 * When "name" is empty, return "cmd" history. | |
6088 * Returns -1 for unknown history name. | |
6089 */ | |
6090 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6091 get_histtype(char_u *name) |
7 | 6092 { |
6093 int i; | |
6094 int len = (int)STRLEN(name); | |
6095 | |
6096 /* No argument: use current history. */ | |
6097 if (len == 0) | |
6098 return hist_char2type(ccline.cmdfirstc); | |
6099 | |
6100 for (i = 0; history_names[i] != NULL; ++i) | |
6101 if (STRNICMP(name, history_names[i], len) == 0) | |
6102 return i; | |
6103 | |
6104 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6105 return hist_char2type(name[0]); | |
6106 | |
6107 return -1; | |
6108 } | |
6109 | |
6110 static int last_maptick = -1; /* last seen maptick */ | |
6111 | |
6112 /* | |
6113 * Add the given string to the given history. If the string is already in the | |
6114 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6115 * values. | |
6116 */ | |
6117 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6118 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6119 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6120 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6121 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
|
6122 int sep) /* separator character used (search hist) */ |
7 | 6123 { |
6124 histentry_T *hisptr; | |
6125 int len; | |
6126 | |
6127 if (hislen == 0) /* no history */ | |
6128 return; | |
6129 | |
5467 | 6130 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6131 return; | |
6132 | |
7 | 6133 /* |
6134 * Searches inside the same mapping overwrite each other, so that only | |
6135 * the last line is kept. Be careful not to remove a line that was moved | |
6136 * down, only lines that were added. | |
6137 */ | |
6138 if (histype == HIST_SEARCH && in_map) | |
6139 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6140 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6141 { |
6142 /* Current line is from the same mapping, remove it */ | |
6143 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6144 vim_free(hisptr->hisstr); | |
4258 | 6145 clear_hist_entry(hisptr); |
7 | 6146 --hisnum[histype]; |
6147 if (--hisidx[HIST_SEARCH] < 0) | |
6148 hisidx[HIST_SEARCH] = hislen - 1; | |
6149 } | |
6150 last_maptick = -1; | |
6151 } | |
4285 | 6152 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6153 { |
6154 if (++hisidx[histype] == hislen) | |
6155 hisidx[histype] = 0; | |
6156 hisptr = &history[histype][hisidx[histype]]; | |
6157 vim_free(hisptr->hisstr); | |
6158 | |
6159 /* Store the separator after the NUL of the string. */ | |
835 | 6160 len = (int)STRLEN(new_entry); |
7 | 6161 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6162 if (hisptr->hisstr != NULL) | |
6163 hisptr->hisstr[len + 1] = sep; | |
6164 | |
6165 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6166 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6167 hisptr->time_set = vim_time(); |
7 | 6168 if (histype == HIST_SEARCH && in_map) |
6169 last_maptick = maptick; | |
6170 } | |
6171 } | |
6172 | |
6173 #if defined(FEAT_EVAL) || defined(PROTO) | |
6174 | |
6175 /* | |
6176 * Get identifier of newest history entry. | |
6177 * "histype" may be one of the HIST_ values. | |
6178 */ | |
6179 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6180 get_history_idx(int histype) |
7 | 6181 { |
6182 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6183 || hisidx[histype] < 0) | |
6184 return -1; | |
6185 | |
6186 return history[histype][hisidx[histype]].hisnum; | |
6187 } | |
6188 | |
531 | 6189 /* |
7 | 6190 * Calculate history index from a number: |
6191 * num > 0: seen as identifying number of a history entry | |
6192 * num < 0: relative position in history wrt newest entry | |
6193 * "histype" may be one of the HIST_ values. | |
6194 */ | |
6195 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6196 calc_hist_idx(int histype, int num) |
7 | 6197 { |
6198 int i; | |
6199 histentry_T *hist; | |
6200 int wrapped = FALSE; | |
6201 | |
6202 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6203 || (i = hisidx[histype]) < 0 || num == 0) | |
6204 return -1; | |
6205 | |
6206 hist = history[histype]; | |
6207 if (num > 0) | |
6208 { | |
6209 while (hist[i].hisnum > num) | |
6210 if (--i < 0) | |
6211 { | |
6212 if (wrapped) | |
6213 break; | |
6214 i += hislen; | |
6215 wrapped = TRUE; | |
6216 } | |
6217 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6218 return i; | |
6219 } | |
6220 else if (-num <= hislen) | |
6221 { | |
6222 i += num + 1; | |
6223 if (i < 0) | |
6224 i += hislen; | |
6225 if (hist[i].hisstr != NULL) | |
6226 return i; | |
6227 } | |
6228 return -1; | |
6229 } | |
6230 | |
6231 /* | |
6232 * Get a history entry by its index. | |
6233 * "histype" may be one of the HIST_ values. | |
6234 */ | |
6235 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6236 get_history_entry(int histype, int idx) |
7 | 6237 { |
6238 idx = calc_hist_idx(histype, idx); | |
6239 if (idx >= 0) | |
6240 return history[histype][idx].hisstr; | |
6241 else | |
6242 return (char_u *)""; | |
6243 } | |
6244 | |
6245 /* | |
6246 * Clear all entries of a history. | |
6247 * "histype" may be one of the HIST_ values. | |
6248 */ | |
6249 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6250 clr_history(int histype) |
7 | 6251 { |
6252 int i; | |
6253 histentry_T *hisptr; | |
6254 | |
6255 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6256 { | |
6257 hisptr = history[histype]; | |
6258 for (i = hislen; i--;) | |
6259 { | |
6260 vim_free(hisptr->hisstr); | |
4258 | 6261 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6262 hisptr++; |
7 | 6263 } |
6264 hisidx[histype] = -1; /* mark history as cleared */ | |
6265 hisnum[histype] = 0; /* reset identifier counter */ | |
6266 return OK; | |
6267 } | |
6268 return FAIL; | |
6269 } | |
6270 | |
6271 /* | |
6272 * Remove all entries matching {str} from a history. | |
6273 * "histype" may be one of the HIST_ values. | |
6274 */ | |
6275 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6276 del_history_entry(int histype, char_u *str) |
7 | 6277 { |
6278 regmatch_T regmatch; | |
6279 histentry_T *hisptr; | |
6280 int idx; | |
6281 int i; | |
6282 int last; | |
6283 int found = FALSE; | |
6284 | |
6285 regmatch.regprog = NULL; | |
6286 regmatch.rm_ic = FALSE; /* always match case */ | |
6287 if (hislen != 0 | |
6288 && histype >= 0 | |
6289 && histype < HIST_COUNT | |
6290 && *str != NUL | |
6291 && (idx = hisidx[histype]) >= 0 | |
6292 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6293 != NULL) | |
6294 { | |
6295 i = last = idx; | |
6296 do | |
6297 { | |
6298 hisptr = &history[histype][i]; | |
6299 if (hisptr->hisstr == NULL) | |
6300 break; | |
6301 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6302 { | |
6303 found = TRUE; | |
6304 vim_free(hisptr->hisstr); | |
4258 | 6305 clear_hist_entry(hisptr); |
7 | 6306 } |
6307 else | |
6308 { | |
6309 if (i != last) | |
6310 { | |
6311 history[histype][last] = *hisptr; | |
4258 | 6312 clear_hist_entry(hisptr); |
7 | 6313 } |
6314 if (--last < 0) | |
6315 last += hislen; | |
6316 } | |
6317 if (--i < 0) | |
6318 i += hislen; | |
6319 } while (i != idx); | |
6320 if (history[histype][idx].hisstr == NULL) | |
6321 hisidx[histype] = -1; | |
6322 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6323 vim_regfree(regmatch.regprog); |
7 | 6324 return found; |
6325 } | |
6326 | |
6327 /* | |
6328 * Remove an indexed entry from a history. | |
6329 * "histype" may be one of the HIST_ values. | |
6330 */ | |
6331 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6332 del_history_idx(int histype, int idx) |
7 | 6333 { |
6334 int i, j; | |
6335 | |
6336 i = calc_hist_idx(histype, idx); | |
6337 if (i < 0) | |
6338 return FALSE; | |
6339 idx = hisidx[histype]; | |
6340 vim_free(history[histype][i].hisstr); | |
6341 | |
6342 /* When deleting the last added search string in a mapping, reset | |
6343 * last_maptick, so that the last added search string isn't deleted again. | |
6344 */ | |
6345 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6346 last_maptick = -1; | |
6347 | |
6348 while (i != idx) | |
6349 { | |
6350 j = (i + 1) % hislen; | |
6351 history[histype][i] = history[histype][j]; | |
6352 i = j; | |
6353 } | |
4258 | 6354 clear_hist_entry(&history[histype][i]); |
7 | 6355 if (--i < 0) |
6356 i += hislen; | |
6357 hisidx[histype] = i; | |
6358 return TRUE; | |
6359 } | |
6360 | |
6361 #endif /* FEAT_EVAL */ | |
6362 | |
6363 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6364 /* | |
6365 * Very specific function to remove the value in ":set key=val" from the | |
6366 * history. | |
6367 */ | |
6368 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6369 remove_key_from_history(void) |
7 | 6370 { |
6371 char_u *p; | |
6372 int i; | |
6373 | |
6374 i = hisidx[HIST_CMD]; | |
6375 if (i < 0) | |
6376 return; | |
6377 p = history[HIST_CMD][i].hisstr; | |
6378 if (p != NULL) | |
6379 for ( ; *p; ++p) | |
6380 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6381 { | |
6382 p = vim_strchr(p + 3, '='); | |
6383 if (p == NULL) | |
6384 break; | |
6385 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6386 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6387 if (p[i] == '\\' && p[i + 1]) |
6388 ++i; | |
1621 | 6389 STRMOVE(p, p + i); |
7 | 6390 --p; |
6391 } | |
6392 } | |
6393 #endif | |
6394 | |
6395 #endif /* FEAT_CMDHIST */ | |
6396 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6397 #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
|
6398 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6399 * Get pointer to the command line info to use. cmdline_paste() may clear |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6400 * 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
|
6401 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6402 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6403 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6404 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6405 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6406 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6407 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6408 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6409 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
|
6410 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6411 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6412 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6413 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6414 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6415 #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
|
6416 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6417 * 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
|
6418 * 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
|
6419 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6420 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6421 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6422 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6423 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6424 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
|
6425 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6426 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6427 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6428 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
|
6429 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6430 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6431 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6432 * 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
|
6433 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6434 * 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
|
6435 * Returns -1 when something is wrong. |
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 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6438 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6439 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6440 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
|
6441 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6442 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6443 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6444 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6445 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6446 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6447 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6448 * 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
|
6449 * 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
|
6450 * 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
|
6451 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6452 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6453 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6454 int pos) |
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 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
|
6457 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6458 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6459 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6460 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6461 /* 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
|
6462 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6463 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6464 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6465 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6466 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6467 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6468 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6469 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6470 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6471 #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
|
6472 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6473 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6474 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6475 * 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
|
6476 * Returns NUL when something is wrong. |
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 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6479 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6480 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6481 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
|
6482 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6483 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6484 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6485 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6486 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6487 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6488 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6489 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6490 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6491 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6492 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6493 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6494 |
7 | 6495 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6496 /* | |
6497 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6498 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6499 * Returns OK if parsed successfully, otherwise FAIL. | |
6500 */ | |
6501 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6502 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6503 { |
6504 int len; | |
6505 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6506 varnumber_T num; |
7 | 6507 |
6508 *str = skipwhite(*str); | |
6509 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6510 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6511 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6512 *str += len; |
6513 *num1 = (int)num; | |
6514 first = TRUE; | |
6515 } | |
6516 *str = skipwhite(*str); | |
6517 if (**str == ',') /* parse "to" part of range */ | |
6518 { | |
6519 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6520 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6521 if (len > 0) |
6522 { | |
6523 *num2 = (int)num; | |
6524 *str = skipwhite(*str + len); | |
6525 } | |
6526 else if (!first) /* no number given at all */ | |
6527 return FAIL; | |
6528 } | |
6529 else if (first) /* only one number given */ | |
6530 *num2 = *num1; | |
6531 return OK; | |
6532 } | |
6533 #endif | |
6534 | |
6535 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6536 /* | |
6537 * :history command - print a history | |
6538 */ | |
6539 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6540 ex_history(exarg_T *eap) |
7 | 6541 { |
6542 histentry_T *hist; | |
6543 int histype1 = HIST_CMD; | |
6544 int histype2 = HIST_CMD; | |
6545 int hisidx1 = 1; | |
6546 int hisidx2 = -1; | |
6547 int idx; | |
6548 int i, j, k; | |
6549 char_u *end; | |
6550 char_u *arg = eap->arg; | |
6551 | |
6552 if (hislen == 0) | |
6553 { | |
6554 MSG(_("'history' option is zero")); | |
6555 return; | |
6556 } | |
6557 | |
6558 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6559 { | |
6560 end = arg; | |
6561 while (ASCII_ISALPHA(*end) | |
6562 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6563 end++; | |
6564 i = *end; | |
6565 *end = NUL; | |
6566 histype1 = get_histtype(arg); | |
6567 if (histype1 == -1) | |
6568 { | |
1853 | 6569 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6570 { |
6571 histype1 = 0; | |
6572 histype2 = HIST_COUNT-1; | |
6573 } | |
6574 else | |
6575 { | |
6576 *end = i; | |
6577 EMSG(_(e_trailing)); | |
6578 return; | |
6579 } | |
6580 } | |
6581 else | |
6582 histype2 = histype1; | |
6583 *end = i; | |
6584 } | |
6585 else | |
6586 end = arg; | |
6587 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6588 { | |
6589 EMSG(_(e_trailing)); | |
6590 return; | |
6591 } | |
6592 | |
6593 for (; !got_int && histype1 <= histype2; ++histype1) | |
6594 { | |
6595 STRCPY(IObuff, "\n # "); | |
6596 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6597 MSG_PUTS_TITLE(IObuff); | |
6598 idx = hisidx[histype1]; | |
6599 hist = history[histype1]; | |
6600 j = hisidx1; | |
6601 k = hisidx2; | |
6602 if (j < 0) | |
6603 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6604 if (k < 0) | |
6605 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6606 if (idx >= 0 && j <= k) | |
6607 for (i = idx + 1; !got_int; ++i) | |
6608 { | |
6609 if (i == hislen) | |
6610 i = 0; | |
6611 if (hist[i].hisstr != NULL | |
6612 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6613 { | |
6614 msg_putchar('\n'); | |
6615 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6616 hist[i].hisnum); | |
6617 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6618 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6619 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6620 else |
6621 STRCAT(IObuff, hist[i].hisstr); | |
6622 msg_outtrans(IObuff); | |
6623 out_flush(); | |
6624 } | |
6625 if (i == idx) | |
6626 break; | |
6627 } | |
6628 } | |
6629 } | |
6630 #endif | |
6631 | |
6632 #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
|
6633 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6634 * 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
|
6635 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6636 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
|
6637 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6638 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
|
6639 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6640 static int viminfo_add_at_front = FALSE; |
6641 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6642 static int hist_type2char(int type, int use_question); |
7 | 6643 |
6644 /* | |
6645 * Translate a history type number to the associated character. | |
6646 */ | |
6647 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6648 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6649 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6650 int use_question) /* use '?' instead of '/' */ |
7 | 6651 { |
6652 if (type == HIST_CMD) | |
6653 return ':'; | |
6654 if (type == HIST_SEARCH) | |
6655 { | |
6656 if (use_question) | |
6657 return '?'; | |
6658 else | |
6659 return '/'; | |
6660 } | |
6661 if (type == HIST_EXPR) | |
6662 return '='; | |
6663 return '@'; | |
6664 } | |
6665 | |
6666 /* | |
6667 * Prepare for reading the history from the viminfo file. | |
6668 * This allocates history arrays to store the read history lines. | |
6669 */ | |
6670 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6671 prepare_viminfo_history(int asklen, int writing) |
7 | 6672 { |
6673 int i; | |
6674 int num; | |
6675 int type; | |
6676 int len; | |
6677 | |
6678 init_history(); | |
4285 | 6679 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6680 if (asklen > hislen) |
6681 asklen = hislen; | |
6682 | |
6683 for (type = 0; type < HIST_COUNT; ++type) | |
6684 { | |
4258 | 6685 /* Count the number of empty spaces in the history list. Entries read |
6686 * from viminfo previously are also considered empty. If there are | |
6687 * more spaces available than we request, then fill them up. */ | |
7 | 6688 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6689 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6690 num++; |
6691 len = asklen; | |
6692 if (num > len) | |
6693 len = num; | |
6694 if (len <= 0) | |
6695 viminfo_history[type] = NULL; | |
6696 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6697 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6698 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6699 if (viminfo_history[type] == NULL) |
6700 len = 0; | |
6701 viminfo_hislen[type] = len; | |
6702 viminfo_hisidx[type] = 0; | |
6703 } | |
6704 } | |
6705 | |
6706 /* | |
6707 * Accept a line from the viminfo, store it in the history array when it's | |
6708 * new. | |
6709 */ | |
6710 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6711 read_viminfo_history(vir_T *virp, int writing) |
7 | 6712 { |
6713 int type; | |
6714 long_u len; | |
6715 char_u *val; | |
6716 char_u *p; | |
6717 | |
6718 type = hist_char2type(virp->vir_line[0]); | |
6719 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6720 { | |
6721 val = viminfo_readstring(virp, 1, TRUE); | |
6722 if (val != NULL && *val != NUL) | |
6723 { | |
3316 | 6724 int sep = (*val == ' ' ? NUL : *val); |
6725 | |
7 | 6726 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6727 viminfo_add_at_front, sep, writing)) |
7 | 6728 { |
6729 /* Need to re-allocate to append the separator byte. */ | |
6730 len = STRLEN(val); | |
6731 p = lalloc(len + 2, TRUE); | |
6732 if (p != NULL) | |
6733 { | |
6734 if (type == HIST_SEARCH) | |
6735 { | |
6736 /* Search entry: Move the separator from the first | |
6737 * column to after the NUL. */ | |
6738 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6739 p[len] = sep; |
7 | 6740 } |
6741 else | |
6742 { | |
6743 /* Not a search entry: No separator in the viminfo | |
6744 * file, add a NUL separator. */ | |
6745 mch_memmove(p, val, (size_t)len + 1); | |
6746 p[len + 1] = NUL; | |
6747 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6748 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
|
6749 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
|
6750 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
|
6751 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
|
6752 viminfo_hisidx[type]++; |
7 | 6753 } |
6754 } | |
6755 } | |
6756 vim_free(val); | |
6757 } | |
6758 return viminfo_readline(virp); | |
6759 } | |
6760 | |
4285 | 6761 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6762 * 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
|
6763 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6764 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6765 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6766 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6767 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6768 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6769 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6770 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6771 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6772 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6773 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6774 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
|
6775 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6776 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6777 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6778 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6779 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6780 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6781 || (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
|
6782 || 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
|
6783 return; |
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 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6786 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6787 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6788 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
|
6789 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6790 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6791 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6792 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6793 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
|
6794 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6795 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6796 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6797 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6798 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
|
6799 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6800 /* 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
|
6801 * 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
|
6802 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
|
6803 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6804 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6805 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6806 && (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
|
6807 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6808 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6809 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6810 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6811 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6812 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6813 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6814 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6815 /* 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
|
6816 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6817 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6818 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6819 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6820 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6821 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6822 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6823 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
|
6824 if (!overwrite) |
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 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
|
6827 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6828 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6829 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
|
6830 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6831 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
|
6832 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6833 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6834 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6835 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6836 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6837 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6838 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6839 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6840 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6841 * 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
|
6842 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6843 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6844 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6845 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6846 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6847 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6848 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6849 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6850 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6851 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6852 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6853 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6854 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6855 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6856 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6857 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6858 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6859 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6860 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6861 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6862 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6863 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6864 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6865 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6866 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6867 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6868 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6869 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6870 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6871 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
|
6872 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6873 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6874 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
|
6875 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6876 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
|
6877 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6878 idx = hislen - 1; |
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 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6881 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6882 for (i = 0; i < viminfo_hisidx[type]; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6883 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6884 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6885 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6886 } |
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 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6889 #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
|
6890 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6891 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6892 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6893 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6894 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
|
6895 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6896 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6897 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6898 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6899 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
|
6900 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
|
6901 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6902 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6903 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6904 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 * 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
|
6907 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6908 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6909 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6911 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6912 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6913 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6914 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6915 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6916 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 /* 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
|
6919 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6920 tot_hist = (histentry_T **)alloc(max_len * (int)sizeof(histentry_T *)); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6921 new_hist = (histentry_T *)alloc(hislen * (int)sizeof(histentry_T)); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6922 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
|
6923 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6926 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 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
|
6929 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
|
6930 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6933 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6934 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6935 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6936 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
|
6937 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6938 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6939 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6940 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6942 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6943 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6944 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6945 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6946 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6947 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6948 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6949 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6950 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6951 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
|
6952 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6953 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6954 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
|
6955 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
|
6956 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6957 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6958 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6959 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
6960 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6961 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6962 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6963 /* |
4285 | 6964 * Finish reading history lines from viminfo. Not used when writing viminfo. |
6965 */ | |
7 | 6966 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6967 finish_viminfo_history(vir_T *virp) |
7 | 6968 { |
6969 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6970 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 6971 |
6972 for (type = 0; type < HIST_COUNT; ++type) | |
6973 { | |
6974 if (history[type] == NULL) | |
4283 | 6975 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6976 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6977 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6978 merge_history(type); |
7 | 6979 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6980 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6981 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
6982 VIM_CLEAR(viminfo_history[type]); |
4327 | 6983 viminfo_hisidx[type] = 0; |
7 | 6984 } |
6985 } | |
6986 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6987 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6988 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6989 * 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
|
6990 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6991 * 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
|
6992 */ |
7 | 6993 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6994 write_viminfo_history(FILE *fp, int merge) |
7 | 6995 { |
6996 int i; | |
6997 int type; | |
6998 int num_saved; | |
4283 | 6999 int round; |
7 | 7000 |
7001 init_history(); | |
7002 if (hislen == 0) | |
7003 return; | |
7004 for (type = 0; type < HIST_COUNT; ++type) | |
7005 { | |
7006 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
7007 if (num_saved == 0) | |
7008 continue; | |
7009 if (num_saved < 0) /* Use default */ | |
7010 num_saved = hislen; | |
7011 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7012 type == HIST_CMD ? _("Command Line") : | |
7013 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7014 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7015 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7016 _("Debug Line")); |
7 | 7017 if (num_saved > hislen) |
7018 num_saved = hislen; | |
4283 | 7019 |
7020 /* | |
7021 * Merge typed and viminfo history: | |
7022 * round 1: history of typed commands. | |
7023 * round 2: history from recently read viminfo. | |
7024 */ | |
7025 for (round = 1; round <= 2; ++round) | |
7026 { | |
4307 | 7027 if (round == 1) |
7028 /* start at newest entry, somewhere in the list */ | |
7029 i = hisidx[type]; | |
7030 else if (viminfo_hisidx[type] > 0) | |
7031 /* start at newest entry, first in the list */ | |
7032 i = 0; | |
7033 else | |
7034 /* empty list */ | |
7035 i = -1; | |
4283 | 7036 if (i >= 0) |
7037 while (num_saved > 0 | |
7038 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7039 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7040 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7041 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7042 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7043 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7044 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7045 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7046 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7047 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7048 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7049 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7050 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7051 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7052 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7053 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7054 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7055 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7056 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7057 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7058 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7059 || !history[type][i].viminfo)) |
7 | 7060 { |
4283 | 7061 --num_saved; |
7062 fputc(hist_type2char(type, TRUE), fp); | |
7063 /* For the search history: put the separator in the | |
7064 * second column; use a space if there isn't one. */ | |
7065 if (type == HIST_SEARCH) | |
7066 { | |
7067 c = p[STRLEN(p) + 1]; | |
7068 putc(c == NUL ? ' ' : c, fp); | |
7069 } | |
7070 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7071 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7072 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7073 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7074 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7075 /* 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
|
7076 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7077 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7078 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7079 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7080 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7081 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
|
7082 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7083 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7084 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7085 } |
7 | 7086 } |
4283 | 7087 if (round == 1) |
7088 { | |
7089 /* Decrement index, loop around and stop when back at | |
7090 * the start. */ | |
7091 if (--i < 0) | |
7092 i = hislen - 1; | |
7093 if (i == hisidx[type]) | |
7094 break; | |
7095 } | |
7096 else | |
7097 { | |
7098 /* Increment index. Stop at the end in the while. */ | |
7099 ++i; | |
7100 } | |
7 | 7101 } |
4283 | 7102 } |
4285 | 7103 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7104 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7105 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
|
7106 VIM_CLEAR(viminfo_history[type]); |
4311 | 7107 viminfo_hisidx[type] = 0; |
7 | 7108 } |
7109 } | |
7110 #endif /* FEAT_VIMINFO */ | |
7111 | |
7112 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7113 /* | |
7114 * Write a character at the current cursor+offset position. | |
7115 * It is directly written into the command buffer block. | |
7116 */ | |
7117 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7118 cmd_pchar(int c, int offset) |
7 | 7119 { |
7120 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7121 { | |
7122 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7123 return; | |
7124 } | |
7125 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7126 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7127 } | |
7128 | |
7129 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7130 cmd_gchar(int offset) |
7 | 7131 { |
7132 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7133 { | |
7134 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7135 return NUL; | |
7136 } | |
7137 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7138 } | |
7139 #endif | |
7140 | |
7141 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7142 /* | |
7143 * Open a window on the current command line and history. Allow editing in | |
7144 * the window. Returns when the window is closed. | |
7145 * Returns: | |
7146 * CR if the command is to be executed | |
7147 * Ctrl_C if it is to be abandoned | |
7148 * K_IGNORE if editing continues | |
7149 */ | |
7150 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
|
7151 open_cmdwin(void) |
7 | 7152 { |
7153 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7154 bufref_T old_curbuf; |
7 | 7155 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7156 bufref_T bufref; |
7 | 7157 win_T *wp; |
7158 int i; | |
7159 linenr_T lnum; | |
7160 int histtype; | |
7161 garray_T winsizes; | |
7162 int save_restart_edit = restart_edit; | |
7163 int save_State = State; | |
7164 int save_exmode = exmode_active; | |
510 | 7165 #ifdef FEAT_RIGHTLEFT |
7166 int save_cmdmsg_rl = cmdmsg_rl; | |
7167 #endif | |
6145 | 7168 #ifdef FEAT_FOLDING |
7169 int save_KeyTyped; | |
7170 #endif | |
7 | 7171 |
7172 /* Can't do this recursively. Can't do it when typing a password. */ | |
7173 if (cmdwin_type != 0 | |
7174 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7175 || cmdline_star > 0 | |
7176 # endif | |
7177 ) | |
7178 { | |
7179 beep_flush(); | |
7180 return K_IGNORE; | |
7181 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7182 set_bufref(&old_curbuf, curbuf); |
7 | 7183 |
7184 /* Save current window sizes. */ | |
7185 win_size_save(&winsizes); | |
7186 | |
7187 /* Don't execute autocommands while creating the window. */ | |
1410 | 7188 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7189 |
683 | 7190 /* don't use a new tab page */ |
7191 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
|
7192 cmdmod.noswapfile = 1; |
683 | 7193 |
7 | 7194 /* Create a window for the command-line buffer. */ |
7195 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7196 { | |
7197 beep_flush(); | |
1410 | 7198 unblock_autocmds(); |
7 | 7199 return K_IGNORE; |
7200 } | |
1831 | 7201 cmdwin_type = get_cmdline_type(); |
7 | 7202 |
7203 /* Create the command-line buffer empty. */ | |
1743 | 7204 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7205 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7206 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7207 curbuf->b_p_ma = TRUE; | |
1865 | 7208 #ifdef FEAT_FOLDING |
7209 curwin->w_p_fen = FALSE; | |
7210 #endif | |
7 | 7211 # ifdef FEAT_RIGHTLEFT |
510 | 7212 curwin->w_p_rl = cmdmsg_rl; |
7213 cmdmsg_rl = FALSE; | |
7 | 7214 # endif |
2583 | 7215 RESET_BINDING(curwin); |
7 | 7216 |
7217 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7218 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7219 /* 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
|
7220 ++curbuf_lock; |
7 | 7221 |
510 | 7222 /* Showing the prompt may have set need_wait_return, reset it. */ |
7223 need_wait_return = FALSE; | |
7224 | |
1831 | 7225 histtype = hist_char2type(cmdwin_type); |
7 | 7226 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7227 { | |
7228 if (p_wc == TAB) | |
7229 { | |
7230 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7231 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7232 } | |
7233 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7234 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7235 --curbuf_lock; |
7 | 7236 |
10 | 7237 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7238 * sets 'textwidth' to 78). */ | |
7239 curbuf->b_p_tw = 0; | |
7240 | |
7 | 7241 /* Fill the buffer with the history. */ |
7242 init_history(); | |
7243 if (hislen > 0) | |
7244 { | |
7245 i = hisidx[histtype]; | |
7246 if (i >= 0) | |
7247 { | |
7248 lnum = 0; | |
7249 do | |
7250 { | |
7251 if (++i == hislen) | |
7252 i = 0; | |
7253 if (history[histtype][i].hisstr != NULL) | |
7254 ml_append(lnum++, history[histtype][i].hisstr, | |
7255 (colnr_T)0, FALSE); | |
7256 } | |
7257 while (i != hisidx[histtype]); | |
7258 } | |
7259 } | |
7260 | |
7261 /* Replace the empty last line with the current command-line and put the | |
7262 * cursor there. */ | |
7263 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7264 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7265 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7266 changed_line_abv_curs(); |
7267 invalidate_botline(); | |
743 | 7268 redraw_later(SOME_VALID); |
7 | 7269 |
7270 /* Save the command line info, can be used recursively. */ | |
10565
ea0dadb041c9
patch 8.0.0172: command line window does not work
Christian Brabandt <cb@256bit.org>
parents:
10542
diff
changeset
|
7271 save_cmdline(&save_ccline); |
7 | 7272 |
7273 /* No Ex mode here! */ | |
7274 exmode_active = 0; | |
7275 | |
7276 State = NORMAL; | |
7277 # ifdef FEAT_MOUSE | |
7278 setmouse(); | |
7279 # endif | |
7280 | |
7281 /* 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
|
7282 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7283 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7284 stuffcharReadbuff(K_NOP); | |
7 | 7285 |
7286 i = RedrawingDisabled; | |
7287 RedrawingDisabled = 0; | |
7288 | |
7289 /* | |
7290 * Call the main loop until <CR> or CTRL-C is typed. | |
7291 */ | |
7292 cmdwin_result = 0; | |
168 | 7293 main_loop(TRUE, FALSE); |
7 | 7294 |
7295 RedrawingDisabled = i; | |
7296 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7297 # ifdef FEAT_FOLDING |
6145 | 7298 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7299 # endif |
6145 | 7300 |
7 | 7301 /* 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
|
7302 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7303 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7304 # ifdef FEAT_FOLDING |
6145 | 7305 /* Restore KeyTyped in case it is modified by autocommands */ |
7306 KeyTyped = save_KeyTyped; | |
7 | 7307 # endif |
7308 | |
1214 | 7309 /* Restore the command line info. */ |
10565
ea0dadb041c9
patch 8.0.0172: command line window does not work
Christian Brabandt <cb@256bit.org>
parents:
10542
diff
changeset
|
7310 restore_cmdline(&save_ccline); |
7 | 7311 cmdwin_type = 0; |
7312 | |
7313 exmode_active = save_exmode; | |
7314 | |
1612 | 7315 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7316 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7317 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7318 { |
7319 cmdwin_result = Ctrl_C; | |
7320 EMSG(_("E199: Active window or buffer deleted")); | |
7321 } | |
7322 else | |
7323 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7324 # if defined(FEAT_EVAL) |
7 | 7325 /* autocmds may abort script processing */ |
7326 if (aborting() && cmdwin_result != K_IGNORE) | |
7327 cmdwin_result = Ctrl_C; | |
7328 # endif | |
7329 /* Set the new command line from the cmdline buffer. */ | |
7330 vim_free(ccline.cmdbuff); | |
510 | 7331 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7332 { |
510 | 7333 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7334 | |
7335 if (histtype == HIST_CMD) | |
7336 { | |
7337 /* Execute the command directly. */ | |
7338 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7339 cmdwin_result = CAR; | |
7340 } | |
7341 else | |
7342 { | |
7343 /* First need to cancel what we were doing. */ | |
7344 ccline.cmdbuff = NULL; | |
7345 stuffcharReadbuff(':'); | |
7346 stuffReadbuff((char_u *)p); | |
7347 stuffcharReadbuff(CAR); | |
7348 } | |
7 | 7349 } |
7350 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7351 { | |
7352 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7353 cmdwin_result = CAR; | |
7354 } | |
2839 | 7355 else if (cmdwin_result == Ctrl_C) |
7356 { | |
7357 /* :q or :close, don't execute any command | |
7358 * and don't modify the cmd window. */ | |
7359 ccline.cmdbuff = NULL; | |
7360 } | |
7 | 7361 else |
7362 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7363 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
|
7364 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7365 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
|
7366 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
|
7367 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
|
7368 ccline.cmdpos = 0; |
7 | 7369 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
|
7370 } |
7 | 7371 else |
7372 { | |
7373 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7374 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7375 ccline.cmdpos = curwin->w_cursor.col; | |
7376 if (ccline.cmdpos > ccline.cmdlen) | |
7377 ccline.cmdpos = ccline.cmdlen; | |
7378 if (cmdwin_result == K_IGNORE) | |
7379 { | |
7380 set_cmdspos_cursor(); | |
7381 redrawcmd(); | |
7382 } | |
7383 } | |
7384 | |
7385 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7386 block_autocmds(); |
6876 | 7387 # ifdef FEAT_CONCEAL |
7388 /* Avoid command-line window first character being concealed. */ | |
7389 curwin->w_p_cole = 0; | |
7390 # endif | |
7 | 7391 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7392 set_bufref(&bufref, curbuf); |
7 | 7393 win_goto(old_curwin); |
7394 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7395 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7396 /* 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
|
7397 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7398 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7399 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7400 |
7401 /* Restore window sizes. */ | |
7402 win_size_restore(&winsizes); | |
7403 | |
1410 | 7404 unblock_autocmds(); |
7 | 7405 } |
7406 | |
7407 ga_clear(&winsizes); | |
7408 restart_edit = save_restart_edit; | |
510 | 7409 # ifdef FEAT_RIGHTLEFT |
7410 cmdmsg_rl = save_cmdmsg_rl; | |
7411 # endif | |
7 | 7412 |
7413 State = save_State; | |
7414 # ifdef FEAT_MOUSE | |
7415 setmouse(); | |
7416 # endif | |
7417 | |
7418 return cmdwin_result; | |
7419 } | |
7420 #endif /* FEAT_CMDWIN */ | |
7421 | |
7422 /* | |
7423 * Used for commands that either take a simple command string argument, or: | |
7424 * cmd << endmarker | |
7425 * {script} | |
7426 * endmarker | |
7427 * Returns a pointer to allocated memory with {script} or NULL. | |
7428 */ | |
7429 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7430 script_get(exarg_T *eap, char_u *cmd) |
7 | 7431 { |
7432 char_u *theline; | |
7433 char *end_pattern = NULL; | |
7434 char dot[] = "."; | |
7435 garray_T ga; | |
7436 | |
7437 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7438 return NULL; | |
7439 | |
7440 ga_init2(&ga, 1, 0x400); | |
7441 | |
7442 if (cmd[2] != NUL) | |
7443 end_pattern = (char *)skipwhite(cmd + 2); | |
7444 else | |
7445 end_pattern = dot; | |
7446 | |
7447 for (;;) | |
7448 { | |
7449 theline = eap->getline( | |
7450 #ifdef FEAT_EVAL | |
75 | 7451 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7452 #endif |
7453 NUL, eap->cookie, 0); | |
7454 | |
7455 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7456 { |
7457 vim_free(theline); | |
7 | 7458 break; |
1694 | 7459 } |
7 | 7460 |
7461 ga_concat(&ga, theline); | |
7462 ga_append(&ga, '\n'); | |
7463 vim_free(theline); | |
7464 } | |
21 | 7465 ga_append(&ga, NUL); |
7 | 7466 |
7467 return (char_u *)ga.ga_data; | |
7468 } |