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