Mercurial > vim
annotate src/ex_getln.c @ 14515:3648e74dd523 v8.1.0271
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
commit https://github.com/vim/vim/commit/b0acacd767a2b0618a7f3c08087708f4329580d0
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 11 16:40:43 2018 +0200
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Problem: 'incsearch' doesn't work for :s, :g or :v.
Solution: Also use 'incsearch' for other commands that use a pattern.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 11 Aug 2018 16:45:05 +0200 |
parents | 4825955cb706 |
children | 20866abc790b |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 /* | |
17 * Variables shared between getcmdline(), redrawcmdline() and others. | |
18 * These need to be saved when using CTRL-R |, that's why they are in a | |
19 * structure. | |
20 */ | |
21 struct cmdline_info | |
22 { | |
23 char_u *cmdbuff; /* pointer to command line buffer */ | |
24 int cmdbufflen; /* length of cmdbuff */ | |
25 int cmdlen; /* number of chars in command line */ | |
26 int cmdpos; /* current cursor position */ | |
27 int cmdspos; /* cursor column on screen */ | |
3503 | 28 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 29 int cmdindent; /* number of spaces before cmdline */ |
30 char_u *cmdprompt; /* message in front of cmdline */ | |
31 int cmdattr; /* attributes for prompt */ | |
32 int overstrike; /* Typing mode on the command line. Shared by | |
33 getcmdline() and put_on_cmdline(). */ | |
1718 | 34 expand_T *xpc; /* struct being used for expansion, xp_pattern |
35 may point into cmdbuff */ | |
531 | 36 int xp_context; /* type of expansion */ |
37 # ifdef FEAT_EVAL | |
38 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 39 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 40 # endif |
7 | 41 }; |
42 | |
1718 | 43 /* The current cmdline_info. It is initialized in getcmdline() and after that |
44 * used by other functions. When invoking getcmdline() recursively it needs | |
45 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
46 * TODO: make it local to getcmdline() and pass it around. */ | |
47 static struct cmdline_info ccline; | |
7 | 48 |
49 static int cmd_showtail; /* Only show path tail in lists ? */ | |
50 | |
51 #ifdef FEAT_EVAL | |
52 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
53 #endif | |
54 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
55 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
56 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
57 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
58 |
7 | 59 #ifdef FEAT_CMDHIST |
60 typedef struct hist_entry | |
61 { | |
62 int hisnum; /* identifying number */ | |
4258 | 63 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 64 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
65 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 66 } histentry_T; |
67 | |
68 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
69 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
70 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
71 /* identifying (unique) number of newest history entry */ | |
72 static int hislen = 0; /* actual length of history tables */ | |
73 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
74 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
75 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
76 static int in_history(int, char_u *, int, int, int); |
7 | 77 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int calc_hist_idx(int histype, int num); |
7 | 79 # endif |
80 #endif | |
81 | |
82 #ifdef FEAT_RIGHTLEFT | |
83 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
84 #endif | |
85 | |
86 #ifdef FEAT_FKMAP | |
87 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
88 #endif | |
89 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
90 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
91 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
92 static void set_cmdspos_cursor(void); |
7 | 93 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
97 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void draw_cmdline(int start, int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 static void save_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void restore_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 102 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 static void redrawcmd_preedit(void); |
7 | 104 #endif |
105 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
106 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
108 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
109 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 static int nextwild(expand_T *xp, int type, int options, int escape); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void escape_fname(char_u **pp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static int showmatches(expand_T *xp, int wildmenu); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static void set_expand_context(expand_T *xp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
116 static int expand_showtail(expand_T *xp); |
7 | 117 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
119 static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
120 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 121 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 123 # endif |
7 | 124 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
125 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 127 # endif |
128 #endif | |
4265 | 129 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 131 #endif |
7 | 132 |
133 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
134 static int open_cmdwin(void); |
7 | 135 #endif |
136 | |
3164 | 137 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
138 static int | |
139 #ifdef __BORLANDC__ | |
140 _RTLENTRYF | |
141 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
142 sort_func_compare(const void *s1, const void *s2); |
3164 | 143 #endif |
144 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
145 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
146 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
147 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
148 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
150 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
153 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
155 |
7 | 156 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
157 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
158 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
159 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
160 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
162 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
166 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
169 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
171 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
172 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
173 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
174 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
177 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
181 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
185 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
186 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
187 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
188 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
189 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
190 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
223 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
224 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
225 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
226 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 int incsearch_postponed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
238 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 is_state->incsearch_postponed = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
247 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
267 * Sets search_first_line and search_last_line to the address range. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
270 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
271 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
274 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
275 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
276 if (p_is && !cmd_silent) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
278 // by default search all lines |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
279 search_first_line = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
280 search_last_line = MAXLNUM; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
281 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
282 if (firstc == '/' || firstc == '?') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
283 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
284 if (firstc == ':') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
285 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
286 char_u *cmd = skip_range(ccline.cmdbuff, NULL); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
287 char_u *p; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
288 int delim; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
289 char_u *end; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
290 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
291 if (*cmd == 's' || *cmd == 'g' || *cmd == 'v') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
292 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
293 // Skip over "substitute" to find the pattern separator. |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
294 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
295 ; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
296 if (*p != NUL) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
297 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
298 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
|
299 end = skip_regexp(p, delim, p_magic, NULL); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
300 if (end > p) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
301 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
302 char_u *dummy; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
303 exarg_T ea; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
304 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
|
305 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
306 // 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
|
307 *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
|
308 *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
|
309 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
310 // parse the address range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
311 vim_memset(&ea, 0, sizeof(ea)); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
312 ea.line1 = 1; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
313 ea.line2 = 1; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
314 ea.cmd = ccline.cmdbuff; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
315 ea.addr_type = ADDR_LINES; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
316 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
|
317 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
|
318 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
|
319 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
320 search_first_line = ea.line1; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
321 search_last_line = ea.line2; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
322 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
323 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
|
324 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
325 // :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
|
326 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
|
327 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
|
328 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
329 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
330 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
|
331 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
|
332 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
333 } |
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 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
336 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
337 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
338 return FALSE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
339 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
340 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
341 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
342 * 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
|
343 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
344 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
345 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
|
346 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
347 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
348 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
|
349 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
350 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
|
351 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
352 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
|
353 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
|
354 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
355 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
356 #endif |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
357 int c; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
358 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
359 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
|
360 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
361 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
362 // 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
|
363 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
364 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
365 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
|
366 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
367 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
368 is_state->incsearch_postponed = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
369 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
370 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
|
371 // 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
|
372 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
|
373 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
374 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
375 // 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
|
376 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
|
377 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
|
378 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
379 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
|
380 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
381 // If there is no command line, don't do anything. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
382 if (patlen == 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
383 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
384 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
385 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
|
386 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
|
387 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
388 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
389 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
390 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
|
391 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
392 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
|
393 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
394 ++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
|
395 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
396 // 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
|
397 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
|
398 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
399 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
400 search_flags += SEARCH_KEEP; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
401 c = ccline.cmdbuff[skiplen + patlen]; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
402 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
|
403 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
|
404 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
|
405 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
406 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
407 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
408 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
409 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
410 ); |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
411 ccline.cmdbuff[skiplen + patlen] = c; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
412 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
413 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
414 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
|
415 || curwin->w_cursor.lnum > search_last_line) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
416 // 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
|
417 i = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
418 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
419 // 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
|
420 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
421 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
422 (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
|
423 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
|
424 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
425 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
426 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
|
427 // 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
|
428 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
|
429 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
430 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
431 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
|
432 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
433 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
|
434 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
435 // 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
|
436 // 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
|
437 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
|
438 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
|
439 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
440 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
441 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
442 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
443 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
|
444 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
445 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
|
446 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
|
447 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
448 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
|
449 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
|
450 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
|
451 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
452 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
453 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
|
454 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 // 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
|
456 // Avoids a flash when typing "foo\|". |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
457 c = ccline.cmdbuff[skiplen + patlen]; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
458 ccline.cmdbuff[skiplen + patlen] = NUL; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
459 if (empty_pattern(ccline.cmdbuff)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
460 set_no_hlsearch(TRUE); |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
461 ccline.cmdbuff[skiplen + patlen] = c; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
462 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
463 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
464 // 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
|
465 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
|
466 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
|
467 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
468 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
|
469 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
|
470 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
|
471 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
|
472 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
473 // 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
|
474 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
475 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
|
476 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
477 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
478 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
479 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
|
480 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
481 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
482 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
483 * 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
|
484 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
485 * 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
|
486 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
487 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
488 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
|
489 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
|
490 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
491 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
|
492 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
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 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
|
495 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
496 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
497 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
|
498 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
|
499 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
|
500 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
501 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
|
502 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
|
503 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
|
504 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
505 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
506 if (firstc == 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
|
507 pat = last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
508 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
|
509 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
|
510 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
511 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
|
512 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
513 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
514 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
|
515 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
516 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
|
517 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
|
518 // 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
|
519 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
520 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
521 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
|
522 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
523 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
524 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
|
525 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 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
|
527 ++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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 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
|
534 --emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
535 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
|
536 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
537 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 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
|
542 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
543 // 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
|
544 // 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
|
545 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
|
546 (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
|
547 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 else if (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
|
549 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 // Move just 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
|
551 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
552 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
553 (void)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
|
554 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
555 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
|
556 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
557 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
558 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
|
559 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
560 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
561 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
562 (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
|
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 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
|
566 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
|
567 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
|
568 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
569 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
570 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
571 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
|
572 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
|
573 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
574 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
575 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
576 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
|
577 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
|
578 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
579 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
580 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
581 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
582 * 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
|
583 * 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
|
584 * 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
|
585 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
586 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
587 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
|
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 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
|
590 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
591 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
|
592 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
593 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
594 // 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
|
595 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
|
596 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
597 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
|
598 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
|
599 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
600 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
601 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
602 // 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
|
603 // 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
|
604 // 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
|
605 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
|
606 *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
|
607 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
608 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
609 if (*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
|
610 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
|
611 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
612 // 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
|
613 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
618 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
619 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
621 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
622 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
623 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
624 finish_incsearch_highlighting(int gotesc, incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
625 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
626 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
|
627 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
628 if (gotesc) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
629 curwin->w_cursor = is_state->save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
630 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
631 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
632 if (!EQUAL_POS(is_state->save_cursor, is_state->search_start)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
633 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
634 // put the '" mark at the original position |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
635 curwin->w_cursor = is_state->save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
636 setpcmark(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
637 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
638 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
|
639 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
640 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
|
641 highlight_match = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
642 validate_cursor(); /* needed for TAB */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
643 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
|
644 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
645 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
646 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
647 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
648 /* |
7 | 649 * getcmdline() - accept a command line starting with firstc. |
650 * | |
651 * firstc == ':' get ":" command line. | |
652 * firstc == '/' or '?' get search pattern | |
653 * firstc == '=' get expression | |
654 * firstc == '@' get text for input() function | |
655 * firstc == '>' get text for debug mode | |
656 * firstc == NUL get text for :insert command | |
657 * firstc == -1 like NUL, and break on CTRL-C | |
658 * | |
659 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
660 * command line. | |
661 * | |
662 * Careful: getcmdline() can be called recursively! | |
663 * | |
664 * Return pointer to allocated string if there is a commandline, NULL | |
665 * otherwise. | |
666 */ | |
667 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
668 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
669 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
670 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
|
671 int indent) /* indent for inside conditionals */ |
7 | 672 { |
673 int c; | |
674 int i; | |
675 int j; | |
676 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
677 int do_abbr; /* when TRUE check for abbr. */ | |
678 #ifdef FEAT_CMDHIST | |
679 char_u *lookfor = NULL; /* string to match */ | |
680 int hiscnt; /* current history line in use */ | |
681 int histype; /* history type to be used */ | |
682 #endif | |
683 #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
|
684 incsearch_state_T is_state; |
7 | 685 #endif |
686 int did_wild_list = FALSE; /* did wild_list() recently */ | |
687 int wim_index = 0; /* index in wim_flags[] */ | |
688 int res; | |
689 int save_msg_scroll = msg_scroll; | |
690 int save_State = State; /* remember State when called */ | |
691 int some_key_typed = FALSE; /* one of the keys was typed */ | |
692 #ifdef FEAT_MOUSE | |
693 /* mouse drag and release events are ignored, unless they are | |
694 * preceded with a mouse down event */ | |
695 int ignore_drag_release = TRUE; | |
696 #endif | |
697 #ifdef FEAT_EVAL | |
698 int break_ctrl_c = FALSE; | |
699 #endif | |
700 expand_T xpc; | |
701 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
|
702 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 703 /* Everything that may work recursively should save and restore the |
704 * current command line in save_ccline. That includes update_screen(), a | |
705 * custom status line may invoke ":normal". */ | |
706 struct cmdline_info save_ccline; | |
707 #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
|
708 int cmdline_type; |
7 | 709 |
710 #ifdef FEAT_EVAL | |
711 if (firstc == -1) | |
712 { | |
713 firstc = NUL; | |
714 break_ctrl_c = TRUE; | |
715 } | |
716 #endif | |
717 #ifdef FEAT_RIGHTLEFT | |
718 /* start without Hebrew mapping for a command line */ | |
719 if (firstc == ':' || firstc == '=' || firstc == '>') | |
720 cmd_hkmap = 0; | |
721 #endif | |
722 | |
723 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
|
724 |
7 | 725 #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
|
726 init_incsearch_state(&is_state); |
7 | 727 #endif |
728 | |
729 /* | |
730 * set some variables for redrawcmd() | |
731 */ | |
732 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 733 ccline.cmdindent = (firstc > 0 ? indent : 0); |
734 | |
735 /* alloc initial ccline.cmdbuff */ | |
736 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 737 if (ccline.cmdbuff == NULL) |
738 return NULL; /* out of memory */ | |
739 ccline.cmdlen = ccline.cmdpos = 0; | |
740 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
|
741 sb_text_start_cmdline(); |
7 | 742 |
164 | 743 /* autoindent for :insert and :append */ |
744 if (firstc <= 0) | |
745 { | |
6929 | 746 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 747 ccline.cmdbuff[indent] = NUL; |
748 ccline.cmdpos = indent; | |
749 ccline.cmdspos = indent; | |
750 ccline.cmdlen = indent; | |
751 } | |
752 | |
7 | 753 ExpandInit(&xpc); |
1718 | 754 ccline.xpc = &xpc; |
7 | 755 |
756 #ifdef FEAT_RIGHTLEFT | |
757 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
758 && (firstc == '/' || firstc == '?')) | |
759 cmdmsg_rl = TRUE; | |
760 else | |
761 cmdmsg_rl = FALSE; | |
762 #endif | |
763 | |
764 redir_off = TRUE; /* don't redirect the typed command */ | |
765 if (!cmd_silent) | |
766 { | |
767 i = msg_scrolled; | |
768 msg_scrolled = 0; /* avoid wait_return message */ | |
769 gotocmdline(TRUE); | |
770 msg_scrolled += i; | |
771 redrawcmdprompt(); /* draw prompt or indent */ | |
772 set_cmdspos(); | |
773 } | |
774 xpc.xp_context = EXPAND_NOTHING; | |
775 xpc.xp_backslash = XP_BS_NONE; | |
632 | 776 #ifndef BACKSLASH_IN_FILENAME |
777 xpc.xp_shell = FALSE; | |
778 #endif | |
7 | 779 |
531 | 780 #if defined(FEAT_EVAL) |
781 if (ccline.input_fn) | |
782 { | |
783 xpc.xp_context = ccline.xp_context; | |
784 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 785 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 786 xpc.xp_arg = ccline.xp_arg; |
1322 | 787 # endif |
531 | 788 } |
789 #endif | |
790 | |
7 | 791 /* |
792 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
793 * doing ":@0" when register 0 doesn't contain a CR. | |
794 */ | |
795 msg_scroll = FALSE; | |
796 | |
797 State = CMDLINE; | |
798 | |
799 if (firstc == '/' || firstc == '?' || firstc == '@') | |
800 { | |
801 /* Use ":lmap" mappings for search pattern and input(). */ | |
802 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
803 b_im_ptr = &curbuf->b_p_iminsert; | |
804 else | |
805 b_im_ptr = &curbuf->b_p_imsearch; | |
806 if (*b_im_ptr == B_IMODE_LMAP) | |
807 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
808 #ifdef HAVE_INPUT_METHOD |
7 | 809 im_set_active(*b_im_ptr == B_IMODE_IM); |
810 #endif | |
811 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
812 #ifdef HAVE_INPUT_METHOD |
7 | 813 else if (p_imcmdline) |
814 im_set_active(TRUE); | |
815 #endif | |
816 | |
817 #ifdef FEAT_MOUSE | |
818 setmouse(); | |
819 #endif | |
820 #ifdef CURSOR_SHAPE | |
821 ui_cursor_shape(); /* may show different cursor shape */ | |
822 #endif | |
823 | |
571 | 824 /* When inside an autocommand for writing "exiting" may be set and |
825 * terminal mode set to cooked. Need to set raw mode here then. */ | |
826 settmode(TMODE_RAW); | |
827 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
828 /* 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
|
829 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
|
830 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
|
831 |
7 | 832 #ifdef FEAT_CMDHIST |
833 init_history(); | |
834 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
835 histype = hist_char2type(firstc); | |
836 #endif | |
837 | |
838 #ifdef FEAT_DIGRAPHS | |
1868 | 839 do_digraph(-1); /* init digraph typeahead */ |
7 | 840 #endif |
841 | |
5993 | 842 /* If something above caused an error, reset the flags, we do want to type |
843 * and execute commands. Display may be messed up a bit. */ | |
844 if (did_emsg) | |
845 redrawcmd(); | |
846 did_emsg = FALSE; | |
847 got_int = FALSE; | |
848 | |
7 | 849 /* |
850 * Collect the command string, handling editing keys. | |
851 */ | |
852 for (;;) | |
853 { | |
972 | 854 redir_off = TRUE; /* Don't redirect the typed command. |
855 Repeated, because a ":redir" inside | |
856 completion may switch it on. */ | |
7 | 857 #ifdef USE_ON_FLY_SCROLL |
858 dont_scroll = FALSE; /* allow scrolling here */ | |
859 #endif | |
860 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
861 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
862 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
|
863 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
|
864 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
|
865 |
7 | 866 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 867 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
868 /* 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
|
869 * anything, such as stop completion. */ |
1472 | 870 do |
871 { | |
872 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
|
873 } while (c == K_IGNORE || c == K_NOP); |
1472 | 874 |
7 | 875 if (KeyTyped) |
876 { | |
877 some_key_typed = TRUE; | |
878 #ifdef FEAT_RIGHTLEFT | |
879 if (cmd_hkmap) | |
880 c = hkmap(c); | |
881 # ifdef FEAT_FKMAP | |
882 if (cmd_fkmap) | |
883 c = cmdl_fkmap(c); | |
884 # endif | |
885 if (cmdmsg_rl && !KeyStuffed) | |
886 { | |
887 /* Invert horizontal movements and operations. Only when | |
888 * typed by the user directly, not when the result of a | |
889 * mapping. */ | |
890 switch (c) | |
891 { | |
892 case K_RIGHT: c = K_LEFT; break; | |
893 case K_S_RIGHT: c = K_S_LEFT; break; | |
894 case K_C_RIGHT: c = K_C_LEFT; break; | |
895 case K_LEFT: c = K_RIGHT; break; | |
896 case K_S_LEFT: c = K_S_RIGHT; break; | |
897 case K_C_LEFT: c = K_C_RIGHT; break; | |
898 } | |
899 } | |
900 #endif | |
901 } | |
902 | |
903 /* | |
904 * Ignore got_int when CTRL-C was typed here. | |
905 * Don't ignore it in :global, we really need to break then, e.g., for | |
906 * ":g/pat/normal /pat" (without the <CR>). | |
907 * Don't ignore it for the input() function. | |
908 */ | |
909 if ((c == Ctrl_C | |
910 #ifdef UNIX | |
911 || c == intr_char | |
912 #endif | |
913 ) | |
914 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
915 && firstc != '@' | |
916 #endif | |
917 #ifdef FEAT_EVAL | |
918 && !break_ctrl_c | |
919 #endif | |
920 && !global_busy) | |
921 got_int = FALSE; | |
922 | |
923 #ifdef FEAT_CMDHIST | |
924 /* free old command line when finished moving around in the history | |
925 * list */ | |
926 if (lookfor != NULL | |
180 | 927 && c != K_S_DOWN && c != K_S_UP |
230 | 928 && c != K_DOWN && c != K_UP |
7 | 929 && c != K_PAGEDOWN && c != K_PAGEUP |
930 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 931 && c != K_LEFT && c != K_RIGHT |
7 | 932 && (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
|
933 VIM_CLEAR(lookfor); |
7 | 934 #endif |
935 | |
936 /* | |
1718 | 937 * When there are matching completions to select <S-Tab> works like |
938 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 939 */ |
1718 | 940 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 941 c = Ctrl_P; |
942 | |
943 #ifdef FEAT_WILDMENU | |
944 /* Special translations for 'wildmenu' */ | |
945 if (did_wild_list && p_wmnu) | |
946 { | |
230 | 947 if (c == K_LEFT) |
7 | 948 c = Ctrl_P; |
230 | 949 else if (c == K_RIGHT) |
7 | 950 c = Ctrl_N; |
951 } | |
952 /* Hitting CR after "emenu Name.": complete submenu */ | |
953 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
954 && ccline.cmdpos > 1 | |
955 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
956 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
957 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
958 c = K_DOWN; | |
959 #endif | |
960 | |
961 /* free expanded names when finished walking through matches */ | |
962 if (xpc.xp_numfiles != -1 | |
963 && !(c == p_wc && KeyTyped) && c != p_wcm | |
964 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
965 && c != Ctrl_L) | |
966 { | |
967 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
968 did_wild_list = FALSE; | |
969 #ifdef FEAT_WILDMENU | |
230 | 970 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 971 #endif |
972 xpc.xp_context = EXPAND_NOTHING; | |
973 wim_index = 0; | |
974 #ifdef FEAT_WILDMENU | |
975 if (p_wmnu && wild_menu_showing != 0) | |
976 { | |
977 int skt = KeyTyped; | |
532 | 978 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 979 |
980 if (ccline.input_fn) | |
981 RedrawingDisabled = 0; | |
7 | 982 |
983 if (wild_menu_showing == WM_SCROLLED) | |
984 { | |
985 /* Entered command line, move it up */ | |
986 cmdline_row--; | |
987 redrawcmd(); | |
988 } | |
989 else if (save_p_ls != -1) | |
990 { | |
991 /* restore 'laststatus' and 'winminheight' */ | |
992 p_ls = save_p_ls; | |
993 p_wmh = save_p_wmh; | |
994 last_status(FALSE); | |
195 | 995 save_cmdline(&save_ccline); |
7 | 996 update_screen(VALID); /* redraw the screen NOW */ |
195 | 997 restore_cmdline(&save_ccline); |
7 | 998 redrawcmd(); |
999 save_p_ls = -1; | |
1000 } | |
1001 else | |
1002 { | |
1003 win_redraw_last_status(topframe); | |
1004 redraw_statuslines(); | |
1005 } | |
532 | 1006 KeyTyped = skt; |
1007 wild_menu_showing = 0; | |
531 | 1008 if (ccline.input_fn) |
1009 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1010 } |
1011 #endif | |
1012 } | |
1013 | |
1014 #ifdef FEAT_WILDMENU | |
1015 /* Special translations for 'wildmenu' */ | |
1016 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1017 { | |
1018 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1019 if (c == K_DOWN && ccline.cmdpos > 0 |
1020 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1021 c = p_wc; |
230 | 1022 else if (c == K_UP) |
7 | 1023 { |
1024 /* Hitting <Up>: Remove one submenu name in front of the | |
1025 * cursor */ | |
1026 int found = FALSE; | |
1027 | |
1028 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1029 i = 0; | |
1030 while (--j > 0) | |
1031 { | |
1032 /* check for start of menu name */ | |
1033 if (ccline.cmdbuff[j] == ' ' | |
1034 && ccline.cmdbuff[j - 1] != '\\') | |
1035 { | |
1036 i = j + 1; | |
1037 break; | |
1038 } | |
1039 /* check for start of submenu name */ | |
1040 if (ccline.cmdbuff[j] == '.' | |
1041 && ccline.cmdbuff[j - 1] != '\\') | |
1042 { | |
1043 if (found) | |
1044 { | |
1045 i = j + 1; | |
1046 break; | |
1047 } | |
1048 else | |
1049 found = TRUE; | |
1050 } | |
1051 } | |
1052 if (i > 0) | |
1053 cmdline_del(i); | |
1054 c = p_wc; | |
1055 xpc.xp_context = EXPAND_NOTHING; | |
1056 } | |
1057 } | |
714 | 1058 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1059 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1060 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1061 { |
1062 char_u upseg[5]; | |
1063 | |
1064 upseg[0] = PATHSEP; | |
1065 upseg[1] = '.'; | |
1066 upseg[2] = '.'; | |
1067 upseg[3] = PATHSEP; | |
1068 upseg[4] = NUL; | |
1069 | |
1318 | 1070 if (c == K_DOWN |
1071 && ccline.cmdpos > 0 | |
1072 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1073 && (ccline.cmdpos < 3 | |
1074 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1075 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1076 { | |
1077 /* go down a directory */ | |
1078 c = p_wc; | |
1079 } | |
230 | 1080 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1081 { |
1082 /* If in a direct ancestor, strip off one ../ to go down */ | |
1083 int found = FALSE; | |
1084 | |
1085 j = ccline.cmdpos; | |
1086 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1087 while (--j > i) | |
1088 { | |
39 | 1089 #ifdef FEAT_MBYTE |
1090 if (has_mbyte) | |
1091 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1092 #endif | |
7 | 1093 if (vim_ispathsep(ccline.cmdbuff[j])) |
1094 { | |
1095 found = TRUE; | |
1096 break; | |
1097 } | |
1098 } | |
1099 if (found | |
1100 && ccline.cmdbuff[j - 1] == '.' | |
1101 && ccline.cmdbuff[j - 2] == '.' | |
1102 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1103 { | |
1104 cmdline_del(j - 2); | |
1105 c = p_wc; | |
1106 } | |
1107 } | |
230 | 1108 else if (c == K_UP) |
7 | 1109 { |
1110 /* go up a directory */ | |
1111 int found = FALSE; | |
1112 | |
1113 j = ccline.cmdpos - 1; | |
1114 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1115 while (--j > i) | |
1116 { | |
1117 #ifdef FEAT_MBYTE | |
1118 if (has_mbyte) | |
1119 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1120 #endif | |
1121 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1122 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1123 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1124 ccline.cmdbuff[j + 1]) == NULL |
7 | 1125 #endif |
1126 ) | |
1127 { | |
1128 if (found) | |
1129 { | |
1130 i = j + 1; | |
1131 break; | |
1132 } | |
1133 else | |
1134 found = TRUE; | |
1135 } | |
1136 } | |
1137 | |
1138 if (!found) | |
1139 j = i; | |
1140 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1141 j += 4; | |
1142 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1143 && j == i) | |
1144 j += 3; | |
1145 else | |
1146 j = 0; | |
1147 if (j > 0) | |
1148 { | |
1149 /* TODO this is only for DOS/UNIX systems - need to put in | |
1150 * machine-specific stuff here and in upseg init */ | |
1151 cmdline_del(j); | |
1152 put_on_cmdline(upseg + 1, 3, FALSE); | |
1153 } | |
1154 else if (ccline.cmdpos > i) | |
1155 cmdline_del(i); | |
3204 | 1156 |
1157 /* Now complete in the new directory. Set KeyTyped in case the | |
1158 * Up key came from a mapping. */ | |
7 | 1159 c = p_wc; |
3204 | 1160 KeyTyped = TRUE; |
7 | 1161 } |
1162 } | |
1163 | |
1164 #endif /* FEAT_WILDMENU */ | |
1165 | |
1166 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1167 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1168 if (c == Ctrl_BSL) | |
1169 { | |
1170 ++no_mapping; | |
1171 ++allow_keys; | |
1389 | 1172 c = plain_vgetc(); |
7 | 1173 --no_mapping; |
1174 --allow_keys; | |
3859 | 1175 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1176 * is in a mapping. */ | |
1177 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1178 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1179 { |
1180 vungetc(c); | |
1181 c = Ctrl_BSL; | |
1182 } | |
1183 #ifdef FEAT_EVAL | |
1184 else if (c == 'e') | |
1185 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1186 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1187 int len; |
7 | 1188 |
1189 /* | |
1190 * Replace the command line with the result of an expression. | |
625 | 1191 * Need to save and restore the current command line, to be |
1192 * able to enter a new one... | |
7 | 1193 */ |
1194 if (ccline.cmdpos == ccline.cmdlen) | |
1195 new_cmdpos = 99999; /* keep it at the end */ | |
1196 else | |
1197 new_cmdpos = ccline.cmdpos; | |
95 | 1198 |
1199 save_cmdline(&save_ccline); | |
7 | 1200 c = get_expr_register(); |
95 | 1201 restore_cmdline(&save_ccline); |
7 | 1202 if (c == '=') |
1203 { | |
634 | 1204 /* Need to save and restore ccline. And set "textlock" |
632 | 1205 * to avoid nasty things like going to another buffer when |
1206 * evaluating an expression. */ | |
95 | 1207 save_cmdline(&save_ccline); |
634 | 1208 ++textlock; |
7 | 1209 p = get_expr_line(); |
634 | 1210 --textlock; |
95 | 1211 restore_cmdline(&save_ccline); |
2617 | 1212 |
1213 if (p != NULL) | |
7 | 1214 { |
2617 | 1215 len = (int)STRLEN(p); |
1216 if (realloc_cmdbuff(len + 1) == OK) | |
1217 { | |
1218 ccline.cmdlen = len; | |
1219 STRCPY(ccline.cmdbuff, p); | |
1220 vim_free(p); | |
1221 | |
1222 /* Restore the cursor or use the position set with | |
1223 * set_cmdline_pos(). */ | |
1224 if (new_cmdpos > ccline.cmdlen) | |
1225 ccline.cmdpos = ccline.cmdlen; | |
1226 else | |
1227 ccline.cmdpos = new_cmdpos; | |
1228 | |
1229 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1230 redrawcmd(); | |
1231 goto cmdline_changed; | |
1232 } | |
7 | 1233 } |
1234 } | |
1235 beep_flush(); | |
2636 | 1236 got_int = FALSE; /* don't abandon the command line */ |
1237 did_emsg = FALSE; | |
1238 emsg_on_display = FALSE; | |
1239 redrawcmd(); | |
1240 goto cmdline_not_changed; | |
7 | 1241 } |
1242 #endif | |
1243 else | |
1244 { | |
1245 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1246 restart_edit = 'a'; | |
1247 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1248 in history */ | |
1249 goto returncmd; /* back to Normal mode */ | |
1250 } | |
1251 } | |
1252 | |
1253 #ifdef FEAT_CMDWIN | |
1254 if (c == cedit_key || c == K_CMDWIN) | |
1255 { | |
6211 | 1256 if (ex_normal_busy == 0 && got_int == FALSE) |
1257 { | |
1258 /* | |
1259 * Open a window to edit the command line (and history). | |
1260 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1261 c = open_cmdwin(); |
6211 | 1262 some_key_typed = TRUE; |
1263 } | |
7 | 1264 } |
1265 # ifdef FEAT_DIGRAPHS | |
1266 else | |
1267 # endif | |
1268 #endif | |
1269 #ifdef FEAT_DIGRAPHS | |
1270 c = do_digraph(c); | |
1271 #endif | |
1272 | |
1273 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1274 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1275 { | |
168 | 1276 /* In Ex mode a backslash escapes a newline. */ |
1277 if (exmode_active | |
1278 && c != ESC | |
1318 | 1279 && ccline.cmdpos == ccline.cmdlen |
168 | 1280 && ccline.cmdpos > 0 |
1281 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1282 { | |
1283 if (c == K_KENTER) | |
1284 c = '\n'; | |
1285 } | |
1286 else | |
7 | 1287 { |
168 | 1288 gotesc = FALSE; /* Might have typed ESC previously, don't |
1289 truncate the cmdline now. */ | |
1290 if (ccheck_abbr(c + ABBR_OFF)) | |
1291 goto cmdline_changed; | |
1292 if (!cmd_silent) | |
1293 { | |
1294 windgoto(msg_row, 0); | |
1295 out_flush(); | |
1296 } | |
1297 break; | |
7 | 1298 } |
1299 } | |
1300 | |
1301 /* | |
1302 * Completion for 'wildchar' or 'wildcharm' key. | |
1303 * - hitting <ESC> twice means: abandon command line. | |
1304 * - wildcard expansion is only done when the 'wildchar' key is really | |
1305 * typed, not when it comes from a macro | |
1306 */ | |
1307 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1308 { | |
1309 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1310 { | |
1311 /* if 'wildmode' contains "list" may still need to list */ | |
1312 if (xpc.xp_numfiles > 1 | |
1313 && !did_wild_list | |
1314 && (wim_flags[wim_index] & WIM_LIST)) | |
1315 { | |
1316 (void)showmatches(&xpc, FALSE); | |
1317 redrawcmd(); | |
1318 did_wild_list = TRUE; | |
1319 } | |
1320 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1321 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1322 firstc != '@'); | |
7 | 1323 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1324 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1325 firstc != '@'); | |
7 | 1326 else |
1327 res = OK; /* don't insert 'wildchar' now */ | |
1328 } | |
1329 else /* typed p_wc first time */ | |
1330 { | |
1331 wim_index = 0; | |
1332 j = ccline.cmdpos; | |
1333 /* if 'wildmode' first contains "longest", get longest | |
1334 * common part */ | |
1335 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1336 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1337 firstc != '@'); | |
7 | 1338 else |
3961 | 1339 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1340 firstc != '@'); | |
7 | 1341 |
1342 /* if interrupted while completing, behave like it failed */ | |
1343 if (got_int) | |
1344 { | |
1345 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1346 got_int = FALSE; /* don't abandon the command line */ | |
1347 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1348 #ifdef FEAT_WILDMENU | |
1349 xpc.xp_context = EXPAND_NOTHING; | |
1350 #endif | |
1351 goto cmdline_changed; | |
1352 } | |
1353 | |
1354 /* when more than one match, and 'wildmode' first contains | |
1355 * "list", or no change and 'wildmode' contains "longest,list", | |
1356 * list all matches */ | |
1357 if (res == OK && xpc.xp_numfiles > 1) | |
1358 { | |
1359 /* a "longest" that didn't do anything is skipped (but not | |
1360 * "list:longest") */ | |
1361 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1362 wim_index = 1; | |
1363 if ((wim_flags[wim_index] & WIM_LIST) | |
1364 #ifdef FEAT_WILDMENU | |
1365 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1366 #endif | |
1367 ) | |
1368 { | |
1369 if (!(wim_flags[0] & WIM_LONGEST)) | |
1370 { | |
1371 #ifdef FEAT_WILDMENU | |
1372 int p_wmnu_save = p_wmnu; | |
1373 p_wmnu = 0; | |
1374 #endif | |
3961 | 1375 /* remove match */ |
1376 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1377 #ifdef FEAT_WILDMENU |
1378 p_wmnu = p_wmnu_save; | |
1379 #endif | |
1380 } | |
1381 #ifdef FEAT_WILDMENU | |
1382 (void)showmatches(&xpc, p_wmnu | |
1383 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1384 #else | |
1385 (void)showmatches(&xpc, FALSE); | |
1386 #endif | |
1387 redrawcmd(); | |
1388 did_wild_list = TRUE; | |
1389 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1390 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1391 firstc != '@'); | |
7 | 1392 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1393 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1394 firstc != '@'); | |
7 | 1395 } |
1396 else | |
6949 | 1397 vim_beep(BO_WILD); |
7 | 1398 } |
1399 #ifdef FEAT_WILDMENU | |
1400 else if (xpc.xp_numfiles == -1) | |
1401 xpc.xp_context = EXPAND_NOTHING; | |
1402 #endif | |
1403 } | |
1404 if (wim_index < 3) | |
1405 ++wim_index; | |
1406 if (c == ESC) | |
1407 gotesc = TRUE; | |
1408 if (res == OK) | |
1409 goto cmdline_changed; | |
1410 } | |
1411 | |
1412 gotesc = FALSE; | |
1413 | |
1414 /* <S-Tab> goes to last match, in a clumsy way */ | |
1415 if (c == K_S_TAB && KeyTyped) | |
1416 { | |
3961 | 1417 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1418 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1419 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1420 goto cmdline_changed; |
1421 } | |
1422 | |
1423 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1424 c = NL; | |
1425 | |
1426 do_abbr = TRUE; /* default: check for abbreviation */ | |
1427 | |
1428 /* | |
1429 * Big switch for a typed command line character. | |
1430 */ | |
1431 switch (c) | |
1432 { | |
1433 case K_BS: | |
1434 case Ctrl_H: | |
1435 case K_DEL: | |
1436 case K_KDEL: | |
1437 case Ctrl_W: | |
1438 #ifdef FEAT_FKMAP | |
1439 if (cmd_fkmap && c == K_BS) | |
1440 c = K_DEL; | |
1441 #endif | |
1442 if (c == K_KDEL) | |
1443 c = K_DEL; | |
1444 | |
1445 /* | |
1446 * delete current character is the same as backspace on next | |
1447 * character, except at end of line | |
1448 */ | |
1449 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1450 ++ccline.cmdpos; | |
1451 #ifdef FEAT_MBYTE | |
1452 if (has_mbyte && c == K_DEL) | |
1453 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1454 ccline.cmdbuff + ccline.cmdpos); | |
1455 #endif | |
1456 if (ccline.cmdpos > 0) | |
1457 { | |
1458 char_u *p; | |
1459 | |
1460 j = ccline.cmdpos; | |
1461 p = ccline.cmdbuff + j; | |
1462 #ifdef FEAT_MBYTE | |
1463 if (has_mbyte) | |
1464 { | |
1465 p = mb_prevptr(ccline.cmdbuff, p); | |
1466 if (c == Ctrl_W) | |
1467 { | |
1468 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1469 p = mb_prevptr(ccline.cmdbuff, p); | |
1470 i = mb_get_class(p); | |
1471 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1472 p = mb_prevptr(ccline.cmdbuff, p); | |
1473 if (mb_get_class(p) != i) | |
474 | 1474 p += (*mb_ptr2len)(p); |
7 | 1475 } |
1476 } | |
1477 else | |
1478 #endif | |
1479 if (c == Ctrl_W) | |
1480 { | |
1481 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1482 --p; | |
1483 i = vim_iswordc(p[-1]); | |
1484 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1485 && vim_iswordc(p[-1]) == i) | |
1486 --p; | |
1487 } | |
1488 else | |
1489 --p; | |
1490 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1491 ccline.cmdlen -= j - ccline.cmdpos; | |
1492 i = ccline.cmdpos; | |
1493 while (i < ccline.cmdlen) | |
1494 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1495 | |
1496 /* Truncate at the end, required for multi-byte chars. */ | |
1497 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1498 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1499 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1500 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1501 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
|
1502 /* 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
|
1503 * 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
|
1504 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
|
1505 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1506 #endif |
7 | 1507 redrawcmd(); |
1508 } | |
1509 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1510 && ccline.cmdprompt == NULL && indent == 0) | |
1511 { | |
1512 /* In ex and debug mode it doesn't make sense to return. */ | |
1513 if (exmode_active | |
1514 #ifdef FEAT_EVAL | |
1515 || ccline.cmdfirstc == '>' | |
1516 #endif | |
1517 ) | |
1518 goto cmdline_not_changed; | |
1519 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1520 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1521 if (!cmd_silent) |
1522 { | |
1523 #ifdef FEAT_RIGHTLEFT | |
1524 if (cmdmsg_rl) | |
1525 msg_col = Columns; | |
1526 else | |
1527 #endif | |
1528 msg_col = 0; | |
1529 msg_putchar(' '); /* delete ':' */ | |
1530 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1531 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1532 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
|
1533 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
|
1534 #endif |
7 | 1535 redraw_cmdline = TRUE; |
1536 goto returncmd; /* back to cmd mode */ | |
1537 } | |
1538 goto cmdline_changed; | |
1539 | |
1540 case K_INS: | |
1541 case K_KINS: | |
1542 #ifdef FEAT_FKMAP | |
1543 /* if Farsi mode set, we are in reverse insert mode - | |
1544 Do not change the mode */ | |
1545 if (cmd_fkmap) | |
1546 beep_flush(); | |
1547 else | |
1548 #endif | |
1549 ccline.overstrike = !ccline.overstrike; | |
1550 #ifdef CURSOR_SHAPE | |
1551 ui_cursor_shape(); /* may show different cursor shape */ | |
1552 #endif | |
1553 goto cmdline_not_changed; | |
1554 | |
1555 case Ctrl_HAT: | |
782 | 1556 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1557 { |
1558 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1559 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1560 #ifdef HAVE_INPUT_METHOD |
7 | 1561 im_set_active(FALSE); /* Disable input method */ |
1562 #endif | |
1563 if (b_im_ptr != NULL) | |
1564 { | |
1565 if (State & LANGMAP) | |
1566 *b_im_ptr = B_IMODE_LMAP; | |
1567 else | |
1568 *b_im_ptr = B_IMODE_NONE; | |
1569 } | |
1570 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1571 #ifdef HAVE_INPUT_METHOD |
7 | 1572 else |
1573 { | |
1574 /* There are no ":lmap" mappings, toggle IM. When | |
1575 * 'imdisable' is set don't try getting the status, it's | |
1576 * always off. */ | |
1577 if ((p_imdisable && b_im_ptr != NULL) | |
1578 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1579 { | |
1580 im_set_active(FALSE); /* Disable input method */ | |
1581 if (b_im_ptr != NULL) | |
1582 *b_im_ptr = B_IMODE_NONE; | |
1583 } | |
1584 else | |
1585 { | |
1586 im_set_active(TRUE); /* Enable input method */ | |
1587 if (b_im_ptr != NULL) | |
1588 *b_im_ptr = B_IMODE_IM; | |
1589 } | |
1590 } | |
1591 #endif | |
1592 if (b_im_ptr != NULL) | |
1593 { | |
1594 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1595 set_iminsert_global(); | |
1596 else | |
1597 set_imsearch_global(); | |
1598 } | |
1599 #ifdef CURSOR_SHAPE | |
1600 ui_cursor_shape(); /* may show different cursor shape */ | |
1601 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1602 #if defined(FEAT_KEYMAP) |
7 | 1603 /* Show/unshow value of 'keymap' in status lines later. */ |
1604 status_redraw_curbuf(); | |
1605 #endif | |
1606 goto cmdline_not_changed; | |
1607 | |
1608 /* case '@': only in very old vi */ | |
1609 case Ctrl_U: | |
1610 /* delete all characters left of the cursor */ | |
1611 j = ccline.cmdpos; | |
1612 ccline.cmdlen -= j; | |
1613 i = ccline.cmdpos = 0; | |
1614 while (i < ccline.cmdlen) | |
1615 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1616 /* Truncate at the end, required for multi-byte chars. */ | |
1617 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1618 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1619 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
|
1620 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
|
1621 #endif |
7 | 1622 redrawcmd(); |
1623 goto cmdline_changed; | |
1624 | |
1625 #ifdef FEAT_CLIPBOARD | |
1626 case Ctrl_Y: | |
1627 /* Copy the modeless selection, if there is one. */ | |
1628 if (clip_star.state != SELECT_CLEARED) | |
1629 { | |
1630 if (clip_star.state == SELECT_DONE) | |
1631 clip_copy_modeless_selection(TRUE); | |
1632 goto cmdline_not_changed; | |
1633 } | |
1634 break; | |
1635 #endif | |
1636 | |
1637 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1638 case Ctrl_C: | |
571 | 1639 /* In exmode it doesn't make sense to return. Except when |
161 | 1640 * ":normal" runs out of characters. */ |
1641 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1642 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1643 goto cmdline_not_changed; |
1644 | |
1645 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1646 putting it in history */ | |
1647 goto returncmd; /* back to cmd mode */ | |
1648 | |
1649 case Ctrl_R: /* insert register */ | |
1650 #ifdef USE_ON_FLY_SCROLL | |
1651 dont_scroll = TRUE; /* disallow scrolling here */ | |
1652 #endif | |
1653 putcmdline('"', TRUE); | |
1654 ++no_mapping; | |
1389 | 1655 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1656 if (i == Ctrl_O) |
1657 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1658 if (i == Ctrl_R) | |
1389 | 1659 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
|
1660 extra_char = NUL; |
7 | 1661 --no_mapping; |
1662 #ifdef FEAT_EVAL | |
1663 /* | |
1664 * Insert the result of an expression. | |
1665 * Need to save the current command line, to be able to enter | |
1666 * a new one... | |
1667 */ | |
1668 new_cmdpos = -1; | |
1669 if (c == '=') | |
1670 { | |
1671 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1672 { | |
1673 beep_flush(); | |
1674 c = ESC; | |
1675 } | |
1676 else | |
1677 { | |
95 | 1678 save_cmdline(&save_ccline); |
7 | 1679 c = get_expr_register(); |
95 | 1680 restore_cmdline(&save_ccline); |
7 | 1681 } |
1682 } | |
1683 #endif | |
1684 if (c != ESC) /* use ESC to cancel inserting register */ | |
1685 { | |
1015 | 1686 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1687 |
613 | 1688 #ifdef FEAT_EVAL |
606 | 1689 /* When there was a serious error abort getting the |
1690 * command line. */ | |
1691 if (aborting()) | |
1692 { | |
1693 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1694 putting it in history */ | |
1695 goto returncmd; /* back to cmd mode */ | |
1696 } | |
613 | 1697 #endif |
7 | 1698 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1699 #ifdef FEAT_EVAL | |
1700 if (new_cmdpos >= 0) | |
1701 { | |
1702 /* set_cmdline_pos() was used */ | |
1703 if (new_cmdpos > ccline.cmdlen) | |
1704 ccline.cmdpos = ccline.cmdlen; | |
1705 else | |
1706 ccline.cmdpos = new_cmdpos; | |
1707 } | |
1708 #endif | |
1709 } | |
1710 redrawcmd(); | |
1711 goto cmdline_changed; | |
1712 | |
1713 case Ctrl_D: | |
1714 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1715 break; /* Use ^D as normal char instead */ | |
1716 | |
1717 redrawcmd(); | |
1718 continue; /* don't do incremental search now */ | |
1719 | |
1720 case K_RIGHT: | |
1721 case K_S_RIGHT: | |
1722 case K_C_RIGHT: | |
1723 do | |
1724 { | |
1725 if (ccline.cmdpos >= ccline.cmdlen) | |
1726 break; | |
1727 i = cmdline_charsize(ccline.cmdpos); | |
1728 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1729 break; | |
1730 ccline.cmdspos += i; | |
1731 #ifdef FEAT_MBYTE | |
1732 if (has_mbyte) | |
474 | 1733 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1734 + ccline.cmdpos); |
1735 else | |
1736 #endif | |
1737 ++ccline.cmdpos; | |
1738 } | |
180 | 1739 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1740 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1741 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1742 #ifdef FEAT_MBYTE | |
1743 if (has_mbyte) | |
1744 set_cmdspos_cursor(); | |
1745 #endif | |
1746 goto cmdline_not_changed; | |
1747 | |
1748 case K_LEFT: | |
1749 case K_S_LEFT: | |
1750 case K_C_LEFT: | |
1456 | 1751 if (ccline.cmdpos == 0) |
1752 goto cmdline_not_changed; | |
7 | 1753 do |
1754 { | |
1755 --ccline.cmdpos; | |
1756 #ifdef FEAT_MBYTE | |
1757 if (has_mbyte) /* move to first byte of char */ | |
1758 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1759 ccline.cmdbuff + ccline.cmdpos); | |
1760 #endif | |
1761 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1762 } | |
1456 | 1763 while (ccline.cmdpos > 0 |
1764 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1765 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1766 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1767 #ifdef FEAT_MBYTE | |
1768 if (has_mbyte) | |
1769 set_cmdspos_cursor(); | |
1770 #endif | |
1771 goto cmdline_not_changed; | |
1772 | |
1773 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
|
1774 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1775 goto cmdline_not_changed; |
7 | 1776 |
625 | 1777 #ifdef FEAT_GUI_W32 |
1778 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1779 * cancelled. */ | |
1780 case K_F4: | |
1781 if (mod_mask == MOD_MASK_ALT) | |
1782 { | |
1783 redrawcmd(); /* somehow the cmdline is cleared */ | |
1784 goto cmdline_not_changed; | |
1785 } | |
1786 break; | |
1787 #endif | |
1788 | |
7 | 1789 #ifdef FEAT_MOUSE |
1790 case K_MIDDLEDRAG: | |
1791 case K_MIDDLERELEASE: | |
1792 goto cmdline_not_changed; /* Ignore mouse */ | |
1793 | |
1794 case K_MIDDLEMOUSE: | |
1795 # ifdef FEAT_GUI | |
1796 /* When GUI is active, also paste when 'mouse' is empty */ | |
1797 if (!gui.in_use) | |
1798 # endif | |
1799 if (!mouse_has(MOUSE_COMMAND)) | |
1800 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1801 # ifdef FEAT_CLIPBOARD |
7 | 1802 if (clip_star.available) |
1015 | 1803 cmdline_paste('*', TRUE, TRUE); |
7 | 1804 else |
692 | 1805 # endif |
1015 | 1806 cmdline_paste(0, TRUE, TRUE); |
7 | 1807 redrawcmd(); |
1808 goto cmdline_changed; | |
1809 | |
692 | 1810 # ifdef FEAT_DND |
7 | 1811 case K_DROP: |
1015 | 1812 cmdline_paste('~', TRUE, FALSE); |
7 | 1813 redrawcmd(); |
1814 goto cmdline_changed; | |
692 | 1815 # endif |
7 | 1816 |
1817 case K_LEFTDRAG: | |
1818 case K_LEFTRELEASE: | |
1819 case K_RIGHTDRAG: | |
1820 case K_RIGHTRELEASE: | |
1821 /* Ignore drag and release events when the button-down wasn't | |
1822 * seen before. */ | |
1823 if (ignore_drag_release) | |
1824 goto cmdline_not_changed; | |
1825 /* FALLTHROUGH */ | |
1826 case K_LEFTMOUSE: | |
1827 case K_RIGHTMOUSE: | |
1828 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1829 ignore_drag_release = TRUE; | |
1830 else | |
1831 ignore_drag_release = FALSE; | |
1832 # ifdef FEAT_GUI | |
1833 /* When GUI is active, also move when 'mouse' is empty */ | |
1834 if (!gui.in_use) | |
1835 # endif | |
1836 if (!mouse_has(MOUSE_COMMAND)) | |
1837 goto cmdline_not_changed; /* Ignore mouse */ | |
1838 # ifdef FEAT_CLIPBOARD | |
1839 if (mouse_row < cmdline_row && clip_star.available) | |
1840 { | |
1841 int button, is_click, is_drag; | |
1842 | |
1843 /* | |
1844 * Handle modeless selection. | |
1845 */ | |
1846 button = get_mouse_button(KEY2TERMCAP1(c), | |
1847 &is_click, &is_drag); | |
1848 if (mouse_model_popup() && button == MOUSE_LEFT | |
1849 && (mod_mask & MOD_MASK_SHIFT)) | |
1850 { | |
1851 /* Translate shift-left to right button. */ | |
1852 button = MOUSE_RIGHT; | |
1853 mod_mask &= ~MOD_MASK_SHIFT; | |
1854 } | |
1855 clip_modeless(button, is_click, is_drag); | |
1856 goto cmdline_not_changed; | |
1857 } | |
1858 # endif | |
1859 | |
1860 set_cmdspos(); | |
1861 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1862 ++ccline.cmdpos) | |
1863 { | |
1864 i = cmdline_charsize(ccline.cmdpos); | |
1865 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1866 && mouse_col < ccline.cmdspos % Columns + i) | |
1867 break; | |
692 | 1868 # ifdef FEAT_MBYTE |
7 | 1869 if (has_mbyte) |
1870 { | |
1871 /* Count ">" for double-wide char that doesn't fit. */ | |
1872 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1873 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1874 + ccline.cmdpos) - 1; |
1875 } | |
692 | 1876 # endif |
7 | 1877 ccline.cmdspos += i; |
1878 } | |
1879 goto cmdline_not_changed; | |
1880 | |
1881 /* Mouse scroll wheel: ignored here */ | |
1882 case K_MOUSEDOWN: | |
1883 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1884 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1885 case K_MOUSERIGHT: |
7 | 1886 /* Alternate buttons ignored here */ |
1887 case K_X1MOUSE: | |
1888 case K_X1DRAG: | |
1889 case K_X1RELEASE: | |
1890 case K_X2MOUSE: | |
1891 case K_X2DRAG: | |
1892 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1893 case K_MOUSEMOVE: |
7 | 1894 goto cmdline_not_changed; |
1895 | |
1896 #endif /* FEAT_MOUSE */ | |
1897 | |
1898 #ifdef FEAT_GUI | |
1899 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
1900 case K_LEFTRELEASE_NM: | |
1901 goto cmdline_not_changed; | |
1902 | |
1903 case K_VER_SCROLLBAR: | |
540 | 1904 if (msg_scrolled == 0) |
7 | 1905 { |
1906 gui_do_scroll(); | |
1907 redrawcmd(); | |
1908 } | |
1909 goto cmdline_not_changed; | |
1910 | |
1911 case K_HOR_SCROLLBAR: | |
540 | 1912 if (msg_scrolled == 0) |
7 | 1913 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1914 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 1915 redrawcmd(); |
1916 } | |
1917 goto cmdline_not_changed; | |
1918 #endif | |
692 | 1919 #ifdef FEAT_GUI_TABLINE |
1920 case K_TABLINE: | |
1921 case K_TABMENU: | |
1922 /* Don't want to change any tabs here. Make sure the same tab | |
1923 * is still selected. */ | |
1924 if (gui_use_tabline()) | |
1925 gui_mch_set_curtab(tabpage_index(curtab)); | |
1926 goto cmdline_not_changed; | |
1927 #endif | |
1928 | |
7 | 1929 case K_SELECT: /* end of Select mode mapping - ignore */ |
1930 goto cmdline_not_changed; | |
1931 | |
1932 case Ctrl_B: /* begin of command line */ | |
1933 case K_HOME: | |
1934 case K_KHOME: | |
1935 case K_S_HOME: | |
1936 case K_C_HOME: | |
1937 ccline.cmdpos = 0; | |
1938 set_cmdspos(); | |
1939 goto cmdline_not_changed; | |
1940 | |
1941 case Ctrl_E: /* end of command line */ | |
1942 case K_END: | |
1943 case K_KEND: | |
1944 case K_S_END: | |
1945 case K_C_END: | |
1946 ccline.cmdpos = ccline.cmdlen; | |
1947 set_cmdspos_cursor(); | |
1948 goto cmdline_not_changed; | |
1949 | |
1950 case Ctrl_A: /* all matches */ | |
3961 | 1951 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 1952 break; |
1953 goto cmdline_changed; | |
1954 | |
772 | 1955 case Ctrl_L: |
1956 #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
|
1957 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 1958 goto cmdline_not_changed; |
1959 #endif | |
1960 | |
1961 /* completion: longest common part */ | |
3961 | 1962 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 1963 break; |
1964 goto cmdline_changed; | |
1965 | |
1966 case Ctrl_N: /* next match */ | |
1967 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
1968 if (xpc.xp_numfiles > 0) |
7 | 1969 { |
3961 | 1970 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
1971 0, firstc != '@') == FAIL) | |
7 | 1972 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1973 goto cmdline_not_changed; |
7 | 1974 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
1975 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
1976 /* FALLTHROUGH */ |
7 | 1977 case K_UP: |
1978 case K_DOWN: | |
1979 case K_S_UP: | |
1980 case K_S_DOWN: | |
1981 case K_PAGEUP: | |
1982 case K_KPAGEUP: | |
1983 case K_PAGEDOWN: | |
1984 case K_KPAGEDOWN: | |
1985 if (hislen == 0 || firstc == NUL) /* no history */ | |
1986 goto cmdline_not_changed; | |
1987 | |
1988 i = hiscnt; | |
1989 | |
1990 /* save current command string so it can be restored later */ | |
1991 if (lookfor == NULL) | |
1992 { | |
1993 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
1994 goto cmdline_not_changed; | |
1995 lookfor[ccline.cmdpos] = NUL; | |
1996 } | |
1997 | |
1998 j = (int)STRLEN(lookfor); | |
1999 for (;;) | |
2000 { | |
2001 /* one step backwards */ | |
230 | 2002 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2003 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2004 { |
2005 if (hiscnt == hislen) /* first time */ | |
2006 hiscnt = hisidx[histype]; | |
2007 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2008 hiscnt = hislen - 1; | |
2009 else if (hiscnt != hisidx[histype] + 1) | |
2010 --hiscnt; | |
2011 else /* at top of list */ | |
2012 { | |
2013 hiscnt = i; | |
2014 break; | |
2015 } | |
2016 } | |
2017 else /* one step forwards */ | |
2018 { | |
2019 /* on last entry, clear the line */ | |
2020 if (hiscnt == hisidx[histype]) | |
2021 { | |
2022 hiscnt = hislen; | |
2023 break; | |
2024 } | |
2025 | |
2026 /* not on a history line, nothing to do */ | |
2027 if (hiscnt == hislen) | |
2028 break; | |
2029 if (hiscnt == hislen - 1) /* wrap around */ | |
2030 hiscnt = 0; | |
2031 else | |
2032 ++hiscnt; | |
2033 } | |
2034 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2035 { | |
2036 hiscnt = i; | |
2037 break; | |
2038 } | |
230 | 2039 if ((c != K_UP && c != K_DOWN) |
180 | 2040 || hiscnt == i |
7 | 2041 || STRNCMP(history[histype][hiscnt].hisstr, |
2042 lookfor, (size_t)j) == 0) | |
2043 break; | |
2044 } | |
2045 | |
2046 if (hiscnt != i) /* jumped to other entry */ | |
2047 { | |
2048 char_u *p; | |
2049 int len; | |
2050 int old_firstc; | |
2051 | |
2052 vim_free(ccline.cmdbuff); | |
1718 | 2053 xpc.xp_context = EXPAND_NOTHING; |
7 | 2054 if (hiscnt == hislen) |
2055 p = lookfor; /* back to the old one */ | |
2056 else | |
2057 p = history[histype][hiscnt].hisstr; | |
2058 | |
2059 if (histype == HIST_SEARCH | |
2060 && p != lookfor | |
2061 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2062 { | |
2063 /* Correct for the separator character used when | |
2064 * adding the history entry vs the one used now. | |
2065 * First loop: count length. | |
2066 * Second loop: copy the characters. */ | |
2067 for (i = 0; i <= 1; ++i) | |
2068 { | |
2069 len = 0; | |
2070 for (j = 0; p[j] != NUL; ++j) | |
2071 { | |
2072 /* Replace old sep with new sep, unless it is | |
2073 * escaped. */ | |
2074 if (p[j] == old_firstc | |
2075 && (j == 0 || p[j - 1] != '\\')) | |
2076 { | |
2077 if (i > 0) | |
2078 ccline.cmdbuff[len] = firstc; | |
2079 } | |
2080 else | |
2081 { | |
2082 /* Escape new sep, unless it is already | |
2083 * escaped. */ | |
2084 if (p[j] == firstc | |
2085 && (j == 0 || p[j - 1] != '\\')) | |
2086 { | |
2087 if (i > 0) | |
2088 ccline.cmdbuff[len] = '\\'; | |
2089 ++len; | |
2090 } | |
2091 if (i > 0) | |
2092 ccline.cmdbuff[len] = p[j]; | |
2093 } | |
2094 ++len; | |
2095 } | |
2096 if (i == 0) | |
2097 { | |
2098 alloc_cmdbuff(len); | |
2099 if (ccline.cmdbuff == NULL) | |
2100 goto returncmd; | |
2101 } | |
2102 } | |
2103 ccline.cmdbuff[len] = NUL; | |
2104 } | |
2105 else | |
2106 { | |
2107 alloc_cmdbuff((int)STRLEN(p)); | |
2108 if (ccline.cmdbuff == NULL) | |
2109 goto returncmd; | |
2110 STRCPY(ccline.cmdbuff, p); | |
2111 } | |
2112 | |
2113 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2114 redrawcmd(); | |
2115 goto cmdline_changed; | |
2116 } | |
2117 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2118 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2119 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2120 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2121 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2122 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2123 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
|
2124 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
|
2125 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
|
2126 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2127 break; |
7 | 2128 #endif |
2129 | |
2130 case Ctrl_V: | |
2131 case Ctrl_Q: | |
2132 #ifdef FEAT_MOUSE | |
2133 ignore_drag_release = TRUE; | |
2134 #endif | |
2135 putcmdline('^', TRUE); | |
2136 c = get_literal(); /* get next (two) character(s) */ | |
2137 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
|
2138 extra_char = NUL; |
7 | 2139 #ifdef FEAT_MBYTE |
2140 /* may need to remove ^ when composing char was typed */ | |
2141 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2142 { | |
2143 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2144 msg_putchar(' '); | |
2145 cursorcmd(); | |
2146 } | |
2147 #endif | |
2148 break; | |
2149 | |
2150 #ifdef FEAT_DIGRAPHS | |
2151 case Ctrl_K: | |
2152 #ifdef FEAT_MOUSE | |
2153 ignore_drag_release = TRUE; | |
2154 #endif | |
2155 putcmdline('?', TRUE); | |
2156 #ifdef USE_ON_FLY_SCROLL | |
2157 dont_scroll = TRUE; /* disallow scrolling here */ | |
2158 #endif | |
2159 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
|
2160 extra_char = NUL; |
7 | 2161 if (c != NUL) |
2162 break; | |
2163 | |
2164 redrawcmd(); | |
2165 goto cmdline_not_changed; | |
2166 #endif /* FEAT_DIGRAPHS */ | |
2167 | |
2168 #ifdef FEAT_RIGHTLEFT | |
2169 case Ctrl__: /* CTRL-_: switch language mode */ | |
2170 if (!p_ari) | |
2171 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2172 # ifdef FEAT_FKMAP |
7 | 2173 if (p_altkeymap) |
2174 { | |
2175 cmd_fkmap = !cmd_fkmap; | |
2176 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2177 ccline.overstrike = FALSE; | |
2178 } | |
2179 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2180 # endif |
7 | 2181 cmd_hkmap = !cmd_hkmap; |
2182 goto cmdline_not_changed; | |
2183 #endif | |
2184 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2185 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
|
2186 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
|
2187 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
|
2188 |
7 | 2189 default: |
2190 #ifdef UNIX | |
2191 if (c == intr_char) | |
2192 { | |
2193 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2194 putting it in history */ | |
2195 goto returncmd; /* back to Normal mode */ | |
2196 } | |
2197 #endif | |
2198 /* | |
2199 * Normal character with no special meaning. Just set mod_mask | |
2200 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2201 * the string <S-Space>. This should only happen after ^V. | |
2202 */ | |
2203 if (!IS_SPECIAL(c)) | |
2204 mod_mask = 0x0; | |
2205 break; | |
2206 } | |
2207 /* | |
2208 * End of switch on command line character. | |
2209 * We come here if we have a normal character. | |
2210 */ | |
2211 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2212 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2213 #ifdef FEAT_MBYTE |
2214 /* Add ABBR_OFF for characters above 0x100, this is | |
2215 * what check_abbr() expects. */ | |
2216 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2217 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2218 c) || c == Ctrl_RSB)) |
7 | 2219 goto cmdline_changed; |
2220 | |
2221 /* | |
2222 * put the character in the command line | |
2223 */ | |
2224 if (IS_SPECIAL(c) || mod_mask != 0) | |
2225 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2226 else | |
2227 { | |
2228 #ifdef FEAT_MBYTE | |
2229 if (has_mbyte) | |
2230 { | |
2231 j = (*mb_char2bytes)(c, IObuff); | |
2232 IObuff[j] = NUL; /* exclude composing chars */ | |
2233 put_on_cmdline(IObuff, j, TRUE); | |
2234 } | |
2235 else | |
2236 #endif | |
2237 { | |
2238 IObuff[0] = c; | |
2239 put_on_cmdline(IObuff, 1, TRUE); | |
2240 } | |
2241 } | |
2242 goto cmdline_changed; | |
2243 | |
2244 /* | |
2245 * This part implements incremental searches for "/" and "?" | |
2246 * Jump to cmdline_not_changed when a character has been read but the command | |
2247 * line did not change. Then we only search and redraw if something changed in | |
2248 * the past. | |
2249 * Jump to cmdline_changed when the command line did change. | |
2250 * (Sorry for the goto's, I know it is ugly). | |
2251 */ | |
2252 cmdline_not_changed: | |
2253 #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
|
2254 if (!is_state.incsearch_postponed) |
7 | 2255 continue; |
2256 #endif | |
2257 | |
2258 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
|
2259 /* 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
|
2260 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
|
2261 |
7 | 2262 #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
|
2263 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2264 #endif |
2265 | |
2266 #ifdef FEAT_RIGHTLEFT | |
2267 if (cmdmsg_rl | |
2268 # ifdef FEAT_ARABIC | |
534 | 2269 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2270 # endif |
2271 ) | |
2272 /* Always redraw the whole command line to fix shaping and | |
3374 | 2273 * right-left typing. Not efficient, but it works. |
2274 * Do it only when there are no characters left to read | |
2275 * to avoid useless intermediate redraws. */ | |
2276 if (vpeekc() == NUL) | |
2277 redrawcmd(); | |
7 | 2278 #endif |
2279 } | |
2280 | |
2281 returncmd: | |
2282 | |
2283 #ifdef FEAT_RIGHTLEFT | |
2284 cmdmsg_rl = FALSE; | |
2285 #endif | |
2286 | |
2287 #ifdef FEAT_FKMAP | |
2288 cmd_fkmap = 0; | |
2289 #endif | |
2290 | |
2291 ExpandCleanup(&xpc); | |
1718 | 2292 ccline.xpc = NULL; |
7 | 2293 |
2294 #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
|
2295 finish_incsearch_highlighting(gotesc, &is_state); |
7 | 2296 #endif |
2297 | |
2298 if (ccline.cmdbuff != NULL) | |
2299 { | |
2300 /* | |
2301 * Put line in history buffer (":" and "=" only when it was typed). | |
2302 */ | |
2303 #ifdef FEAT_CMDHIST | |
2304 if (ccline.cmdlen && firstc != NUL | |
2305 && (some_key_typed || histype == HIST_SEARCH)) | |
2306 { | |
2307 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2308 histype == HIST_SEARCH ? firstc : NUL); | |
2309 if (firstc == ':') | |
2310 { | |
2311 vim_free(new_last_cmdline); | |
2312 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2313 } | |
2314 } | |
2315 #endif | |
2316 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2317 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
|
2318 abandon_cmdline(); |
7 | 2319 } |
2320 | |
2321 /* | |
2322 * If the screen was shifted up, redraw the whole screen (later). | |
2323 * If the line is too long, clear it, so ruler and shown command do | |
2324 * not get printed in the middle of it. | |
2325 */ | |
2326 msg_check(); | |
2327 msg_scroll = save_msg_scroll; | |
2328 redir_off = FALSE; | |
2329 | |
2330 /* When the command line was typed, no need for a wait-return prompt. */ | |
2331 if (some_key_typed) | |
2332 need_wait_return = FALSE; | |
2333 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2334 /* 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
|
2335 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
|
2336 |
7 | 2337 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2338 #ifdef HAVE_INPUT_METHOD |
7 | 2339 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2340 im_save_status(b_im_ptr); | |
2341 im_set_active(FALSE); | |
2342 #endif | |
2343 #ifdef FEAT_MOUSE | |
2344 setmouse(); | |
2345 #endif | |
2346 #ifdef CURSOR_SHAPE | |
2347 ui_cursor_shape(); /* may show different cursor shape */ | |
2348 #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
|
2349 sb_text_end_cmdline(); |
7 | 2350 |
95 | 2351 { |
2352 char_u *p = ccline.cmdbuff; | |
2353 | |
2354 /* Make ccline empty, getcmdline() may try to use it. */ | |
2355 ccline.cmdbuff = NULL; | |
2356 return p; | |
2357 } | |
7 | 2358 } |
2359 | |
2360 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2361 /* | |
2362 * Get a command line with a prompt. | |
2363 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2364 * f_input() when evaluating an expression from CTRL-R =). | |
2365 * Returns the command line in allocated memory, or NULL. | |
2366 */ | |
2367 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2368 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2369 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2370 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2371 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2372 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2373 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2374 { |
2375 char_u *s; | |
2376 struct cmdline_info save_ccline; | |
2377 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
|
2378 int msg_silent_save = msg_silent; |
7 | 2379 |
95 | 2380 save_cmdline(&save_ccline); |
7 | 2381 ccline.cmdprompt = prompt; |
2382 ccline.cmdattr = attr; | |
531 | 2383 # ifdef FEAT_EVAL |
2384 ccline.xp_context = xp_context; | |
2385 ccline.xp_arg = xp_arg; | |
2386 ccline.input_fn = (firstc == '@'); | |
2387 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2388 msg_silent = 0; |
7 | 2389 s = getcmdline(firstc, 1L, 0); |
95 | 2390 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2391 msg_silent = msg_silent_save; |
3020 | 2392 /* Restore msg_col, the prompt from input() may have changed it. |
2393 * But only if called recursively and the commandline is therefore being | |
2394 * restored to an old one; if not, the input() prompt stays on the screen, | |
2395 * so we need its modified msg_col left intact. */ | |
2396 if (ccline.cmdbuff != NULL) | |
2397 msg_col = msg_col_save; | |
7 | 2398 |
2399 return s; | |
2400 } | |
2401 #endif | |
2402 | |
632 | 2403 /* |
634 | 2404 * Return TRUE when the text must not be changed and we can't switch to |
2405 * another window or buffer. Used when editing the command line, evaluating | |
2406 * 'balloonexpr', etc. | |
632 | 2407 */ |
2408 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2409 text_locked(void) |
632 | 2410 { |
2411 #ifdef FEAT_CMDWIN | |
2412 if (cmdwin_type != 0) | |
2413 return TRUE; | |
2414 #endif | |
634 | 2415 return textlock != 0; |
632 | 2416 } |
2417 | |
2418 /* | |
2419 * Give an error message for a command that isn't allowed while the cmdline | |
2420 * window is open or editing the cmdline in another way. | |
2421 */ | |
2422 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2423 text_locked_msg(void) |
632 | 2424 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2425 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2426 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2427 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2428 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2429 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2430 { |
632 | 2431 #ifdef FEAT_CMDWIN |
2432 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2433 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2434 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2435 return e_secure; |
632 | 2436 } |
2437 | |
819 | 2438 /* |
1834 | 2439 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2440 * and give an error message. | |
819 | 2441 */ |
2442 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2443 curbuf_locked(void) |
819 | 2444 { |
2445 if (curbuf_lock > 0) | |
2446 { | |
2447 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2448 return TRUE; | |
2449 } | |
1834 | 2450 return allbuf_locked(); |
2451 } | |
2452 | |
2453 /* | |
2454 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2455 * message. | |
2456 */ | |
2457 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2458 allbuf_locked(void) |
1834 | 2459 { |
2460 if (allbuf_lock > 0) | |
2461 { | |
2462 EMSG(_("E811: Not allowed to change buffer information now")); | |
2463 return TRUE; | |
2464 } | |
819 | 2465 return FALSE; |
2466 } | |
2467 | |
7 | 2468 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2469 cmdline_charsize(int idx) |
7 | 2470 { |
2471 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2472 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2473 return 1; | |
2474 #endif | |
2475 return ptr2cells(ccline.cmdbuff + idx); | |
2476 } | |
2477 | |
2478 /* | |
2479 * Compute the offset of the cursor on the command line for the prompt and | |
2480 * indent. | |
2481 */ | |
2482 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2483 set_cmdspos(void) |
7 | 2484 { |
531 | 2485 if (ccline.cmdfirstc != NUL) |
7 | 2486 ccline.cmdspos = 1 + ccline.cmdindent; |
2487 else | |
2488 ccline.cmdspos = 0 + ccline.cmdindent; | |
2489 } | |
2490 | |
2491 /* | |
2492 * Compute the screen position for the cursor on the command line. | |
2493 */ | |
2494 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2495 set_cmdspos_cursor(void) |
7 | 2496 { |
2497 int i, m, c; | |
2498 | |
2499 set_cmdspos(); | |
2500 if (KeyTyped) | |
534 | 2501 { |
7 | 2502 m = Columns * Rows; |
534 | 2503 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2504 m = MAXCOL; | |
2505 } | |
7 | 2506 else |
2507 m = MAXCOL; | |
2508 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2509 { | |
2510 c = cmdline_charsize(i); | |
2511 #ifdef FEAT_MBYTE | |
2512 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2513 if (has_mbyte) | |
2514 correct_cmdspos(i, c); | |
2515 #endif | |
1612 | 2516 /* If the cmdline doesn't fit, show cursor on last visible char. |
2517 * Don't move the cursor itself, so we can still append. */ | |
7 | 2518 if ((ccline.cmdspos += c) >= m) |
2519 { | |
2520 ccline.cmdspos -= c; | |
2521 break; | |
2522 } | |
2523 #ifdef FEAT_MBYTE | |
2524 if (has_mbyte) | |
474 | 2525 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2526 #endif |
2527 } | |
2528 } | |
2529 | |
2530 #ifdef FEAT_MBYTE | |
2531 /* | |
2532 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2533 * character that doesn't fit, so that a ">" must be displayed. | |
2534 */ | |
2535 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2536 correct_cmdspos(int idx, int cells) |
7 | 2537 { |
474 | 2538 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2539 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2540 && ccline.cmdspos % Columns + cells > Columns) | |
2541 ccline.cmdspos++; | |
2542 } | |
2543 #endif | |
2544 | |
2545 /* | |
2546 * Get an Ex command line for the ":" command. | |
2547 */ | |
2548 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2549 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2550 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2551 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2552 int indent) /* indent for inside conditionals */ |
7 | 2553 { |
2554 /* When executing a register, remove ':' that's in front of each line. */ | |
2555 if (exec_from_reg && vpeekc() == ':') | |
2556 (void)vgetc(); | |
2557 return getcmdline(c, 1L, indent); | |
2558 } | |
2559 | |
2560 /* | |
2561 * Get an Ex command line for Ex mode. | |
2562 * In Ex mode we only use the OS supplied line editing features and no | |
2563 * mappings or abbreviations. | |
168 | 2564 * Returns a string in allocated memory or NULL. |
7 | 2565 */ |
2566 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2567 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2568 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2569 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2570 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2571 int indent) /* indent for inside conditionals */ |
7 | 2572 { |
168 | 2573 garray_T line_ga; |
2574 char_u *pend; | |
2575 int startcol = 0; | |
1329 | 2576 int c1 = 0; |
168 | 2577 int escaped = FALSE; /* CTRL-V typed */ |
2578 int vcol = 0; | |
2579 char_u *p; | |
1329 | 2580 int prev_char; |
5966 | 2581 int len; |
7 | 2582 |
2583 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2584 * confuses the system function that computes tabstops. */ | |
2585 cursor_on(); | |
2586 | |
2587 /* always start in column 0; write a newline if necessary */ | |
2588 compute_cmdrow(); | |
168 | 2589 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2590 msg_putchar('\n'); |
168 | 2591 if (promptc == ':') |
7 | 2592 { |
164 | 2593 /* indent that is only displayed, not in the line itself */ |
168 | 2594 if (p_prompt) |
2595 msg_putchar(':'); | |
7 | 2596 while (indent-- > 0) |
2597 msg_putchar(' '); | |
2598 startcol = msg_col; | |
2599 } | |
2600 | |
2601 ga_init2(&line_ga, 1, 30); | |
2602 | |
164 | 2603 /* autoindent for :insert and :append is in the line itself */ |
168 | 2604 if (promptc <= 0) |
164 | 2605 { |
2606 vcol = indent; | |
2607 while (indent >= 8) | |
2608 { | |
2609 ga_append(&line_ga, TAB); | |
2610 msg_puts((char_u *)" "); | |
2611 indent -= 8; | |
2612 } | |
2613 while (indent-- > 0) | |
2614 { | |
2615 ga_append(&line_ga, ' '); | |
2616 msg_putchar(' '); | |
2617 } | |
2618 } | |
168 | 2619 ++no_mapping; |
2620 ++allow_keys; | |
164 | 2621 |
7 | 2622 /* |
2623 * Get the line, one character at a time. | |
2624 */ | |
2625 got_int = FALSE; | |
168 | 2626 while (!got_int) |
7 | 2627 { |
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
|
2628 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
|
2629 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
|
2630 |
7 | 2631 if (ga_grow(&line_ga, 40) == FAIL) |
2632 break; | |
2633 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2634 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2635 * 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
|
2636 */ |
1329 | 2637 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
|
2638 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2639 /* 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
|
2640 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
|
2641 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
|
2642 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2643 c1 = vgetc(); |
7 | 2644 |
2645 /* | |
168 | 2646 * Handle line editing. |
2647 * Previously this was left to the system, putting the terminal in | |
2648 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2649 */ |
168 | 2650 if (got_int) |
2651 { | |
2652 msg_putchar('\n'); | |
2653 break; | |
2654 } | |
2655 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2656 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
|
2657 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2658 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
|
2659 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
|
2660 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2661 |
168 | 2662 if (!escaped) |
7 | 2663 { |
168 | 2664 /* CR typed means "enter", which is NL */ |
2665 if (c1 == '\r') | |
2666 c1 = '\n'; | |
2667 | |
2668 if (c1 == BS || c1 == K_BS | |
2669 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2670 { |
168 | 2671 if (line_ga.ga_len > 0) |
2672 { | |
5966 | 2673 #ifdef FEAT_MBYTE |
2674 if (has_mbyte) | |
2675 { | |
2676 p = (char_u *)line_ga.ga_data; | |
2677 p[line_ga.ga_len] = NUL; | |
2678 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2679 line_ga.ga_len -= len; | |
2680 } | |
2681 else | |
2682 #endif | |
2683 --line_ga.ga_len; | |
168 | 2684 goto redraw; |
2685 } | |
2686 continue; | |
7 | 2687 } |
2688 | |
168 | 2689 if (c1 == Ctrl_U) |
7 | 2690 { |
168 | 2691 msg_col = startcol; |
2692 msg_clr_eos(); | |
2693 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
|
2694 goto redraw; |
168 | 2695 } |
2696 | |
2697 if (c1 == Ctrl_T) | |
2698 { | |
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
|
2699 sw = get_sw_value(curbuf); |
168 | 2700 p = (char_u *)line_ga.ga_data; |
2701 p[line_ga.ga_len] = NUL; | |
5995 | 2702 indent = get_indent_str(p, 8, FALSE); |
3740 | 2703 indent += sw - indent % sw; |
168 | 2704 add_indent: |
5995 | 2705 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2706 { |
7009 | 2707 (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
|
2708 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
|
2709 s = skipwhite(p); |
168 | 2710 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2711 *s = ' '; | |
2712 ++line_ga.ga_len; | |
7 | 2713 } |
168 | 2714 redraw: |
2715 /* redraw the line */ | |
2716 msg_col = startcol; | |
2717 vcol = 0; | |
5966 | 2718 p = (char_u *)line_ga.ga_data; |
2719 p[line_ga.ga_len] = NUL; | |
2720 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2721 { |
168 | 2722 if (*p == TAB) |
7 | 2723 { |
168 | 2724 do |
7 | 2725 { |
168 | 2726 msg_putchar(' '); |
2727 } while (++vcol % 8); | |
5966 | 2728 ++p; |
7 | 2729 } |
168 | 2730 else |
164 | 2731 { |
5966 | 2732 len = MB_PTR2LEN(p); |
2733 msg_outtrans_len(p, len); | |
2734 vcol += ptr2cells(p); | |
2735 p += len; | |
7 | 2736 } |
2737 } | |
168 | 2738 msg_clr_eos(); |
1329 | 2739 windgoto(msg_row, msg_col); |
168 | 2740 continue; |
2741 } | |
2742 | |
2743 if (c1 == Ctrl_D) | |
2744 { | |
2745 /* Delete one shiftwidth. */ | |
2746 p = (char_u *)line_ga.ga_data; | |
2747 if (prev_char == '0' || prev_char == '^') | |
7 | 2748 { |
168 | 2749 if (prev_char == '^') |
2750 ex_keep_indent = TRUE; | |
2751 indent = 0; | |
2752 p[--line_ga.ga_len] = NUL; | |
7 | 2753 } |
2754 else | |
2755 { | |
168 | 2756 p[line_ga.ga_len] = NUL; |
5995 | 2757 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
|
2758 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
|
2759 { |
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
|
2760 --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
|
2761 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
|
2762 } |
168 | 2763 } |
5995 | 2764 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2765 { |
6733
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2766 s = skipwhite(p); |
168 | 2767 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2768 --line_ga.ga_len; | |
7 | 2769 } |
168 | 2770 goto add_indent; |
2771 } | |
2772 | |
2773 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2774 { | |
2775 escaped = TRUE; | |
2776 continue; | |
7 | 2777 } |
168 | 2778 |
2779 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2780 if (IS_SPECIAL(c1)) | |
2781 continue; | |
7 | 2782 } |
168 | 2783 |
2784 if (IS_SPECIAL(c1)) | |
2785 c1 = '?'; | |
5966 | 2786 #ifdef FEAT_MBYTE |
2787 if (has_mbyte) | |
2788 len = (*mb_char2bytes)(c1, | |
2789 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2790 else | |
2791 #endif | |
2792 { | |
2793 len = 1; | |
2794 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2795 } | |
168 | 2796 if (c1 == '\n') |
2797 msg_putchar('\n'); | |
2798 else if (c1 == TAB) | |
2799 { | |
2800 /* Don't use chartabsize(), 'ts' can be different */ | |
2801 do | |
2802 { | |
2803 msg_putchar(' '); | |
2804 } while (++vcol % 8); | |
2805 } | |
7 | 2806 else |
2807 { | |
168 | 2808 msg_outtrans_len( |
5966 | 2809 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2810 vcol += char2cells(c1); |
7 | 2811 } |
5966 | 2812 line_ga.ga_len += len; |
168 | 2813 escaped = FALSE; |
2814 | |
2815 windgoto(msg_row, msg_col); | |
164 | 2816 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2817 |
2590 | 2818 /* We are done when a NL is entered, but not when it comes after an |
2819 * odd number of backslashes, that results in a NUL. */ | |
2820 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2821 { |
2590 | 2822 int bcount = 0; |
2823 | |
2824 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2825 ++bcount; | |
2826 | |
2827 if (bcount > 0) | |
2828 { | |
2829 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2830 * "\NL", etc. */ | |
2831 line_ga.ga_len -= (bcount + 1) / 2; | |
2832 pend -= (bcount + 1) / 2; | |
2833 pend[-1] = '\n'; | |
2834 } | |
2835 | |
2836 if ((bcount & 1) == 0) | |
2837 { | |
2838 --line_ga.ga_len; | |
2839 --pend; | |
2840 *pend = NUL; | |
2841 break; | |
2842 } | |
7 | 2843 } |
2844 } | |
2845 | |
168 | 2846 --no_mapping; |
2847 --allow_keys; | |
2848 | |
7 | 2849 /* make following messages go to the next line */ |
2850 msg_didout = FALSE; | |
2851 msg_col = 0; | |
2852 if (msg_row < Rows - 1) | |
2853 ++msg_row; | |
2854 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2855 | |
2856 if (got_int) | |
2857 ga_clear(&line_ga); | |
2858 | |
2859 return (char_u *)line_ga.ga_data; | |
2860 } | |
2861 | |
502 | 2862 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2863 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2864 /* |
2865 * Return TRUE if ccline.overstrike is on. | |
2866 */ | |
2867 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2868 cmdline_overstrike(void) |
7 | 2869 { |
2870 return ccline.overstrike; | |
2871 } | |
2872 | |
2873 /* | |
2874 * Return TRUE if the cursor is at the end of the cmdline. | |
2875 */ | |
2876 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2877 cmdline_at_end(void) |
7 | 2878 { |
2879 return (ccline.cmdpos >= ccline.cmdlen); | |
2880 } | |
2881 #endif | |
2882 | |
574 | 2883 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2884 /* |
2885 * Return the virtual column number at the current cursor position. | |
2886 * This is used by the IM code to obtain the start of the preedit string. | |
2887 */ | |
2888 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2889 cmdline_getvcol_cursor(void) |
7 | 2890 { |
2891 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2892 return MAXCOL; | |
2893 | |
2894 # ifdef FEAT_MBYTE | |
2895 if (has_mbyte) | |
2896 { | |
2897 colnr_T col; | |
2898 int i = 0; | |
2899 | |
2900 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 2901 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 2902 |
2903 return col; | |
2904 } | |
2905 else | |
2906 # endif | |
2907 return ccline.cmdpos; | |
2908 } | |
2909 #endif | |
2910 | |
2911 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
2912 /* | |
2913 * If part of the command line is an IM preedit string, redraw it with | |
2914 * IM feedback attributes. The cursor position is restored after drawing. | |
2915 */ | |
2916 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2917 redrawcmd_preedit(void) |
7 | 2918 { |
2919 if ((State & CMDLINE) | |
2920 && xic != NULL | |
976 | 2921 /* && im_get_status() doesn't work when using SCIM */ |
7 | 2922 && !p_imdisable |
2923 && im_is_preediting()) | |
2924 { | |
2925 int cmdpos = 0; | |
2926 int cmdspos; | |
2927 int old_row; | |
2928 int old_col; | |
2929 colnr_T col; | |
2930 | |
2931 old_row = msg_row; | |
2932 old_col = msg_col; | |
531 | 2933 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 2934 |
2935 # ifdef FEAT_MBYTE | |
2936 if (has_mbyte) | |
2937 { | |
2938 for (col = 0; col < preedit_start_col | |
2939 && cmdpos < ccline.cmdlen; ++col) | |
2940 { | |
2941 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 2942 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2943 } |
2944 } | |
2945 else | |
2946 # endif | |
2947 { | |
2948 cmdspos += preedit_start_col; | |
2949 cmdpos += preedit_start_col; | |
2950 } | |
2951 | |
2952 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
2953 msg_col = cmdspos % (int)Columns; | |
2954 if (msg_row >= Rows) | |
2955 msg_row = Rows - 1; | |
2956 | |
2957 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
2958 { | |
2959 int char_len; | |
2960 int char_attr; | |
2961 | |
2962 char_attr = im_get_feedback_attr(col); | |
2963 if (char_attr < 0) | |
2964 break; /* end of preedit string */ | |
2965 | |
2966 # ifdef FEAT_MBYTE | |
2967 if (has_mbyte) | |
474 | 2968 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2969 else |
2970 # endif | |
2971 char_len = 1; | |
2972 | |
2973 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
2974 cmdpos += char_len; | |
2975 } | |
2976 | |
2977 msg_row = old_row; | |
2978 msg_col = old_col; | |
2979 } | |
2980 } | |
2981 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
2982 | |
2983 /* | |
2984 * Allocate a new command line buffer. | |
2985 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
2986 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
2987 */ | |
2988 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2989 alloc_cmdbuff(int len) |
7 | 2990 { |
2991 /* | |
2992 * give some extra space to avoid having to allocate all the time | |
2993 */ | |
2994 if (len < 80) | |
2995 len = 100; | |
2996 else | |
2997 len += 20; | |
2998 | |
2999 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3000 ccline.cmdbufflen = len; | |
3001 } | |
3002 | |
3003 /* | |
3004 * Re-allocate the command line to length len + something extra. | |
3005 * return FAIL for failure, OK otherwise | |
3006 */ | |
3007 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3008 realloc_cmdbuff(int len) |
7 | 3009 { |
3010 char_u *p; | |
3011 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3012 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3013 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
|
3014 |
7 | 3015 p = ccline.cmdbuff; |
3016 alloc_cmdbuff(len); /* will get some more */ | |
3017 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3018 { | |
3019 ccline.cmdbuff = p; /* keep the old one */ | |
3020 return FAIL; | |
3021 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3022 /* 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
|
3023 * 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
|
3024 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
|
3025 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3026 vim_free(p); |
1718 | 3027 |
3028 if (ccline.xpc != NULL | |
3029 && ccline.xpc->xp_pattern != NULL | |
3030 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3031 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3032 { | |
1754 | 3033 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3034 |
3035 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3036 * to point into the newly allocated memory. */ | |
3037 if (i >= 0 && i <= ccline.cmdlen) | |
3038 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3039 } | |
3040 | |
7 | 3041 return OK; |
3042 } | |
3043 | |
359 | 3044 #if defined(FEAT_ARABIC) || defined(PROTO) |
3045 static char_u *arshape_buf = NULL; | |
3046 | |
3047 # if defined(EXITFREE) || defined(PROTO) | |
3048 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3049 free_cmdline_buf(void) |
359 | 3050 { |
3051 vim_free(arshape_buf); | |
3052 } | |
3053 # endif | |
3054 #endif | |
3055 | |
7 | 3056 /* |
3057 * Draw part of the cmdline at the current cursor position. But draw stars | |
3058 * when cmdline_star is TRUE. | |
3059 */ | |
3060 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3061 draw_cmdline(int start, int len) |
7 | 3062 { |
3063 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3064 int i; | |
3065 | |
3066 if (cmdline_star > 0) | |
3067 for (i = 0; i < len; ++i) | |
3068 { | |
3069 msg_putchar('*'); | |
3070 # ifdef FEAT_MBYTE | |
3071 if (has_mbyte) | |
474 | 3072 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3073 # endif |
3074 } | |
3075 else | |
3076 #endif | |
3077 #ifdef FEAT_ARABIC | |
3078 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3079 { | |
3080 static int buflen = 0; | |
3081 char_u *p; | |
3082 int j; | |
3083 int newlen = 0; | |
3084 int mb_l; | |
719 | 3085 int pc, pc1 = 0; |
7 | 3086 int prev_c = 0; |
3087 int prev_c1 = 0; | |
714 | 3088 int u8c; |
3089 int u8cc[MAX_MCO]; | |
7 | 3090 int nc = 0; |
3091 | |
3092 /* | |
3093 * Do arabic shaping into a temporary buffer. This is very | |
3094 * inefficient! | |
3095 */ | |
507 | 3096 if (len * 2 + 2 > buflen) |
7 | 3097 { |
3098 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3099 * alloc()/free() calls. */ | |
359 | 3100 vim_free(arshape_buf); |
507 | 3101 buflen = len * 2 + 2; |
359 | 3102 arshape_buf = alloc(buflen); |
3103 if (arshape_buf == NULL) | |
7 | 3104 return; /* out of memory */ |
3105 } | |
3106 | |
507 | 3107 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3108 { | |
3109 /* Prepend a space to draw the leading composing char on. */ | |
3110 arshape_buf[0] = ' '; | |
3111 newlen = 1; | |
3112 } | |
3113 | |
7 | 3114 for (j = start; j < start + len; j += mb_l) |
3115 { | |
3116 p = ccline.cmdbuff + j; | |
714 | 3117 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3118 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3119 if (ARABIC_CHAR(u8c)) |
3120 { | |
3121 /* Do Arabic shaping. */ | |
3122 if (cmdmsg_rl) | |
3123 { | |
3124 /* displaying from right to left */ | |
3125 pc = prev_c; | |
3126 pc1 = prev_c1; | |
714 | 3127 prev_c1 = u8cc[0]; |
7 | 3128 if (j + mb_l >= start + len) |
3129 nc = NUL; | |
3130 else | |
3131 nc = utf_ptr2char(p + mb_l); | |
3132 } | |
3133 else | |
3134 { | |
3135 /* displaying from left to right */ | |
3136 if (j + mb_l >= start + len) | |
3137 pc = NUL; | |
3138 else | |
714 | 3139 { |
3140 int pcc[MAX_MCO]; | |
3141 | |
3142 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3143 start + len - j - mb_l); |
714 | 3144 pc1 = pcc[0]; |
3145 } | |
7 | 3146 nc = prev_c; |
3147 } | |
3148 prev_c = u8c; | |
3149 | |
714 | 3150 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3151 |
359 | 3152 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3153 if (u8cc[0] != 0) |
7 | 3154 { |
714 | 3155 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3156 if (u8cc[1] != 0) | |
3157 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3158 arshape_buf + newlen); |
7 | 3159 } |
3160 } | |
3161 else | |
3162 { | |
3163 prev_c = u8c; | |
359 | 3164 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3165 newlen += mb_l; |
3166 } | |
3167 } | |
3168 | |
359 | 3169 msg_outtrans_len(arshape_buf, newlen); |
7 | 3170 } |
3171 else | |
3172 #endif | |
3173 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3174 } | |
3175 | |
3176 /* | |
3177 * Put a character on the command line. Shifts the following text to the | |
3178 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3179 * "c" must be printable (fit in one display cell)! | |
3180 */ | |
3181 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3182 putcmdline(int c, int shift) |
7 | 3183 { |
3184 if (cmd_silent) | |
3185 return; | |
3186 msg_no_more = TRUE; | |
3187 msg_putchar(c); | |
3188 if (shift) | |
3189 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3190 msg_no_more = FALSE; | |
3191 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3192 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3193 extra_char_shift = shift; |
7 | 3194 } |
3195 | |
3196 /* | |
3197 * Undo a putcmdline(c, FALSE). | |
3198 */ | |
3199 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3200 unputcmdline(void) |
7 | 3201 { |
3202 if (cmd_silent) | |
3203 return; | |
3204 msg_no_more = TRUE; | |
3205 if (ccline.cmdlen == ccline.cmdpos) | |
3206 msg_putchar(' '); | |
3558 | 3207 #ifdef FEAT_MBYTE |
3208 else if (has_mbyte) | |
3209 draw_cmdline(ccline.cmdpos, | |
3210 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3211 #endif | |
7 | 3212 else |
3213 draw_cmdline(ccline.cmdpos, 1); | |
3214 msg_no_more = FALSE; | |
3215 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3216 extra_char = NUL; |
7 | 3217 } |
3218 | |
3219 /* | |
3220 * Put the given string, of the given length, onto the command line. | |
3221 * If len is -1, then STRLEN() is used to calculate the length. | |
3222 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3223 * part will be redrawn, otherwise it will not. If this function is called | |
3224 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3225 * called afterwards. | |
3226 */ | |
3227 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3228 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3229 { |
3230 int retval; | |
3231 int i; | |
3232 int m; | |
3233 int c; | |
3234 | |
3235 if (len < 0) | |
3236 len = (int)STRLEN(str); | |
3237 | |
3238 /* Check if ccline.cmdbuff needs to be longer */ | |
3239 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
|
3240 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3241 else |
3242 retval = OK; | |
3243 if (retval == OK) | |
3244 { | |
3245 if (!ccline.overstrike) | |
3246 { | |
3247 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3248 ccline.cmdbuff + ccline.cmdpos, | |
3249 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3250 ccline.cmdlen += len; | |
3251 } | |
3252 else | |
3253 { | |
3254 #ifdef FEAT_MBYTE | |
3255 if (has_mbyte) | |
3256 { | |
3257 /* Count nr of characters in the new string. */ | |
3258 m = 0; | |
474 | 3259 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3260 ++m; |
3261 /* Count nr of bytes in cmdline that are overwritten by these | |
3262 * characters. */ | |
3263 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3264 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3265 --m; |
3266 if (i < ccline.cmdlen) | |
3267 { | |
3268 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3269 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3270 ccline.cmdlen += ccline.cmdpos + len - i; | |
3271 } | |
3272 else | |
3273 ccline.cmdlen = ccline.cmdpos + len; | |
3274 } | |
3275 else | |
3276 #endif | |
3277 if (ccline.cmdpos + len > ccline.cmdlen) | |
3278 ccline.cmdlen = ccline.cmdpos + len; | |
3279 } | |
3280 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3281 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3282 | |
3283 #ifdef FEAT_MBYTE | |
3284 if (enc_utf8) | |
3285 { | |
3286 /* When the inserted text starts with a composing character, | |
3287 * backup to the character before it. There could be two of them. | |
3288 */ | |
3289 i = 0; | |
3290 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3291 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3292 { | |
3293 i = (*mb_head_off)(ccline.cmdbuff, | |
3294 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3295 ccline.cmdpos -= i; | |
3296 len += i; | |
3297 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3298 } | |
3299 # ifdef FEAT_ARABIC | |
3300 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3301 { | |
3302 /* Check the previous character for Arabic combining pair. */ | |
3303 i = (*mb_head_off)(ccline.cmdbuff, | |
3304 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3305 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3306 + ccline.cmdpos - i), c)) | |
3307 { | |
3308 ccline.cmdpos -= i; | |
3309 len += i; | |
3310 } | |
3311 else | |
3312 i = 0; | |
3313 } | |
3314 # endif | |
3315 if (i != 0) | |
3316 { | |
3317 /* Also backup the cursor position. */ | |
3318 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3319 ccline.cmdspos -= i; | |
3320 msg_col -= i; | |
3321 if (msg_col < 0) | |
3322 { | |
3323 msg_col += Columns; | |
3324 --msg_row; | |
3325 } | |
3326 } | |
3327 } | |
3328 #endif | |
3329 | |
3330 if (redraw && !cmd_silent) | |
3331 { | |
3332 msg_no_more = TRUE; | |
3333 i = cmdline_row; | |
3114 | 3334 cursorcmd(); |
7 | 3335 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3336 /* Avoid clearing the rest of the line too often. */ | |
3337 if (cmdline_row != i || ccline.overstrike) | |
3338 msg_clr_eos(); | |
3339 msg_no_more = FALSE; | |
3340 } | |
3341 #ifdef FEAT_FKMAP | |
3342 /* | |
3343 * If we are in Farsi command mode, the character input must be in | |
3344 * Insert mode. So do not advance the cmdpos. | |
3345 */ | |
3346 if (!cmd_fkmap) | |
3347 #endif | |
3348 { | |
3349 if (KeyTyped) | |
534 | 3350 { |
7 | 3351 m = Columns * Rows; |
534 | 3352 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3353 m = MAXCOL; | |
3354 } | |
7 | 3355 else |
3356 m = MAXCOL; | |
3357 for (i = 0; i < len; ++i) | |
3358 { | |
3359 c = cmdline_charsize(ccline.cmdpos); | |
3360 #ifdef FEAT_MBYTE | |
3361 /* count ">" for a double-wide char that doesn't fit. */ | |
3362 if (has_mbyte) | |
3363 correct_cmdspos(ccline.cmdpos, c); | |
3364 #endif | |
1612 | 3365 /* Stop cursor at the end of the screen, but do increment the |
3366 * insert position, so that entering a very long command | |
3367 * works, even though you can't see it. */ | |
3368 if (ccline.cmdspos + c < m) | |
3369 ccline.cmdspos += c; | |
7 | 3370 #ifdef FEAT_MBYTE |
3371 if (has_mbyte) | |
3372 { | |
474 | 3373 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3374 if (c > len - i - 1) |
3375 c = len - i - 1; | |
3376 ccline.cmdpos += c; | |
3377 i += c; | |
3378 } | |
3379 #endif | |
3380 ++ccline.cmdpos; | |
3381 } | |
3382 } | |
3383 } | |
3384 if (redraw) | |
3385 msg_check(); | |
3386 return retval; | |
3387 } | |
3388 | |
95 | 3389 static struct cmdline_info prev_ccline; |
3390 static int prev_ccline_used = FALSE; | |
3391 | |
3392 /* | |
3393 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3394 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3395 * available globally in prev_ccline. | |
3396 */ | |
3397 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3398 save_cmdline(struct cmdline_info *ccp) |
95 | 3399 { |
3400 if (!prev_ccline_used) | |
3401 { | |
3402 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3403 prev_ccline_used = TRUE; | |
3404 } | |
3405 *ccp = prev_ccline; | |
3406 prev_ccline = ccline; | |
3407 ccline.cmdbuff = NULL; | |
3408 ccline.cmdprompt = NULL; | |
1718 | 3409 ccline.xpc = NULL; |
95 | 3410 } |
3411 | |
3412 /* | |
1214 | 3413 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3414 */ |
3415 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3416 restore_cmdline(struct cmdline_info *ccp) |
95 | 3417 { |
3418 ccline = prev_ccline; | |
3419 prev_ccline = *ccp; | |
3420 } | |
3421 | |
849 | 3422 #if defined(FEAT_EVAL) || defined(PROTO) |
3423 /* | |
3424 * Save the command line into allocated memory. Returns a pointer to be | |
3425 * passed to restore_cmdline_alloc() later. | |
3426 * Returns NULL when failed. | |
3427 */ | |
3428 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3429 save_cmdline_alloc(void) |
849 | 3430 { |
3431 struct cmdline_info *p; | |
3432 | |
3433 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3434 if (p != NULL) | |
3435 save_cmdline(p); | |
3436 return (char_u *)p; | |
3437 } | |
3438 | |
3439 /* | |
3440 * Restore the command line from the return value of save_cmdline_alloc(). | |
3441 */ | |
3442 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3443 restore_cmdline_alloc(char_u *p) |
849 | 3444 { |
3445 if (p != NULL) | |
3446 { | |
3447 restore_cmdline((struct cmdline_info *)p); | |
3448 vim_free(p); | |
3449 } | |
3450 } | |
3451 #endif | |
3452 | |
15 | 3453 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3454 * 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
|
3455 * Used by CTRL-R command in command-line mode. |
15 | 3456 * insert_reg() can't be used here, because special characters from the |
3457 * register contents will be interpreted as commands. | |
3458 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3459 * Return FAIL for failure, OK otherwise. |
15 | 3460 */ |
3461 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3462 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3463 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3464 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
|
3465 int remcr) /* remove trailing CR */ |
15 | 3466 { |
3467 long i; | |
3468 char_u *arg; | |
772 | 3469 char_u *p; |
15 | 3470 int allocated; |
3471 struct cmdline_info save_ccline; | |
3472 | |
3473 /* check for valid regname; also accept special characters for CTRL-R in | |
3474 * the command line */ | |
3475 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
|
3476 && 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
|
3477 && !valid_yank_reg(regname, FALSE)) |
15 | 3478 return FAIL; |
3479 | |
3480 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3481 * CTRL-C to break the loop. */ | |
3482 line_breakcheck(); | |
3483 if (got_int) | |
3484 return FAIL; | |
3485 | |
3486 #ifdef FEAT_CLIPBOARD | |
3487 regname = may_get_selection(regname); | |
3488 #endif | |
3489 | |
634 | 3490 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3491 * things like going to another buffer when evaluating an expression. */ |
95 | 3492 save_cmdline(&save_ccline); |
634 | 3493 ++textlock; |
15 | 3494 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3495 --textlock; |
95 | 3496 restore_cmdline(&save_ccline); |
15 | 3497 |
3498 if (i) | |
3499 { | |
3500 /* Got the value of a special register in "arg". */ | |
3501 if (arg == NULL) | |
3502 return FAIL; | |
772 | 3503 |
3504 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3505 * part of the word. */ | |
3506 p = arg; | |
3507 if (p_is && regname == Ctrl_W) | |
3508 { | |
3509 char_u *w; | |
3510 int len; | |
3511 | |
3512 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3513 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3514 { |
3515 #ifdef FEAT_MBYTE | |
3516 if (has_mbyte) | |
3517 { | |
3518 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3519 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3520 break; | |
3521 w -= len; | |
3522 } | |
3523 else | |
3524 #endif | |
3525 { | |
3526 if (!vim_iswordc(w[-1])) | |
3527 break; | |
3528 --w; | |
3529 } | |
3530 } | |
2937 | 3531 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3532 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3533 p += len; | |
3534 } | |
3535 | |
3536 cmdline_paste_str(p, literally); | |
15 | 3537 if (allocated) |
3538 vim_free(arg); | |
3539 return OK; | |
3540 } | |
3541 | |
1015 | 3542 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3543 } |
3544 | |
3545 /* | |
3546 * Put a string on the command line. | |
3547 * When "literally" is TRUE, insert literally. | |
3548 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3549 * line. | |
3550 */ | |
3551 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3552 cmdline_paste_str(char_u *s, int literally) |
15 | 3553 { |
3554 int c, cv; | |
3555 | |
3556 if (literally) | |
3557 put_on_cmdline(s, -1, TRUE); | |
3558 else | |
3559 while (*s != NUL) | |
3560 { | |
3561 cv = *s; | |
3562 if (cv == Ctrl_V && s[1]) | |
3563 ++s; | |
3564 #ifdef FEAT_MBYTE | |
3565 if (has_mbyte) | |
1606 | 3566 c = mb_cptr2char_adv(&s); |
15 | 3567 else |
3568 #endif | |
3569 c = *s++; | |
3628 | 3570 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3571 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3572 #ifdef UNIX |
3573 || c == intr_char | |
3574 #endif | |
3575 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3576 stuffcharReadbuff(Ctrl_V); | |
3577 stuffcharReadbuff(c); | |
3578 } | |
3579 } | |
3580 | |
7 | 3581 #ifdef FEAT_WILDMENU |
3582 /* | |
3583 * Delete characters on the command line, from "from" to the current | |
3584 * position. | |
3585 */ | |
3586 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3587 cmdline_del(int from) |
7 | 3588 { |
3589 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3590 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3591 ccline.cmdlen -= ccline.cmdpos - from; | |
3592 ccline.cmdpos = from; | |
3593 } | |
3594 #endif | |
3595 | |
3596 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3597 * 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
|
3598 * 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
|
3599 * overwritten. |
7 | 3600 */ |
3601 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3602 redrawcmdline(void) |
7 | 3603 { |
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
|
3604 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
|
3605 } |
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
|
3606 |
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
|
3607 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
|
3608 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
|
3609 { |
7 | 3610 if (cmd_silent) |
3611 return; | |
3612 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
|
3613 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
|
3614 compute_cmdrow(); |
7 | 3615 redrawcmd(); |
3616 cursorcmd(); | |
3617 } | |
3618 | |
3619 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3620 redrawcmdprompt(void) |
7 | 3621 { |
3622 int i; | |
3623 | |
3624 if (cmd_silent) | |
3625 return; | |
531 | 3626 if (ccline.cmdfirstc != NUL) |
7 | 3627 msg_putchar(ccline.cmdfirstc); |
3628 if (ccline.cmdprompt != NULL) | |
3629 { | |
3630 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3631 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3632 /* do the reverse of set_cmdspos() */ | |
531 | 3633 if (ccline.cmdfirstc != NUL) |
7 | 3634 --ccline.cmdindent; |
3635 } | |
3636 else | |
3637 for (i = ccline.cmdindent; i > 0; --i) | |
3638 msg_putchar(' '); | |
3639 } | |
3640 | |
3641 /* | |
3642 * Redraw what is currently on the command line. | |
3643 */ | |
3644 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3645 redrawcmd(void) |
7 | 3646 { |
3647 if (cmd_silent) | |
3648 return; | |
3649 | |
683 | 3650 /* when 'incsearch' is set there may be no command line while redrawing */ |
3651 if (ccline.cmdbuff == NULL) | |
3652 { | |
3653 windgoto(cmdline_row, 0); | |
3654 msg_clr_eos(); | |
3655 return; | |
3656 } | |
3657 | |
7 | 3658 msg_start(); |
3659 redrawcmdprompt(); | |
3660 | |
3661 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3662 msg_no_more = TRUE; | |
3663 draw_cmdline(0, ccline.cmdlen); | |
3664 msg_clr_eos(); | |
3665 msg_no_more = FALSE; | |
3666 | |
3667 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
|
3668 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
|
3669 putcmdline(extra_char, extra_char_shift); |
7 | 3670 |
3671 /* | |
3672 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3673 * in cmdline mode we can reset them now. | |
3674 */ | |
3675 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3676 | |
3677 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3678 * in cmdline mode */ | |
3679 skip_redraw = FALSE; | |
3680 } | |
3681 | |
3682 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3683 compute_cmdrow(void) |
7 | 3684 { |
540 | 3685 if (exmode_active || msg_scrolled != 0) |
7 | 3686 cmdline_row = Rows - 1; |
3687 else | |
3688 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
|
3689 + lastwin->w_status_height; |
7 | 3690 } |
3691 | |
3692 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3693 cursorcmd(void) |
7 | 3694 { |
3695 if (cmd_silent) | |
3696 return; | |
3697 | |
3698 #ifdef FEAT_RIGHTLEFT | |
3699 if (cmdmsg_rl) | |
3700 { | |
3701 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3702 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3703 if (msg_row <= 0) | |
3704 msg_row = Rows - 1; | |
3705 } | |
3706 else | |
3707 #endif | |
3708 { | |
3709 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3710 msg_col = ccline.cmdspos % (int)Columns; | |
3711 if (msg_row >= Rows) | |
3712 msg_row = Rows - 1; | |
3713 } | |
3714 | |
3715 windgoto(msg_row, msg_col); | |
3716 #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
|
3717 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
|
3718 redrawcmd_preedit(); |
7 | 3719 #endif |
3720 #ifdef MCH_CURSOR_SHAPE | |
3721 mch_update_cursor(); | |
3722 #endif | |
3723 } | |
3724 | |
3725 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3726 gotocmdline(int clr) |
7 | 3727 { |
3728 msg_start(); | |
3729 #ifdef FEAT_RIGHTLEFT | |
3730 if (cmdmsg_rl) | |
3731 msg_col = Columns - 1; | |
3732 else | |
3733 #endif | |
3734 msg_col = 0; /* always start in column 0 */ | |
3735 if (clr) /* clear the bottom line(s) */ | |
3736 msg_clr_eos(); /* will reset clear_cmdline */ | |
3737 windgoto(cmdline_row, 0); | |
3738 } | |
3739 | |
3740 /* | |
3741 * Check the word in front of the cursor for an abbreviation. | |
3742 * Called when the non-id character "c" has been entered. | |
3743 * When an abbreviation is recognized it is removed from the text with | |
3744 * backspaces and the replacement string is inserted, followed by "c". | |
3745 */ | |
3746 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3747 ccheck_abbr(int c) |
7 | 3748 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3749 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3750 |
7 | 3751 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3752 return FALSE; | |
3753 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3754 /* 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
|
3755 * 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
|
3756 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
|
3757 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3758 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
|
3759 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3760 && 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
|
3761 && 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
|
3762 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3763 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3764 /* 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
|
3765 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3766 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3767 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3768 } |
3769 | |
3164 | 3770 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3771 static int | |
3772 #ifdef __BORLANDC__ | |
3773 _RTLENTRYF | |
3774 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3775 sort_func_compare(const void *s1, const void *s2) |
3164 | 3776 { |
3777 char_u *p1 = *(char_u **)s1; | |
3778 char_u *p2 = *(char_u **)s2; | |
3779 | |
3780 if (*p1 != '<' && *p2 == '<') return -1; | |
3781 if (*p1 == '<' && *p2 != '<') return 1; | |
3782 return STRCMP(p1, p2); | |
3783 } | |
3784 #endif | |
3785 | |
7 | 3786 /* |
3787 * Return FAIL if this is not an appropriate context in which to do | |
3788 * completion of anything, return OK if it is (even if there are no matches). | |
3789 * For the caller, this means that the character is just passed through like a | |
3790 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3791 */ | |
3792 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3793 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3794 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3795 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3796 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3797 int escape) /* if TRUE, escape the returned matches */ |
7 | 3798 { |
3799 int i, j; | |
3800 char_u *p1; | |
3801 char_u *p2; | |
3802 int difflen; | |
3803 int v; | |
3804 | |
3805 if (xp->xp_numfiles == -1) | |
3806 { | |
3807 set_expand_context(xp); | |
3808 cmd_showtail = expand_showtail(xp); | |
3809 } | |
3810 | |
3811 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3812 { | |
3813 beep_flush(); | |
3814 return OK; /* Something illegal on command line */ | |
3815 } | |
3816 if (xp->xp_context == EXPAND_NOTHING) | |
3817 { | |
3818 /* Caller can use the character as a normal char instead */ | |
3819 return FAIL; | |
3820 } | |
3821 | |
3822 MSG_PUTS("..."); /* show that we are busy */ | |
3823 out_flush(); | |
3824 | |
3825 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3826 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3827 |
3828 if (type == WILD_NEXT || type == WILD_PREV) | |
3829 { | |
3830 /* | |
3831 * Get next/previous match for a previous expanded pattern. | |
3832 */ | |
3833 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3834 } | |
3835 else | |
3836 { | |
3837 /* | |
3838 * Translate string into pattern and expand it. | |
3839 */ | |
1965 | 3840 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3841 xp->xp_context)) == NULL) | |
7 | 3842 p2 = NULL; |
3843 else | |
3844 { | |
2652 | 3845 int use_options = options | |
3961 | 3846 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3847 if (escape) | |
3848 use_options |= WILD_ESCAPE; | |
2652 | 3849 |
3850 if (p_wic) | |
3851 use_options += WILD_ICASE; | |
1965 | 3852 p2 = ExpandOne(xp, p1, |
3853 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3854 use_options, type); |
7 | 3855 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3856 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3857 if (p2 != NULL && type == WILD_LONGEST) |
3858 { | |
1965 | 3859 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3860 if (ccline.cmdbuff[i + j] == '*' |
3861 || ccline.cmdbuff[i + j] == '?') | |
3862 break; | |
3863 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
|
3864 VIM_CLEAR(p2); |
7 | 3865 } |
3866 } | |
3867 } | |
3868 | |
3869 if (p2 != NULL && !got_int) | |
3870 { | |
1965 | 3871 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
|
3872 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3873 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3874 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3875 xp->xp_pattern = ccline.cmdbuff + i; |
3876 } | |
3877 else | |
3878 v = OK; | |
3879 if (v == OK) | |
3880 { | |
323 | 3881 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3882 &ccline.cmdbuff[ccline.cmdpos], | |
3883 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3884 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3885 ccline.cmdlen += difflen; |
3886 ccline.cmdpos += difflen; | |
3887 } | |
3888 } | |
3889 vim_free(p2); | |
3890 | |
3891 redrawcmd(); | |
33 | 3892 cursorcmd(); |
7 | 3893 |
3894 /* When expanding a ":map" command and no matches are found, assume that | |
3895 * the key is supposed to be inserted literally */ | |
3896 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3897 return FAIL; | |
3898 | |
3899 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
3900 beep_flush(); | |
3901 else if (xp->xp_numfiles == 1) | |
3902 /* free expanded pattern */ | |
3903 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
3904 | |
3905 return OK; | |
3906 } | |
3907 | |
3908 /* | |
3909 * Do wildcard expansion on the string 'str'. | |
3910 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 3911 * Return a pointer to allocated memory containing the new string. |
7 | 3912 * Return NULL for failure. |
3913 * | |
1412 | 3914 * "orig" is the originally expanded string, copied to allocated memory. It |
3915 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
3916 * WILD_PREV "orig" should be NULL. | |
3917 * | |
838 | 3918 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
3919 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 3920 * |
3921 * mode = WILD_FREE: just free previously expanded matches | |
3922 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
3923 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
3924 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
3925 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
3926 * mode = WILD_ALL: return all matches concatenated | |
3927 * mode = WILD_LONGEST: return longest matched part | |
3398 | 3928 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 3929 * |
3930 * options = WILD_LIST_NOTFOUND: list entries without a match | |
3931 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
3932 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
3933 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
3934 * options = WILD_ADD_SLASH: add a slash after directory names | |
3935 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
3936 * options = WILD_SILENT: don't print warning messages | |
3937 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 3938 * options = WILD_ICASE: ignore case for files |
7 | 3939 * |
3940 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
3941 */ | |
3942 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3943 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3944 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3945 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3946 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
|
3947 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3948 int mode) |
7 | 3949 { |
3950 char_u *ss = NULL; | |
3951 static int findex; | |
3952 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 3953 int orig_saved = FALSE; |
7 | 3954 int i; |
3955 long_u len; | |
3956 int non_suf_match; /* number without matching suffix */ | |
3957 | |
3958 /* | |
3959 * first handle the case of using an old match | |
3960 */ | |
3961 if (mode == WILD_NEXT || mode == WILD_PREV) | |
3962 { | |
3963 if (xp->xp_numfiles > 0) | |
3964 { | |
3965 if (mode == WILD_PREV) | |
3966 { | |
3967 if (findex == -1) | |
3968 findex = xp->xp_numfiles; | |
3969 --findex; | |
3970 } | |
3971 else /* mode == WILD_NEXT */ | |
3972 ++findex; | |
3973 | |
3974 /* | |
3975 * When wrapping around, return the original string, set findex to | |
3976 * -1. | |
3977 */ | |
3978 if (findex < 0) | |
3979 { | |
3980 if (orig_save == NULL) | |
3981 findex = xp->xp_numfiles - 1; | |
3982 else | |
3983 findex = -1; | |
3984 } | |
3985 if (findex >= xp->xp_numfiles) | |
3986 { | |
3987 if (orig_save == NULL) | |
3988 findex = 0; | |
3989 else | |
3990 findex = -1; | |
3991 } | |
3992 #ifdef FEAT_WILDMENU | |
3993 if (p_wmnu) | |
3994 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
3995 findex, cmd_showtail); | |
3996 #endif | |
3997 if (findex == -1) | |
3998 return vim_strsave(orig_save); | |
3999 return vim_strsave(xp->xp_files[findex]); | |
4000 } | |
4001 else | |
4002 return NULL; | |
4003 } | |
4004 | |
1412 | 4005 /* free old names */ |
7 | 4006 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4007 { | |
4008 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4009 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
|
4010 VIM_CLEAR(orig_save); |
7 | 4011 } |
4012 findex = 0; | |
4013 | |
4014 if (mode == WILD_FREE) /* only release file name */ | |
4015 return NULL; | |
4016 | |
4017 if (xp->xp_numfiles == -1) | |
4018 { | |
4019 vim_free(orig_save); | |
4020 orig_save = orig; | |
1432 | 4021 orig_saved = TRUE; |
7 | 4022 |
4023 /* | |
4024 * Do the expansion. | |
4025 */ | |
4026 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4027 options) == FAIL) | |
4028 { | |
4029 #ifdef FNAME_ILLEGAL | |
4030 /* Illegal file name has been silently skipped. But when there | |
4031 * are wildcards, the real problem is that there was no match, | |
4032 * causing the pattern to be added, which has illegal characters. | |
4033 */ | |
4034 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4035 EMSG2(_(e_nomatch2), str); | |
4036 #endif | |
4037 } | |
4038 else if (xp->xp_numfiles == 0) | |
4039 { | |
4040 if (!(options & WILD_SILENT)) | |
4041 EMSG2(_(e_nomatch2), str); | |
4042 } | |
4043 else | |
4044 { | |
4045 /* Escape the matches for use on the command line. */ | |
4046 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4047 | |
4048 /* | |
4049 * Check for matching suffixes in file names. | |
4050 */ | |
3398 | 4051 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4052 && mode != WILD_LONGEST) | |
7 | 4053 { |
4054 if (xp->xp_numfiles) | |
4055 non_suf_match = xp->xp_numfiles; | |
4056 else | |
4057 non_suf_match = 1; | |
4058 if ((xp->xp_context == EXPAND_FILES | |
4059 || xp->xp_context == EXPAND_DIRECTORIES) | |
4060 && xp->xp_numfiles > 1) | |
4061 { | |
4062 /* | |
4063 * More than one match; check suffix. | |
4064 * The files will have been sorted on matching suffix in | |
4065 * expand_wildcards, only need to check the first two. | |
4066 */ | |
4067 non_suf_match = 0; | |
4068 for (i = 0; i < 2; ++i) | |
4069 if (match_suffix(xp->xp_files[i])) | |
4070 ++non_suf_match; | |
4071 } | |
4072 if (non_suf_match != 1) | |
4073 { | |
4074 /* Can we ever get here unless it's while expanding | |
4075 * interactively? If not, we can get rid of this all | |
4076 * together. Don't really want to wait for this message | |
4077 * (and possibly have to hit return to continue!). | |
4078 */ | |
4079 if (!(options & WILD_SILENT)) | |
4080 EMSG(_(e_toomany)); | |
4081 else if (!(options & WILD_NO_BEEP)) | |
4082 beep_flush(); | |
4083 } | |
4084 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4085 ss = vim_strsave(xp->xp_files[0]); | |
4086 } | |
4087 } | |
4088 } | |
4089 | |
4090 /* Find longest common part */ | |
4091 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4092 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4093 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4094 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4095 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4096 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4097 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4098 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4099 if (has_mbyte) |
7 | 4100 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4101 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
|
4102 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
|
4103 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4104 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4105 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4106 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
|
4107 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
|
4108 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4109 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4110 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4111 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
|
4112 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4113 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4114 ci = xp->xp_files[i][len]; |
4242 | 4115 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4116 || xp->xp_context == EXPAND_FILES |
714 | 4117 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4118 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4119 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4120 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4121 break; |
4122 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4123 else if (c0 != ci) |
7 | 4124 break; |
4125 } | |
4126 if (i < xp->xp_numfiles) | |
4127 { | |
4128 if (!(options & WILD_NO_BEEP)) | |
6949 | 4129 vim_beep(BO_WILD); |
7 | 4130 break; |
4131 } | |
4132 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4133 |
7 | 4134 ss = alloc((unsigned)len + 1); |
4135 if (ss) | |
419 | 4136 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4137 findex = -1; /* next p_wc gets first one */ |
4138 } | |
4139 | |
4140 /* Concatenate all matching names */ | |
4141 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4142 { | |
4143 len = 0; | |
4144 for (i = 0; i < xp->xp_numfiles; ++i) | |
4145 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4146 ss = lalloc(len, TRUE); | |
4147 if (ss != NULL) | |
4148 { | |
4149 *ss = NUL; | |
4150 for (i = 0; i < xp->xp_numfiles; ++i) | |
4151 { | |
4152 STRCAT(ss, xp->xp_files[i]); | |
4153 if (i != xp->xp_numfiles - 1) | |
4154 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4155 } | |
4156 } | |
4157 } | |
4158 | |
4159 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4160 ExpandCleanup(xp); | |
4161 | |
1412 | 4162 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4163 if (!orig_saved) |
1412 | 4164 vim_free(orig); |
4165 | |
7 | 4166 return ss; |
4167 } | |
4168 | |
4169 /* | |
4170 * Prepare an expand structure for use. | |
4171 */ | |
4172 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4173 ExpandInit(expand_T *xp) |
7 | 4174 { |
1718 | 4175 xp->xp_pattern = NULL; |
1965 | 4176 xp->xp_pattern_len = 0; |
7 | 4177 xp->xp_backslash = XP_BS_NONE; |
632 | 4178 #ifndef BACKSLASH_IN_FILENAME |
4179 xp->xp_shell = FALSE; | |
4180 #endif | |
7 | 4181 xp->xp_numfiles = -1; |
4182 xp->xp_files = NULL; | |
632 | 4183 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4184 xp->xp_arg = NULL; | |
4185 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4186 xp->xp_line = NULL; |
7 | 4187 } |
4188 | |
4189 /* | |
4190 * Cleanup an expand structure after use. | |
4191 */ | |
4192 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4193 ExpandCleanup(expand_T *xp) |
7 | 4194 { |
4195 if (xp->xp_numfiles >= 0) | |
4196 { | |
4197 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4198 xp->xp_numfiles = -1; | |
4199 } | |
4200 } | |
4201 | |
4202 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4203 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4204 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4205 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4206 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4207 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4208 int options) |
7 | 4209 { |
4210 int i; | |
4211 char_u *p; | |
4212 | |
4213 /* | |
4214 * May change home directory back to "~" | |
4215 */ | |
4216 if (options & WILD_HOME_REPLACE) | |
4217 tilde_replace(str, numfiles, files); | |
4218 | |
4219 if (options & WILD_ESCAPE) | |
4220 { | |
4221 if (xp->xp_context == EXPAND_FILES | |
2778 | 4222 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4223 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4224 || xp->xp_context == EXPAND_BUFFERS |
4225 || xp->xp_context == EXPAND_DIRECTORIES) | |
4226 { | |
4227 /* | |
4228 * Insert a backslash into a file name before a space, \, %, # | |
4229 * and wildmatch characters, except '~'. | |
4230 */ | |
4231 for (i = 0; i < numfiles; ++i) | |
4232 { | |
4233 /* for ":set path=" we need to escape spaces twice */ | |
4234 if (xp->xp_backslash == XP_BS_THREE) | |
4235 { | |
4236 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4237 if (p != NULL) | |
4238 { | |
4239 vim_free(files[i]); | |
4240 files[i] = p; | |
719 | 4241 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4242 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4243 if (p != NULL) | |
4244 { | |
4245 vim_free(files[i]); | |
4246 files[i] = p; | |
4247 } | |
4248 #endif | |
4249 } | |
4250 } | |
1589 | 4251 #ifdef BACKSLASH_IN_FILENAME |
4252 p = vim_strsave_fnameescape(files[i], FALSE); | |
4253 #else | |
1586 | 4254 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4255 #endif |
7 | 4256 if (p != NULL) |
4257 { | |
4258 vim_free(files[i]); | |
4259 files[i] = p; | |
4260 } | |
4261 | |
4262 /* If 'str' starts with "\~", replace "~" at start of | |
4263 * files[i] with "\~". */ | |
4264 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4265 escape_fname(&files[i]); |
7 | 4266 } |
4267 xp->xp_backslash = XP_BS_NONE; | |
435 | 4268 |
4269 /* If the first file starts with a '+' escape it. Otherwise it | |
4270 * could be seen as "+cmd". */ | |
4271 if (*files[0] == '+') | |
4272 escape_fname(&files[0]); | |
7 | 4273 } |
4274 else if (xp->xp_context == EXPAND_TAGS) | |
4275 { | |
4276 /* | |
4277 * Insert a backslash before characters in a tag name that | |
4278 * would terminate the ":tag" command. | |
4279 */ | |
4280 for (i = 0; i < numfiles; ++i) | |
4281 { | |
4282 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4283 if (p != NULL) | |
4284 { | |
4285 vim_free(files[i]); | |
4286 files[i] = p; | |
4287 } | |
4288 } | |
4289 } | |
4290 } | |
4291 } | |
4292 | |
4293 /* | |
1586 | 4294 * Escape special characters in "fname" for when used as a file name argument |
4295 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4296 * Returns the result in allocated memory. | |
4297 */ | |
4298 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4299 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4300 { |
1685 | 4301 char_u *p; |
1586 | 4302 #ifdef BACKSLASH_IN_FILENAME |
4303 char_u buf[20]; | |
4304 int j = 0; | |
4305 | |
5481 | 4306 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4307 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4308 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4309 buf[j++] = *p; |
4310 buf[j] = NUL; | |
1700 | 4311 p = vim_strsave_escaped(fname, buf); |
1586 | 4312 #else |
1685 | 4313 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4314 if (shell && csh_like_shell() && p != NULL) | |
4315 { | |
4316 char_u *s; | |
4317 | |
4318 /* For csh and similar shells need to put two backslashes before '!'. | |
4319 * One is taken by Vim, one by the shell. */ | |
4320 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4321 vim_free(p); | |
4322 p = s; | |
4323 } | |
1700 | 4324 #endif |
4325 | |
4326 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4327 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4328 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4329 escape_fname(&p); |
4330 | |
1685 | 4331 return p; |
1586 | 4332 } |
4333 | |
4334 /* | |
435 | 4335 * Put a backslash before the file name in "pp", which is in allocated memory. |
4336 */ | |
4337 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4338 escape_fname(char_u **pp) |
435 | 4339 { |
4340 char_u *p; | |
4341 | |
4342 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4343 if (p != NULL) | |
4344 { | |
4345 p[0] = '\\'; | |
4346 STRCPY(p + 1, *pp); | |
4347 vim_free(*pp); | |
4348 *pp = p; | |
4349 } | |
4350 } | |
4351 | |
4352 /* | |
7 | 4353 * For each file name in files[num_files]: |
4354 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4355 */ | |
4356 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4357 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4358 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4359 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4360 char_u **files) |
7 | 4361 { |
4362 int i; | |
4363 char_u *p; | |
4364 | |
4365 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4366 { | |
4367 for (i = 0; i < num_files; ++i) | |
4368 { | |
4369 p = home_replace_save(NULL, files[i]); | |
4370 if (p != NULL) | |
4371 { | |
4372 vim_free(files[i]); | |
4373 files[i] = p; | |
4374 } | |
4375 } | |
4376 } | |
4377 } | |
4378 | |
4379 /* | |
4380 * Show all matches for completion on the command line. | |
4381 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4382 * be inserted like a normal character. | |
4383 */ | |
4384 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4385 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4386 { |
4387 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4388 int num_files; | |
4389 char_u **files_found; | |
4390 int i, j, k; | |
4391 int maxlen; | |
4392 int lines; | |
4393 int columns; | |
4394 char_u *p; | |
4395 int lastlen; | |
4396 int attr; | |
4397 int showtail; | |
4398 | |
4399 if (xp->xp_numfiles == -1) | |
4400 { | |
4401 set_expand_context(xp); | |
4402 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4403 &num_files, &files_found); | |
4404 showtail = expand_showtail(xp); | |
4405 if (i != EXPAND_OK) | |
4406 return i; | |
4407 | |
4408 } | |
4409 else | |
4410 { | |
4411 num_files = xp->xp_numfiles; | |
4412 files_found = xp->xp_files; | |
4413 showtail = cmd_showtail; | |
4414 } | |
4415 | |
4416 #ifdef FEAT_WILDMENU | |
4417 if (!wildmenu) | |
4418 { | |
4419 #endif | |
4420 msg_didany = FALSE; /* lines_left will be set */ | |
4421 msg_start(); /* prepare for paging */ | |
4422 msg_putchar('\n'); | |
4423 out_flush(); | |
4424 cmdline_row = msg_row; | |
4425 msg_didany = FALSE; /* lines_left will be set again */ | |
4426 msg_start(); /* prepare for paging */ | |
4427 #ifdef FEAT_WILDMENU | |
4428 } | |
4429 #endif | |
4430 | |
4431 if (got_int) | |
4432 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4433 #ifdef FEAT_WILDMENU | |
4434 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
|
4435 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4436 #endif |
4437 else | |
4438 { | |
4439 /* find the length of the longest file name */ | |
4440 maxlen = 0; | |
4441 for (i = 0; i < num_files; ++i) | |
4442 { | |
4443 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4444 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4445 || xp->xp_context == EXPAND_BUFFERS)) |
4446 { | |
4447 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4448 j = vim_strsize(NameBuff); | |
4449 } | |
4450 else | |
4451 j = vim_strsize(L_SHOWFILE(i)); | |
4452 if (j > maxlen) | |
4453 maxlen = j; | |
4454 } | |
4455 | |
4456 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4457 lines = num_files; | |
4458 else | |
4459 { | |
4460 /* compute the number of columns and lines for the listing */ | |
4461 maxlen += 2; /* two spaces between file names */ | |
4462 columns = ((int)Columns + 2) / maxlen; | |
4463 if (columns < 1) | |
4464 columns = 1; | |
4465 lines = (num_files + columns - 1) / columns; | |
4466 } | |
4467 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4468 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4469 |
4470 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4471 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4472 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4473 msg_clr_eos(); |
4474 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
|
4475 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4476 } |
4477 | |
4478 /* list the files line by line */ | |
4479 for (i = 0; i < lines; ++i) | |
4480 { | |
4481 lastlen = 999; | |
4482 for (k = i; k < num_files; k += lines) | |
4483 { | |
4484 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4485 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4486 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4487 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4488 msg_advance(maxlen + 1); | |
4489 msg_puts(p); | |
4490 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
|
4491 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4492 break; |
4493 } | |
4494 for (j = maxlen - lastlen; --j >= 0; ) | |
4495 msg_putchar(' '); | |
4496 if (xp->xp_context == EXPAND_FILES | |
714 | 4497 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4498 || xp->xp_context == EXPAND_BUFFERS) |
4499 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4500 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4501 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4502 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4503 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4504 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4505 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4506 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4507 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4508 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4509 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
|
4510 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4511 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4512 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4513 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4514 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4515 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4516 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4517 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4518 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4519 j = mch_isdir(files_found[k]); |
7 | 4520 if (showtail) |
4521 p = L_SHOWFILE(k); | |
4522 else | |
4523 { | |
4524 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4525 TRUE); | |
4526 p = NameBuff; | |
4527 } | |
4528 } | |
4529 else | |
4530 { | |
4531 j = FALSE; | |
4532 p = L_SHOWFILE(k); | |
4533 } | |
4534 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4535 } | |
4536 if (msg_col > 0) /* when not wrapped around */ | |
4537 { | |
4538 msg_clr_eos(); | |
4539 msg_putchar('\n'); | |
4540 } | |
4541 out_flush(); /* show one line at a time */ | |
4542 if (got_int) | |
4543 { | |
4544 got_int = FALSE; | |
4545 break; | |
4546 } | |
4547 } | |
4548 | |
4549 /* | |
4550 * we redraw the command below the lines that we have just listed | |
4551 * This is a bit tricky, but it saves a lot of screen updating. | |
4552 */ | |
4553 cmdline_row = msg_row; /* will put it back later */ | |
4554 } | |
4555 | |
4556 if (xp->xp_numfiles == -1) | |
4557 FreeWild(num_files, files_found); | |
4558 | |
4559 return EXPAND_OK; | |
4560 } | |
4561 | |
4562 /* | |
4563 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4564 * Find tail of file name path, but ignore trailing "/". | |
4565 */ | |
4566 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4567 sm_gettail(char_u *s) |
7 | 4568 { |
4569 char_u *p; | |
4570 char_u *t = s; | |
4571 int had_sep = FALSE; | |
4572 | |
4573 for (p = s; *p != NUL; ) | |
4574 { | |
4575 if (vim_ispathsep(*p) | |
4576 #ifdef BACKSLASH_IN_FILENAME | |
4577 && !rem_backslash(p) | |
4578 #endif | |
4579 ) | |
4580 had_sep = TRUE; | |
4581 else if (had_sep) | |
4582 { | |
4583 t = p; | |
4584 had_sep = FALSE; | |
4585 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4586 MB_PTR_ADV(p); |
7 | 4587 } |
4588 return t; | |
4589 } | |
4590 | |
4591 /* | |
4592 * Return TRUE if we only need to show the tail of completion matches. | |
4593 * When not completing file names or there is a wildcard in the path FALSE is | |
4594 * returned. | |
4595 */ | |
4596 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4597 expand_showtail(expand_T *xp) |
7 | 4598 { |
4599 char_u *s; | |
4600 char_u *end; | |
4601 | |
4602 /* When not completing file names a "/" may mean something different. */ | |
714 | 4603 if (xp->xp_context != EXPAND_FILES |
4604 && xp->xp_context != EXPAND_SHELLCMD | |
4605 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4606 return FALSE; |
4607 | |
4608 end = gettail(xp->xp_pattern); | |
4609 if (end == xp->xp_pattern) /* there is no path separator */ | |
4610 return FALSE; | |
4611 | |
4612 for (s = xp->xp_pattern; s < end; s++) | |
4613 { | |
4614 /* Skip escaped wildcards. Only when the backslash is not a path | |
4615 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4616 if (rem_backslash(s)) | |
4617 ++s; | |
4618 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4619 return FALSE; | |
4620 } | |
4621 return TRUE; | |
4622 } | |
4623 | |
4624 /* | |
4625 * Prepare a string for expansion. | |
4626 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4627 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4628 * When expanding other names: The string will be used with regcomp(). Copy |
4629 * the name into allocated memory and prepend "^". | |
4630 */ | |
4631 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4632 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4633 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4634 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4635 int context) /* EXPAND_FILES etc. */ |
7 | 4636 { |
4637 char_u *retval; | |
4638 int i, j; | |
4639 int new_len; | |
4640 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4641 int ends_in_star; |
7 | 4642 |
714 | 4643 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4644 && context != EXPAND_FILES_IN_PATH |
714 | 4645 && context != EXPAND_SHELLCMD |
4646 && context != EXPAND_DIRECTORIES) | |
7 | 4647 { |
4648 /* | |
4649 * Matching will be done internally (on something other than files). | |
4650 * So we convert the file-matching-type wildcards into our kind for | |
4651 * use with vim_regcomp(). First work out how long it will be: | |
4652 */ | |
4653 | |
4654 /* For help tags the translation is done in find_help_tags(). | |
4655 * For a tag pattern starting with "/" no translation is needed. */ | |
4656 if (context == EXPAND_HELP | |
4657 || context == EXPAND_COLORS | |
4658 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4659 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4660 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4661 || 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
|
4662 || ((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
|
4663 || 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
|
4664 && fname[0] == '/')) |
7 | 4665 retval = vim_strnsave(fname, len); |
4666 else | |
4667 { | |
4668 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4669 for (i = 0; i < len; i++) | |
4670 { | |
4671 if (fname[i] == '*' || fname[i] == '~') | |
4672 new_len++; /* '*' needs to be replaced by ".*" | |
4673 '~' needs to be replaced by "\~" */ | |
4674 | |
4675 /* Buffer names are like file names. "." should be literal */ | |
4676 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4677 new_len++; /* "." becomes "\." */ | |
4678 | |
4679 /* Custom expansion takes care of special things, match | |
4680 * backslashes literally (perhaps also for other types?) */ | |
634 | 4681 if ((context == EXPAND_USER_DEFINED |
4682 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4683 new_len++; /* '\' becomes "\\" */ |
4684 } | |
4685 retval = alloc(new_len); | |
4686 if (retval != NULL) | |
4687 { | |
4688 retval[0] = '^'; | |
4689 j = 1; | |
4690 for (i = 0; i < len; i++, j++) | |
4691 { | |
4692 /* Skip backslash. But why? At least keep it for custom | |
4693 * expansion. */ | |
4694 if (context != EXPAND_USER_DEFINED | |
407 | 4695 && context != EXPAND_USER_LIST |
4696 && fname[i] == '\\' | |
4697 && ++i == len) | |
7 | 4698 break; |
4699 | |
4700 switch (fname[i]) | |
4701 { | |
4702 case '*': retval[j++] = '.'; | |
4703 break; | |
4704 case '~': retval[j++] = '\\'; | |
4705 break; | |
4706 case '?': retval[j] = '.'; | |
4707 continue; | |
4708 case '.': if (context == EXPAND_BUFFERS) | |
4709 retval[j++] = '\\'; | |
4710 break; | |
407 | 4711 case '\\': if (context == EXPAND_USER_DEFINED |
4712 || context == EXPAND_USER_LIST) | |
7 | 4713 retval[j++] = '\\'; |
4714 break; | |
4715 } | |
4716 retval[j] = fname[i]; | |
4717 } | |
4718 retval[j] = NUL; | |
4719 } | |
4720 } | |
4721 } | |
4722 else | |
4723 { | |
4724 retval = alloc(len + 4); | |
4725 if (retval != NULL) | |
4726 { | |
419 | 4727 vim_strncpy(retval, fname, len); |
7 | 4728 |
4729 /* | |
831 | 4730 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4731 * * would become **, which walks the whole tree. | |
7 | 4732 * ~ would be at the start of the file name, but not the tail. |
4733 * $ could be anywhere in the tail. | |
4734 * ` could be anywhere in the file name. | |
1484 | 4735 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4736 */ |
4737 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4738 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
|
4739 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4740 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4741 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4742 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4743 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4744 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4745 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4746 #endif |
7 | 4747 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4748 && !ends_in_star |
7 | 4749 && vim_strchr(tail, '$') == NULL |
4750 && vim_strchr(retval, '`') == NULL) | |
4751 retval[len++] = '*'; | |
1484 | 4752 else if (len > 0 && retval[len - 1] == '$') |
4753 --len; | |
7 | 4754 retval[len] = NUL; |
4755 } | |
4756 } | |
4757 return retval; | |
4758 } | |
4759 | |
4760 /* | |
4761 * Must parse the command line so far to work out what context we are in. | |
4762 * Completion can then be done based on that context. | |
4763 * This routine sets the variables: | |
4764 * xp->xp_pattern The start of the pattern to be expanded within | |
4765 * the command line (ends at the cursor). | |
4766 * xp->xp_context The type of thing to expand. Will be one of: | |
4767 * | |
4768 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4769 * the command line, like an unknown command. Caller | |
4770 * should beep. | |
4771 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4772 * a normal char, rather than for completion. eg | |
4773 * :s/^I/ | |
4774 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4775 * it. | |
4776 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4777 * EXPAND_FILES After command with XFILE set, or after setting | |
4778 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4779 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4780 * when we know only directories are of interest. eg | |
4781 * :set dir=^I | |
714 | 4782 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4783 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4784 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4785 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4786 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4787 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4788 * EXPAND_EVENTS Complete event names | |
4789 * EXPAND_SYNTAX Complete :syntax command arguments | |
4790 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4791 * EXPAND_AUGROUP Complete autocommand group names | |
4792 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4793 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4794 * eg :unmap a^I , :cunab x^I | |
4795 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4796 * eg :call sub^I | |
4797 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4798 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4799 * names in expressions, eg :while s^I | |
4800 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4801 * EXPAND_USER Complete user names |
7 | 4802 */ |
4803 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4804 set_expand_context(expand_T *xp) |
7 | 4805 { |
168 | 4806 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4807 if (ccline.cmdfirstc != ':' |
4808 #ifdef FEAT_EVAL | |
168 | 4809 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4810 && !ccline.input_fn |
7 | 4811 #endif |
4812 ) | |
4813 { | |
4814 xp->xp_context = EXPAND_NOTHING; | |
4815 return; | |
4816 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4817 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4818 } |
4819 | |
4820 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4821 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4822 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4823 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
|
4824 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
|
4825 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4826 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4827 { |
4828 int old_char = NUL; | |
4829 char_u *nextcomm; | |
4830 | |
4831 /* | |
4832 * Avoid a UMR warning from Purify, only save the character if it has been | |
4833 * written before. | |
4834 */ | |
4835 if (col < len) | |
4836 old_char = str[col]; | |
4837 str[col] = NUL; | |
4838 nextcomm = str; | |
168 | 4839 |
4840 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4841 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4842 { |
4843 # ifdef FEAT_CMDL_COMPL | |
168 | 4844 /* pass CMD_SIZE because there is no real command */ |
4845 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4846 # endif |
4847 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4848 else if (use_ccline && ccline.input_fn) |
531 | 4849 { |
4850 xp->xp_context = ccline.xp_context; | |
4851 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4852 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4853 xp->xp_arg = ccline.xp_arg; |
1322 | 4854 # endif |
531 | 4855 } |
168 | 4856 else |
4857 #endif | |
4858 while (nextcomm != NULL) | |
4859 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4860 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4861 /* 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
|
4862 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4863 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4864 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4865 |
7 | 4866 str[col] = old_char; |
4867 } | |
4868 | |
4869 /* | |
4870 * Expand the command line "str" from context "xp". | |
4871 * "xp" must have been set by set_cmd_context(). | |
4872 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4873 * starts. | |
4874 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4875 * cursor. | |
4876 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4877 * key that triggered expansion literally. | |
4878 * Returns EXPAND_OK otherwise. | |
4879 */ | |
4880 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4881 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4882 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4883 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
|
4884 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4885 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4886 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4887 { |
4888 char_u *file_str = NULL; | |
2652 | 4889 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4890 |
4891 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4892 { | |
4893 beep_flush(); | |
4894 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4895 } | |
4896 if (xp->xp_context == EXPAND_NOTHING) | |
4897 { | |
4898 /* Caller can use the character as a normal char instead */ | |
4899 return EXPAND_NOTHING; | |
4900 } | |
4901 | |
4902 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 4903 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
4904 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 4905 if (file_str == NULL) |
4906 return EXPAND_UNSUCCESSFUL; | |
4907 | |
2652 | 4908 if (p_wic) |
4909 options += WILD_ICASE; | |
4910 | |
7 | 4911 /* find all files that match the description */ |
2652 | 4912 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 4913 { |
4914 *matchcount = 0; | |
4915 *matches = NULL; | |
4916 } | |
4917 vim_free(file_str); | |
4918 | |
4919 return EXPAND_OK; | |
4920 } | |
4921 | |
4922 #ifdef FEAT_MULTI_LANG | |
4923 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4924 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4925 * 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
|
4926 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 4927 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
4928 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 4929 |
4930 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4931 cleanup_help_tags(int num_file, char_u **file) |
7 | 4932 { |
4933 int i, j; | |
4934 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4935 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4936 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4937 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4938 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
|
4939 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4940 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4941 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4942 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4943 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4944 *p = NUL; |
7 | 4945 |
4946 for (i = 0; i < num_file; ++i) | |
4947 { | |
4948 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
|
4949 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4950 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4951 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 4952 { |
4953 /* Sorting on priority means the same item in another language may | |
4954 * be anywhere. Search all items for a match up to the "@en". */ | |
4955 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
|
4956 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
|
4957 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 4958 break; |
4959 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4960 /* item only exists with @en, remove it */ |
7 | 4961 file[i][len] = NUL; |
4962 } | |
4963 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4964 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4965 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4966 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
|
4967 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4968 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4969 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4970 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4971 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
|
4972 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4973 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4974 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4975 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4976 } |
7 | 4977 } |
4978 #endif | |
4979 | |
4980 /* | |
4981 * Do the expansion based on xp->xp_context and "pat". | |
4982 */ | |
4983 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4984 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4985 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4986 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4987 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4988 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4989 int options) /* EW_ flags */ |
7 | 4990 { |
4991 #ifdef FEAT_CMDL_COMPL | |
4992 regmatch_T regmatch; | |
4993 #endif | |
4994 int ret; | |
4995 int flags; | |
4996 | |
4997 flags = EW_DIR; /* include directories */ | |
4998 if (options & WILD_LIST_NOTFOUND) | |
4999 flags |= EW_NOTFOUND; | |
5000 if (options & WILD_ADD_SLASH) | |
5001 flags |= EW_ADDSLASH; | |
5002 if (options & WILD_KEEP_ALL) | |
5003 flags |= EW_KEEPALL; | |
5004 if (options & WILD_SILENT) | |
5005 flags |= EW_SILENT; | |
6659 | 5006 if (options & WILD_ALLLINKS) |
5007 flags |= EW_ALLLINKS; | |
7 | 5008 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5009 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5010 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5011 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5012 { |
5013 /* | |
5014 * Expand file or directory names. | |
5015 */ | |
5016 int free_pat = FALSE; | |
5017 int i; | |
5018 | |
5019 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5020 * space */ | |
5021 if (xp->xp_backslash != XP_BS_NONE) | |
5022 { | |
5023 free_pat = TRUE; | |
5024 pat = vim_strsave(pat); | |
5025 for (i = 0; pat[i]; ++i) | |
5026 if (pat[i] == '\\') | |
5027 { | |
5028 if (xp->xp_backslash == XP_BS_THREE | |
5029 && pat[i + 1] == '\\' | |
5030 && pat[i + 2] == '\\' | |
5031 && pat[i + 3] == ' ') | |
1621 | 5032 STRMOVE(pat + i, pat + i + 3); |
7 | 5033 if (xp->xp_backslash == XP_BS_ONE |
5034 && pat[i + 1] == ' ') | |
1621 | 5035 STRMOVE(pat + i, pat + i + 1); |
7 | 5036 } |
5037 } | |
5038 | |
5039 if (xp->xp_context == EXPAND_FILES) | |
5040 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5041 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
|
5042 flags |= (EW_FILE | EW_PATH); |
7 | 5043 else |
5044 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5045 if (options & WILD_ICASE) |
5046 flags |= EW_ICASE; | |
5047 | |
2016 | 5048 /* Expand wildcards, supporting %:h and the like. */ |
5049 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5050 if (free_pat) |
5051 vim_free(pat); | |
5052 return ret; | |
5053 } | |
5054 | |
5055 *file = (char_u **)""; | |
5056 *num_file = 0; | |
5057 if (xp->xp_context == EXPAND_HELP) | |
5058 { | |
1696 | 5059 /* With an empty argument we would get all the help tags, which is |
5060 * very slow. Get matches for "help" instead. */ | |
5061 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5062 num_file, file, FALSE) == OK) | |
7 | 5063 { |
5064 #ifdef FEAT_MULTI_LANG | |
5065 cleanup_help_tags(*num_file, *file); | |
5066 #endif | |
5067 return OK; | |
5068 } | |
5069 return FAIL; | |
5070 } | |
5071 | |
5072 #ifndef FEAT_CMDL_COMPL | |
5073 return FAIL; | |
5074 #else | |
716 | 5075 if (xp->xp_context == EXPAND_SHELLCMD) |
5076 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5077 if (xp->xp_context == EXPAND_OLD_SETTING) |
5078 return ExpandOldSetting(num_file, file); | |
5079 if (xp->xp_context == EXPAND_BUFFERS) | |
5080 return ExpandBufnames(pat, num_file, file, options); | |
5081 if (xp->xp_context == EXPAND_TAGS | |
5082 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5083 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5084 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5085 { |
5086 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5087 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
|
5088 directories); |
2929 | 5089 } |
7 | 5090 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5091 { |
3106 | 5092 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5093 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5094 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5095 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5096 { |
5097 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5098 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5099 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5100 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5101 { |
5102 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
|
5103 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5104 } |
407 | 5105 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5106 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5107 return ExpandUserList(xp, num_file, file); |
407 | 5108 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5109 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5110 return ExpandPackAddDir(pat, num_file, file); |
7 | 5111 |
5112 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5113 if (regmatch.regprog == NULL) | |
5114 return FAIL; | |
5115 | |
5116 /* set ignore-case according to p_ic, p_scs and pat */ | |
5117 regmatch.rm_ic = ignorecase(pat); | |
5118 | |
5119 if (xp->xp_context == EXPAND_SETTINGS | |
5120 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5121 ret = ExpandSettings(xp, ®match, num_file, file); | |
5122 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5123 ret = ExpandMappings(®match, num_file, file); | |
5124 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5125 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5126 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5127 # endif | |
5128 else | |
5129 { | |
5130 static struct expgen | |
5131 { | |
5132 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5133 char_u *((*func)(expand_T *, int)); |
7 | 5134 int ic; |
2849 | 5135 int escaped; |
7 | 5136 } tab[] = |
5137 { | |
2849 | 5138 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5139 {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
|
5140 {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
|
5141 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5142 #ifdef FEAT_CMDHIST |
5143 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5144 #endif | |
7 | 5145 #ifdef FEAT_USR_CMDS |
2849 | 5146 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5147 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5148 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5149 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5150 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5151 #endif |
5152 #ifdef FEAT_EVAL | |
2849 | 5153 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5154 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5155 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5156 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5157 #endif |
5158 #ifdef FEAT_MENU | |
2849 | 5159 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5160 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5161 #endif |
5162 #ifdef FEAT_SYN_HL | |
2849 | 5163 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5164 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5165 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5166 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5167 #endif |
2849 | 5168 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5169 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5170 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5171 #ifdef FEAT_CSCOPE |
2849 | 5172 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5173 #endif |
1868 | 5174 #ifdef FEAT_SIGNS |
2849 | 5175 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5176 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5177 #ifdef FEAT_PROFILE |
2849 | 5178 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5179 #endif |
7 | 5180 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5181 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5182 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5183 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5184 #endif | |
5185 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5186 {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
|
5187 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5188 }; |
5189 int i; | |
5190 | |
5191 /* | |
5192 * Find a context in the table and call the ExpandGeneric() with the | |
5193 * right function to do the expansion. | |
5194 */ | |
5195 ret = FAIL; | |
1880 | 5196 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5197 if (xp->xp_context == tab[i].context) |
5198 { | |
5199 if (tab[i].ic) | |
5200 regmatch.rm_ic = TRUE; | |
2849 | 5201 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5202 tab[i].func, tab[i].escaped); |
7 | 5203 break; |
5204 } | |
5205 } | |
5206 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5207 vim_regfree(regmatch.regprog); |
7 | 5208 |
5209 return ret; | |
5210 #endif /* FEAT_CMDL_COMPL */ | |
5211 } | |
5212 | |
5213 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5214 /* | |
5215 * Expand a list of names. | |
5216 * | |
5217 * Generic function for command line completion. It calls a function to | |
5218 * obtain strings, one by one. The strings are matched against a regexp | |
5219 * program. Matching strings are copied into an array, which is returned. | |
5220 * | |
5221 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5222 */ | |
5223 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5224 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5225 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5226 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5227 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5228 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5229 char_u *((*func)(expand_T *, int)), |
7 | 5230 /* 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
|
5231 int escaped) |
7 | 5232 { |
5233 int i; | |
5234 int count = 0; | |
480 | 5235 int round; |
7 | 5236 char_u *str; |
5237 | |
5238 /* do this loop twice: | |
480 | 5239 * round == 0: count the number of matching names |
5240 * round == 1: copy the matching names into allocated memory | |
7 | 5241 */ |
480 | 5242 for (round = 0; round <= 1; ++round) |
7 | 5243 { |
5244 for (i = 0; ; ++i) | |
5245 { | |
5246 str = (*func)(xp, i); | |
5247 if (str == NULL) /* end of list */ | |
5248 break; | |
5249 if (*str == NUL) /* skip empty strings */ | |
5250 continue; | |
5251 | |
5252 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5253 { | |
480 | 5254 if (round) |
7 | 5255 { |
2849 | 5256 if (escaped) |
5257 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5258 else | |
5259 str = vim_strsave(str); | |
7 | 5260 (*file)[count] = str; |
5261 #ifdef FEAT_MENU | |
5262 if (func == get_menu_names && str != NULL) | |
5263 { | |
5264 /* test for separator added by get_menu_names() */ | |
5265 str += STRLEN(str) - 1; | |
5266 if (*str == '\001') | |
5267 *str = '.'; | |
5268 } | |
5269 #endif | |
5270 } | |
5271 ++count; | |
5272 } | |
5273 } | |
480 | 5274 if (round == 0) |
7 | 5275 { |
5276 if (count == 0) | |
5277 return OK; | |
5278 *num_file = count; | |
5279 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5280 if (*file == NULL) | |
5281 { | |
5282 *file = (char_u **)""; | |
5283 return FAIL; | |
5284 } | |
5285 count = 0; | |
5286 } | |
5287 } | |
480 | 5288 |
828 | 5289 /* Sort the results. Keep menu's in the specified order. */ |
5290 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5291 { |
5292 if (xp->xp_context == EXPAND_EXPRESSION | |
5293 || xp->xp_context == EXPAND_FUNCTIONS | |
5294 || xp->xp_context == EXPAND_USER_FUNC) | |
5295 /* <SNR> functions should be sorted to the end. */ | |
5296 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5297 sort_func_compare); | |
5298 else | |
5299 sort_strings(*file, *num_file); | |
5300 } | |
480 | 5301 |
1322 | 5302 #ifdef FEAT_CMDL_COMPL |
5303 /* Reset the variables used for special highlight names expansion, so that | |
5304 * they don't show up when getting normal highlight names by ID. */ | |
5305 reset_expand_highlight(); | |
5306 #endif | |
5307 | |
7 | 5308 return OK; |
5309 } | |
5310 | |
716 | 5311 /* |
5312 * Complete a shell command. | |
5313 * Returns FAIL or OK; | |
5314 */ | |
5315 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5316 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5317 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
|
5318 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
|
5319 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
|
5320 int flagsarg) /* EW_ flags */ |
716 | 5321 { |
5322 char_u *pat; | |
5323 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5324 char_u *path = NULL; |
716 | 5325 int mustfree = FALSE; |
5326 garray_T ga; | |
5327 char_u *buf = alloc(MAXPATHL); | |
5328 size_t l; | |
5329 char_u *s, *e; | |
5330 int flags = flagsarg; | |
5331 int ret; | |
6695 | 5332 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5333 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5334 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5335 hash_T hash; |
716 | 5336 |
5337 if (buf == NULL) | |
5338 return FAIL; | |
5339 | |
5340 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5341 * space */ | |
5342 pat = vim_strsave(filepat); | |
5343 for (i = 0; pat[i]; ++i) | |
5344 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5345 STRMOVE(pat + i, pat + i + 1); |
716 | 5346 |
6695 | 5347 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5348 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5349 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
|
5350 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5351 path = (char_u *)"."; |
5352 else | |
2630 | 5353 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5354 /* 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
|
5355 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5356 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5357 if (path == NULL) |
5358 path = (char_u *)""; | |
5359 } | |
716 | 5360 |
5361 /* | |
5362 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5363 * collect them in "ga". When "." is not in $PATH also expand for the |
5364 * current directory, to find "subdir/cmd". | |
716 | 5365 */ |
5366 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
|
5367 hash_init(&found_ht); |
6695 | 5368 for (s = path; ; s = e) |
716 | 5369 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5370 #if defined(MSWIN) |
716 | 5371 e = vim_strchr(s, ';'); |
5372 #else | |
5373 e = vim_strchr(s, ':'); | |
5374 #endif | |
5375 if (e == NULL) | |
5376 e = s + STRLEN(s); | |
5377 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5378 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
|
5379 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5380 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
|
5381 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5382 // 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
|
5383 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
|
5384 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
|
5385 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5386 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
|
5387 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5388 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
|
5389 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
|
5390 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5391 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5392 // 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
|
5393 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
|
5394 |
716 | 5395 l = e - s; |
5396 if (l > MAXPATHL - 5) | |
5397 break; | |
5398 vim_strncpy(buf, s, l); | |
5399 add_pathsep(buf); | |
5400 l = STRLEN(buf); | |
5401 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5402 | |
5403 /* Expand matches in one directory of $PATH. */ | |
5404 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5405 if (ret == OK) | |
5406 { | |
5407 if (ga_grow(&ga, *num_file) == FAIL) | |
5408 FreeWild(*num_file, *file); | |
5409 else | |
5410 { | |
5411 for (i = 0; i < *num_file; ++i) | |
5412 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5413 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5414 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5415 if (STRLEN(name) > l) |
716 | 5416 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5417 // 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
|
5418 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5419 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
|
5420 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5421 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5422 // 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
|
5423 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5424 ((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
|
5425 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
|
5426 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5427 } |
716 | 5428 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5429 vim_free(name); |
716 | 5430 } |
5431 vim_free(*file); | |
5432 } | |
5433 } | |
5434 if (*e != NUL) | |
5435 ++e; | |
5436 } | |
5437 *file = ga.ga_data; | |
5438 *num_file = ga.ga_len; | |
5439 | |
5440 vim_free(buf); | |
5441 vim_free(pat); | |
5442 if (mustfree) | |
5443 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5444 hash_clear(&found_ht); |
716 | 5445 return OK; |
5446 } | |
5447 | |
5448 | |
7 | 5449 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5450 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5451 * 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
|
5452 * return the result (either a string or a List). |
7 | 5453 */ |
407 | 5454 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5455 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
|
5456 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
|
5457 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5458 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5459 char_u ***file) |
7 | 5460 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5461 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
|
5462 typval_T args[4]; |
7 | 5463 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
|
5464 char_u *pat = NULL; |
407 | 5465 void *ret; |
13 | 5466 struct cmdline_info save_ccline; |
7 | 5467 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5468 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5469 return NULL; |
7 | 5470 *num_file = 0; |
5471 *file = NULL; | |
5472 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5473 if (ccline.cmdbuff != NULL) |
1518 | 5474 { |
5475 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5476 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5477 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5478 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5479 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
|
5480 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5481 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
|
5482 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
|
5483 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
|
5484 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
|
5485 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
|
5486 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
|
5487 args[3].v_type = VAR_UNKNOWN; |
7 | 5488 |
13 | 5489 /* Save the cmdline, we don't know what the function may do. */ |
5490 save_ccline = ccline; | |
5491 ccline.cmdbuff = NULL; | |
5492 ccline.cmdprompt = NULL; | |
7 | 5493 current_SID = xp->xp_scriptID; |
13 | 5494 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5495 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5496 |
5497 ccline = save_ccline; | |
7 | 5498 current_SID = save_current_SID; |
1518 | 5499 if (ccline.cmdbuff != NULL) |
5500 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5501 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5502 vim_free(pat); |
407 | 5503 return ret; |
5504 } | |
5505 | |
5506 /* | |
5507 * Expand names with a function defined by the user. | |
5508 */ | |
5509 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5510 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5511 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5512 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5513 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5514 char_u ***file) |
407 | 5515 { |
5516 char_u *retstr; | |
5517 char_u *s; | |
5518 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
|
5519 int keep; |
407 | 5520 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
|
5521 int skip; |
407 | 5522 |
5523 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5524 if (retstr == NULL) | |
7 | 5525 return FAIL; |
5526 | |
5527 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5528 for (s = retstr; *s != NUL; s = e) |
7 | 5529 { |
5530 e = vim_strchr(s, '\n'); | |
5531 if (e == NULL) | |
5532 e = s + STRLEN(s); | |
5533 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
|
5534 *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
|
5535 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5536 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
|
5537 *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
|
5538 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5539 if (!skip) |
7 | 5540 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5541 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
|
5542 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5543 ((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
|
5544 ++ga.ga_len; |
7 | 5545 } |
5546 | |
5547 if (*e != NUL) | |
5548 ++e; | |
5549 } | |
407 | 5550 vim_free(retstr); |
5551 *file = ga.ga_data; | |
5552 *num_file = ga.ga_len; | |
5553 return OK; | |
5554 } | |
5555 | |
5556 /* | |
5557 * Expand names with a list returned by a function defined by the user. | |
5558 */ | |
5559 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5560 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5561 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5562 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5563 char_u ***file) |
407 | 5564 { |
5565 list_T *retlist; | |
5566 listitem_T *li; | |
5567 garray_T ga; | |
5568 | |
5569 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5570 if (retlist == NULL) | |
5571 return FAIL; | |
5572 | |
5573 ga_init2(&ga, (int)sizeof(char *), 3); | |
5574 /* Loop over the items in the list. */ | |
5575 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5576 { | |
1917 | 5577 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5578 continue; /* Skip non-string items and empty strings */ | |
407 | 5579 |
5580 if (ga_grow(&ga, 1) == FAIL) | |
5581 break; | |
5582 | |
5583 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5584 vim_strsave(li->li_tv.vval.v_string); |
407 | 5585 ++ga.ga_len; |
5586 } | |
5587 list_unref(retlist); | |
5588 | |
7 | 5589 *file = ga.ga_data; |
5590 *num_file = ga.ga_len; | |
5591 return OK; | |
5592 } | |
5593 #endif | |
5594 | |
5595 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5596 * 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
|
5597 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5598 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5599 * 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
|
5600 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5601 * 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
|
5602 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5603 * "dirnames" is an array with one or more directory names. |
7 | 5604 */ |
5605 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5606 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5607 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5608 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5609 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5610 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5611 char *dirnames[]) |
7 | 5612 { |
5613 char_u *s; | |
5614 char_u *e; | |
5873 | 5615 char_u *match; |
7 | 5616 garray_T ga; |
2929 | 5617 int i; |
5618 int pat_len; | |
7 | 5619 |
5620 *num_file = 0; | |
5621 *file = NULL; | |
2931 | 5622 pat_len = (int)STRLEN(pat); |
2929 | 5623 ga_init2(&ga, (int)sizeof(char *), 10); |
5624 | |
5625 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5626 { |
2929 | 5627 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5628 if (s == NULL) | |
5629 { | |
5630 ga_clear_strings(&ga); | |
5631 return FAIL; | |
5632 } | |
5633 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5634 globpath(p_rtp, s, &ga, 0); |
2929 | 5635 vim_free(s); |
5873 | 5636 } |
5637 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5638 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5639 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
|
5640 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5641 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
|
5642 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5643 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5644 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5645 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5646 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5647 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
|
5648 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5649 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5650 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5651 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5652 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5653 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5654 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
|
5655 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5656 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
|
5657 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5658 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5659 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5660 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5661 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5662 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
|
5663 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5664 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5665 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5666 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5667 |
5873 | 5668 for (i = 0; i < ga.ga_len; ++i) |
5669 { | |
5670 match = ((char_u **)ga.ga_data)[i]; | |
5671 s = match; | |
5672 e = s + STRLEN(s); | |
5673 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5674 { |
5873 | 5675 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5676 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5677 if (s < match || vim_ispathsep(*s)) |
5678 break; | |
5679 ++s; | |
5680 *e = NUL; | |
5681 mch_memmove(match, s, e - s + 1); | |
7 | 5682 } |
5683 } | |
5873 | 5684 |
2929 | 5685 if (ga.ga_len == 0) |
3628 | 5686 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5687 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5688 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5689 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5690 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5691 |
7 | 5692 *file = ga.ga_data; |
5693 *num_file = ga.ga_len; | |
5694 return OK; | |
5695 } | |
5696 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5697 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5698 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5699 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5700 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5701 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5702 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5703 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5704 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5705 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5706 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5707 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5708 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5709 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5710 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5711 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5712 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5713 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5714 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5715 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5716 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5717 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
|
5718 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5719 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5720 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5721 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5722 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5723 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5724 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5725 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
|
5726 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5727 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5728 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5729 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
|
5730 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5731 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
|
5732 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5733 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5734 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
|
5735 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5736 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5737 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5738 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5739 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5740 /* 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
|
5741 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5742 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5743 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5744 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5745 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5746 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5747 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5748 |
7 | 5749 #endif |
5750 | |
5751 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5752 /* | |
5753 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5754 * Adds the matches to "ga". Caller must init "ga". |
7 | 5755 */ |
5873 | 5756 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5757 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5758 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5759 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5760 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5761 int expand_options) |
7 | 5762 { |
5763 expand_T xpc; | |
5764 char_u *buf; | |
5765 int i; | |
5766 int num_p; | |
5767 char_u **p; | |
5768 | |
5769 buf = alloc(MAXPATHL); | |
5770 if (buf == NULL) | |
5873 | 5771 return; |
7 | 5772 |
632 | 5773 ExpandInit(&xpc); |
7 | 5774 xpc.xp_context = EXPAND_FILES; |
632 | 5775 |
7 | 5776 /* Loop over all entries in {path}. */ |
5777 while (*path != NUL) | |
5778 { | |
5779 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5780 copy_option_part(&path, buf, MAXPATHL, ","); | |
5781 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5782 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5783 # 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
|
5784 /* 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
|
5785 * 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
|
5786 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
|
5787 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5788 # else |
7 | 5789 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
|
5790 # endif |
7 | 5791 STRCAT(buf, file); |
1754 | 5792 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5793 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5794 { |
1754 | 5795 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5796 |
5797 if (ga_grow(ga, num_p) == OK) | |
7 | 5798 { |
5799 for (i = 0; i < num_p; ++i) | |
5800 { | |
5873 | 5801 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5802 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5803 ++ga->ga_len; |
7 | 5804 } |
5805 } | |
5873 | 5806 |
7 | 5807 FreeWild(num_p, p); |
5808 } | |
5809 } | |
5810 } | |
5811 | |
5812 vim_free(buf); | |
5813 } | |
5814 | |
5815 #endif | |
5816 | |
5817 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5818 | |
5819 /********************************* | |
5820 * Command line history stuff * | |
5821 *********************************/ | |
5822 | |
5823 /* | |
5824 * Translate a history character to the associated type number. | |
5825 */ | |
5826 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5827 hist_char2type(int c) |
7 | 5828 { |
5829 if (c == ':') | |
5830 return HIST_CMD; | |
5831 if (c == '=') | |
5832 return HIST_EXPR; | |
5833 if (c == '@') | |
5834 return HIST_INPUT; | |
5835 if (c == '>') | |
5836 return HIST_DEBUG; | |
5837 return HIST_SEARCH; /* must be '?' or '/' */ | |
5838 } | |
5839 | |
5840 /* | |
5841 * Table of history names. | |
5842 * These names are used in :history and various hist...() functions. | |
5843 * It is sufficient to give the significant prefix of a history name. | |
5844 */ | |
5845 | |
5846 static char *(history_names[]) = | |
5847 { | |
5848 "cmd", | |
5849 "search", | |
5850 "expr", | |
5851 "input", | |
5852 "debug", | |
5853 NULL | |
5854 }; | |
5855 | |
3503 | 5856 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5857 /* | |
5858 * Function given to ExpandGeneric() to obtain the possible first | |
5859 * arguments of the ":history command. | |
5860 */ | |
5861 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5862 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5863 { |
5864 static char_u compl[2] = { NUL, NUL }; | |
5865 char *short_names = ":=@>?/"; | |
3529 | 5866 int short_names_count = (int)STRLEN(short_names); |
3503 | 5867 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5868 | |
5869 if (idx < short_names_count) | |
5870 { | |
5871 compl[0] = (char_u)short_names[idx]; | |
5872 return compl; | |
5873 } | |
5874 if (idx < short_names_count + history_name_count) | |
5875 return (char_u *)history_names[idx - short_names_count]; | |
5876 if (idx == short_names_count + history_name_count) | |
5877 return (char_u *)"all"; | |
5878 return NULL; | |
5879 } | |
5880 #endif | |
5881 | |
7 | 5882 /* |
5883 * init_history() - Initialize the command line history. | |
5884 * Also used to re-allocate the history when the size changes. | |
5885 */ | |
356 | 5886 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5887 init_history(void) |
7 | 5888 { |
5889 int newlen; /* new length of history table */ | |
5890 histentry_T *temp; | |
5891 int i; | |
5892 int j; | |
5893 int type; | |
5894 | |
5895 /* | |
5896 * If size of history table changed, reallocate it | |
5897 */ | |
5898 newlen = (int)p_hi; | |
5899 if (newlen != hislen) /* history length changed */ | |
5900 { | |
5901 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
5902 { | |
5903 if (newlen) | |
5904 { | |
5905 temp = (histentry_T *)lalloc( | |
5906 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
5907 if (temp == NULL) /* out of memory! */ | |
5908 { | |
5909 if (type == 0) /* first one: just keep the old length */ | |
5910 { | |
5911 newlen = hislen; | |
5912 break; | |
5913 } | |
5914 /* Already changed one table, now we can only have zero | |
5915 * length for all tables. */ | |
5916 newlen = 0; | |
5917 type = -1; | |
5918 continue; | |
5919 } | |
5920 } | |
5921 else | |
5922 temp = NULL; | |
5923 if (newlen == 0 || temp != NULL) | |
5924 { | |
5925 if (hisidx[type] < 0) /* there are no entries yet */ | |
5926 { | |
5927 for (i = 0; i < newlen; ++i) | |
4258 | 5928 clear_hist_entry(&temp[i]); |
7 | 5929 } |
5930 else if (newlen > hislen) /* array becomes bigger */ | |
5931 { | |
5932 for (i = 0; i <= hisidx[type]; ++i) | |
5933 temp[i] = history[type][i]; | |
5934 j = i; | |
5935 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 5936 clear_hist_entry(&temp[i]); |
7 | 5937 for ( ; j < hislen; ++i, ++j) |
5938 temp[i] = history[type][j]; | |
5939 } | |
5940 else /* array becomes smaller or 0 */ | |
5941 { | |
5942 j = hisidx[type]; | |
5943 for (i = newlen - 1; ; --i) | |
5944 { | |
5945 if (i >= 0) /* copy newest entries */ | |
5946 temp[i] = history[type][j]; | |
5947 else /* remove older entries */ | |
5948 vim_free(history[type][j].hisstr); | |
5949 if (--j < 0) | |
5950 j = hislen - 1; | |
5951 if (j == hisidx[type]) | |
5952 break; | |
5953 } | |
5954 hisidx[type] = newlen - 1; | |
5955 } | |
5956 vim_free(history[type]); | |
5957 history[type] = temp; | |
5958 } | |
5959 } | |
5960 hislen = newlen; | |
5961 } | |
5962 } | |
5963 | |
4258 | 5964 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5965 clear_hist_entry(histentry_T *hisptr) |
4258 | 5966 { |
5967 hisptr->hisnum = 0; | |
5968 hisptr->viminfo = FALSE; | |
5969 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
5970 hisptr->time_set = 0; |
4258 | 5971 } |
5972 | |
7 | 5973 /* |
5974 * Check if command line 'str' is already in history. | |
5975 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
5976 */ | |
5977 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5978 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5979 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5980 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5981 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
|
5982 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5983 int writing) /* ignore entries read from viminfo */ |
7 | 5984 { |
5985 int i; | |
5986 int last_i = -1; | |
2986 | 5987 char_u *p; |
7 | 5988 |
5989 if (hisidx[type] < 0) | |
5990 return FALSE; | |
5991 i = hisidx[type]; | |
5992 do | |
5993 { | |
5994 if (history[type][i].hisstr == NULL) | |
5995 return FALSE; | |
2986 | 5996 |
5997 /* For search history, check that the separator character matches as | |
5998 * well. */ | |
5999 p = history[type][i].hisstr; | |
6000 if (STRCMP(str, p) == 0 | |
4285 | 6001 && !(writing && history[type][i].viminfo) |
2986 | 6002 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6003 { |
6004 if (!move_to_front) | |
6005 return TRUE; | |
6006 last_i = i; | |
6007 break; | |
6008 } | |
6009 if (--i < 0) | |
6010 i = hislen - 1; | |
6011 } while (i != hisidx[type]); | |
6012 | |
6013 if (last_i >= 0) | |
6014 { | |
6015 str = history[type][i].hisstr; | |
6016 while (i != hisidx[type]) | |
6017 { | |
6018 if (++i >= hislen) | |
6019 i = 0; | |
6020 history[type][last_i] = history[type][i]; | |
6021 last_i = i; | |
6022 } | |
4258 | 6023 history[type][i].hisnum = ++hisnum[type]; |
6024 history[type][i].viminfo = FALSE; | |
7 | 6025 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6026 history[type][i].time_set = vim_time(); |
7 | 6027 return TRUE; |
6028 } | |
6029 return FALSE; | |
6030 } | |
6031 | |
6032 /* | |
6033 * Convert history name (from table above) to its HIST_ equivalent. | |
6034 * When "name" is empty, return "cmd" history. | |
6035 * Returns -1 for unknown history name. | |
6036 */ | |
6037 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6038 get_histtype(char_u *name) |
7 | 6039 { |
6040 int i; | |
6041 int len = (int)STRLEN(name); | |
6042 | |
6043 /* No argument: use current history. */ | |
6044 if (len == 0) | |
6045 return hist_char2type(ccline.cmdfirstc); | |
6046 | |
6047 for (i = 0; history_names[i] != NULL; ++i) | |
6048 if (STRNICMP(name, history_names[i], len) == 0) | |
6049 return i; | |
6050 | |
6051 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6052 return hist_char2type(name[0]); | |
6053 | |
6054 return -1; | |
6055 } | |
6056 | |
6057 static int last_maptick = -1; /* last seen maptick */ | |
6058 | |
6059 /* | |
6060 * Add the given string to the given history. If the string is already in the | |
6061 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6062 * values. | |
6063 */ | |
6064 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6065 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6066 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6067 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6068 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
|
6069 int sep) /* separator character used (search hist) */ |
7 | 6070 { |
6071 histentry_T *hisptr; | |
6072 int len; | |
6073 | |
6074 if (hislen == 0) /* no history */ | |
6075 return; | |
6076 | |
5467 | 6077 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6078 return; | |
6079 | |
7 | 6080 /* |
6081 * Searches inside the same mapping overwrite each other, so that only | |
6082 * the last line is kept. Be careful not to remove a line that was moved | |
6083 * down, only lines that were added. | |
6084 */ | |
6085 if (histype == HIST_SEARCH && in_map) | |
6086 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6087 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6088 { |
6089 /* Current line is from the same mapping, remove it */ | |
6090 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6091 vim_free(hisptr->hisstr); | |
4258 | 6092 clear_hist_entry(hisptr); |
7 | 6093 --hisnum[histype]; |
6094 if (--hisidx[HIST_SEARCH] < 0) | |
6095 hisidx[HIST_SEARCH] = hislen - 1; | |
6096 } | |
6097 last_maptick = -1; | |
6098 } | |
4285 | 6099 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6100 { |
6101 if (++hisidx[histype] == hislen) | |
6102 hisidx[histype] = 0; | |
6103 hisptr = &history[histype][hisidx[histype]]; | |
6104 vim_free(hisptr->hisstr); | |
6105 | |
6106 /* Store the separator after the NUL of the string. */ | |
835 | 6107 len = (int)STRLEN(new_entry); |
7 | 6108 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6109 if (hisptr->hisstr != NULL) | |
6110 hisptr->hisstr[len + 1] = sep; | |
6111 | |
6112 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6113 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6114 hisptr->time_set = vim_time(); |
7 | 6115 if (histype == HIST_SEARCH && in_map) |
6116 last_maptick = maptick; | |
6117 } | |
6118 } | |
6119 | |
6120 #if defined(FEAT_EVAL) || defined(PROTO) | |
6121 | |
6122 /* | |
6123 * Get identifier of newest history entry. | |
6124 * "histype" may be one of the HIST_ values. | |
6125 */ | |
6126 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6127 get_history_idx(int histype) |
7 | 6128 { |
6129 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6130 || hisidx[histype] < 0) | |
6131 return -1; | |
6132 | |
6133 return history[histype][hisidx[histype]].hisnum; | |
6134 } | |
6135 | |
531 | 6136 /* |
7 | 6137 * Calculate history index from a number: |
6138 * num > 0: seen as identifying number of a history entry | |
6139 * num < 0: relative position in history wrt newest entry | |
6140 * "histype" may be one of the HIST_ values. | |
6141 */ | |
6142 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6143 calc_hist_idx(int histype, int num) |
7 | 6144 { |
6145 int i; | |
6146 histentry_T *hist; | |
6147 int wrapped = FALSE; | |
6148 | |
6149 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6150 || (i = hisidx[histype]) < 0 || num == 0) | |
6151 return -1; | |
6152 | |
6153 hist = history[histype]; | |
6154 if (num > 0) | |
6155 { | |
6156 while (hist[i].hisnum > num) | |
6157 if (--i < 0) | |
6158 { | |
6159 if (wrapped) | |
6160 break; | |
6161 i += hislen; | |
6162 wrapped = TRUE; | |
6163 } | |
6164 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6165 return i; | |
6166 } | |
6167 else if (-num <= hislen) | |
6168 { | |
6169 i += num + 1; | |
6170 if (i < 0) | |
6171 i += hislen; | |
6172 if (hist[i].hisstr != NULL) | |
6173 return i; | |
6174 } | |
6175 return -1; | |
6176 } | |
6177 | |
6178 /* | |
6179 * Get a history entry by its index. | |
6180 * "histype" may be one of the HIST_ values. | |
6181 */ | |
6182 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6183 get_history_entry(int histype, int idx) |
7 | 6184 { |
6185 idx = calc_hist_idx(histype, idx); | |
6186 if (idx >= 0) | |
6187 return history[histype][idx].hisstr; | |
6188 else | |
6189 return (char_u *)""; | |
6190 } | |
6191 | |
6192 /* | |
6193 * Clear all entries of a history. | |
6194 * "histype" may be one of the HIST_ values. | |
6195 */ | |
6196 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6197 clr_history(int histype) |
7 | 6198 { |
6199 int i; | |
6200 histentry_T *hisptr; | |
6201 | |
6202 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6203 { | |
6204 hisptr = history[histype]; | |
6205 for (i = hislen; i--;) | |
6206 { | |
6207 vim_free(hisptr->hisstr); | |
4258 | 6208 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6209 hisptr++; |
7 | 6210 } |
6211 hisidx[histype] = -1; /* mark history as cleared */ | |
6212 hisnum[histype] = 0; /* reset identifier counter */ | |
6213 return OK; | |
6214 } | |
6215 return FAIL; | |
6216 } | |
6217 | |
6218 /* | |
6219 * Remove all entries matching {str} from a history. | |
6220 * "histype" may be one of the HIST_ values. | |
6221 */ | |
6222 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6223 del_history_entry(int histype, char_u *str) |
7 | 6224 { |
6225 regmatch_T regmatch; | |
6226 histentry_T *hisptr; | |
6227 int idx; | |
6228 int i; | |
6229 int last; | |
6230 int found = FALSE; | |
6231 | |
6232 regmatch.regprog = NULL; | |
6233 regmatch.rm_ic = FALSE; /* always match case */ | |
6234 if (hislen != 0 | |
6235 && histype >= 0 | |
6236 && histype < HIST_COUNT | |
6237 && *str != NUL | |
6238 && (idx = hisidx[histype]) >= 0 | |
6239 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6240 != NULL) | |
6241 { | |
6242 i = last = idx; | |
6243 do | |
6244 { | |
6245 hisptr = &history[histype][i]; | |
6246 if (hisptr->hisstr == NULL) | |
6247 break; | |
6248 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6249 { | |
6250 found = TRUE; | |
6251 vim_free(hisptr->hisstr); | |
4258 | 6252 clear_hist_entry(hisptr); |
7 | 6253 } |
6254 else | |
6255 { | |
6256 if (i != last) | |
6257 { | |
6258 history[histype][last] = *hisptr; | |
4258 | 6259 clear_hist_entry(hisptr); |
7 | 6260 } |
6261 if (--last < 0) | |
6262 last += hislen; | |
6263 } | |
6264 if (--i < 0) | |
6265 i += hislen; | |
6266 } while (i != idx); | |
6267 if (history[histype][idx].hisstr == NULL) | |
6268 hisidx[histype] = -1; | |
6269 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6270 vim_regfree(regmatch.regprog); |
7 | 6271 return found; |
6272 } | |
6273 | |
6274 /* | |
6275 * Remove an indexed entry from a history. | |
6276 * "histype" may be one of the HIST_ values. | |
6277 */ | |
6278 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6279 del_history_idx(int histype, int idx) |
7 | 6280 { |
6281 int i, j; | |
6282 | |
6283 i = calc_hist_idx(histype, idx); | |
6284 if (i < 0) | |
6285 return FALSE; | |
6286 idx = hisidx[histype]; | |
6287 vim_free(history[histype][i].hisstr); | |
6288 | |
6289 /* When deleting the last added search string in a mapping, reset | |
6290 * last_maptick, so that the last added search string isn't deleted again. | |
6291 */ | |
6292 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6293 last_maptick = -1; | |
6294 | |
6295 while (i != idx) | |
6296 { | |
6297 j = (i + 1) % hislen; | |
6298 history[histype][i] = history[histype][j]; | |
6299 i = j; | |
6300 } | |
4258 | 6301 clear_hist_entry(&history[histype][i]); |
7 | 6302 if (--i < 0) |
6303 i += hislen; | |
6304 hisidx[histype] = i; | |
6305 return TRUE; | |
6306 } | |
6307 | |
6308 #endif /* FEAT_EVAL */ | |
6309 | |
6310 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6311 /* | |
6312 * Very specific function to remove the value in ":set key=val" from the | |
6313 * history. | |
6314 */ | |
6315 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6316 remove_key_from_history(void) |
7 | 6317 { |
6318 char_u *p; | |
6319 int i; | |
6320 | |
6321 i = hisidx[HIST_CMD]; | |
6322 if (i < 0) | |
6323 return; | |
6324 p = history[HIST_CMD][i].hisstr; | |
6325 if (p != NULL) | |
6326 for ( ; *p; ++p) | |
6327 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6328 { | |
6329 p = vim_strchr(p + 3, '='); | |
6330 if (p == NULL) | |
6331 break; | |
6332 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6333 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6334 if (p[i] == '\\' && p[i + 1]) |
6335 ++i; | |
1621 | 6336 STRMOVE(p, p + i); |
7 | 6337 --p; |
6338 } | |
6339 } | |
6340 #endif | |
6341 | |
6342 #endif /* FEAT_CMDHIST */ | |
6343 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6344 #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
|
6345 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6346 * 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
|
6347 * 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
|
6348 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6349 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6350 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6351 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6352 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6353 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6354 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6355 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6356 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
|
6357 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6358 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6359 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6360 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6361 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6362 #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
|
6363 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6364 * 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
|
6365 * 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
|
6366 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6367 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6368 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6369 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6370 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6371 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
|
6372 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6373 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6374 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6375 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
|
6376 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6377 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6378 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6379 * 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
|
6380 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6381 * 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
|
6382 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6383 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6384 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6385 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6386 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6387 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
|
6388 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6389 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6390 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6391 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6392 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6393 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6394 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6395 * 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
|
6396 * 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
|
6397 * 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
|
6398 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6399 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6400 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6401 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6402 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6403 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
|
6404 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6405 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6406 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6407 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6408 /* 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
|
6409 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6410 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6411 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6412 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6413 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6414 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6415 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6416 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6417 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6418 #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
|
6419 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6420 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6421 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6422 * 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
|
6423 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6424 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6425 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6426 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6427 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6428 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
|
6429 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6430 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6431 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6432 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6433 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6434 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6435 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6436 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6437 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6438 return p->cmdfirstc; |
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 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6441 |
7 | 6442 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6443 /* | |
6444 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6445 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6446 * Returns OK if parsed successfully, otherwise FAIL. | |
6447 */ | |
6448 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6449 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6450 { |
6451 int len; | |
6452 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6453 varnumber_T num; |
7 | 6454 |
6455 *str = skipwhite(*str); | |
6456 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6457 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6458 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6459 *str += len; |
6460 *num1 = (int)num; | |
6461 first = TRUE; | |
6462 } | |
6463 *str = skipwhite(*str); | |
6464 if (**str == ',') /* parse "to" part of range */ | |
6465 { | |
6466 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6467 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6468 if (len > 0) |
6469 { | |
6470 *num2 = (int)num; | |
6471 *str = skipwhite(*str + len); | |
6472 } | |
6473 else if (!first) /* no number given at all */ | |
6474 return FAIL; | |
6475 } | |
6476 else if (first) /* only one number given */ | |
6477 *num2 = *num1; | |
6478 return OK; | |
6479 } | |
6480 #endif | |
6481 | |
6482 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6483 /* | |
6484 * :history command - print a history | |
6485 */ | |
6486 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6487 ex_history(exarg_T *eap) |
7 | 6488 { |
6489 histentry_T *hist; | |
6490 int histype1 = HIST_CMD; | |
6491 int histype2 = HIST_CMD; | |
6492 int hisidx1 = 1; | |
6493 int hisidx2 = -1; | |
6494 int idx; | |
6495 int i, j, k; | |
6496 char_u *end; | |
6497 char_u *arg = eap->arg; | |
6498 | |
6499 if (hislen == 0) | |
6500 { | |
6501 MSG(_("'history' option is zero")); | |
6502 return; | |
6503 } | |
6504 | |
6505 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6506 { | |
6507 end = arg; | |
6508 while (ASCII_ISALPHA(*end) | |
6509 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6510 end++; | |
6511 i = *end; | |
6512 *end = NUL; | |
6513 histype1 = get_histtype(arg); | |
6514 if (histype1 == -1) | |
6515 { | |
1853 | 6516 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6517 { |
6518 histype1 = 0; | |
6519 histype2 = HIST_COUNT-1; | |
6520 } | |
6521 else | |
6522 { | |
6523 *end = i; | |
6524 EMSG(_(e_trailing)); | |
6525 return; | |
6526 } | |
6527 } | |
6528 else | |
6529 histype2 = histype1; | |
6530 *end = i; | |
6531 } | |
6532 else | |
6533 end = arg; | |
6534 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6535 { | |
6536 EMSG(_(e_trailing)); | |
6537 return; | |
6538 } | |
6539 | |
6540 for (; !got_int && histype1 <= histype2; ++histype1) | |
6541 { | |
6542 STRCPY(IObuff, "\n # "); | |
6543 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6544 MSG_PUTS_TITLE(IObuff); | |
6545 idx = hisidx[histype1]; | |
6546 hist = history[histype1]; | |
6547 j = hisidx1; | |
6548 k = hisidx2; | |
6549 if (j < 0) | |
6550 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6551 if (k < 0) | |
6552 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6553 if (idx >= 0 && j <= k) | |
6554 for (i = idx + 1; !got_int; ++i) | |
6555 { | |
6556 if (i == hislen) | |
6557 i = 0; | |
6558 if (hist[i].hisstr != NULL | |
6559 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6560 { | |
6561 msg_putchar('\n'); | |
6562 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6563 hist[i].hisnum); | |
6564 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6565 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6566 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6567 else |
6568 STRCAT(IObuff, hist[i].hisstr); | |
6569 msg_outtrans(IObuff); | |
6570 out_flush(); | |
6571 } | |
6572 if (i == idx) | |
6573 break; | |
6574 } | |
6575 } | |
6576 } | |
6577 #endif | |
6578 | |
6579 #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
|
6580 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6581 * 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
|
6582 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6583 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
|
6584 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6585 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
|
6586 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6587 static int viminfo_add_at_front = FALSE; |
6588 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6589 static int hist_type2char(int type, int use_question); |
7 | 6590 |
6591 /* | |
6592 * Translate a history type number to the associated character. | |
6593 */ | |
6594 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6595 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6596 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6597 int use_question) /* use '?' instead of '/' */ |
7 | 6598 { |
6599 if (type == HIST_CMD) | |
6600 return ':'; | |
6601 if (type == HIST_SEARCH) | |
6602 { | |
6603 if (use_question) | |
6604 return '?'; | |
6605 else | |
6606 return '/'; | |
6607 } | |
6608 if (type == HIST_EXPR) | |
6609 return '='; | |
6610 return '@'; | |
6611 } | |
6612 | |
6613 /* | |
6614 * Prepare for reading the history from the viminfo file. | |
6615 * This allocates history arrays to store the read history lines. | |
6616 */ | |
6617 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6618 prepare_viminfo_history(int asklen, int writing) |
7 | 6619 { |
6620 int i; | |
6621 int num; | |
6622 int type; | |
6623 int len; | |
6624 | |
6625 init_history(); | |
4285 | 6626 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6627 if (asklen > hislen) |
6628 asklen = hislen; | |
6629 | |
6630 for (type = 0; type < HIST_COUNT; ++type) | |
6631 { | |
4258 | 6632 /* Count the number of empty spaces in the history list. Entries read |
6633 * from viminfo previously are also considered empty. If there are | |
6634 * more spaces available than we request, then fill them up. */ | |
7 | 6635 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6636 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6637 num++; |
6638 len = asklen; | |
6639 if (num > len) | |
6640 len = num; | |
6641 if (len <= 0) | |
6642 viminfo_history[type] = NULL; | |
6643 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6644 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6645 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6646 if (viminfo_history[type] == NULL) |
6647 len = 0; | |
6648 viminfo_hislen[type] = len; | |
6649 viminfo_hisidx[type] = 0; | |
6650 } | |
6651 } | |
6652 | |
6653 /* | |
6654 * Accept a line from the viminfo, store it in the history array when it's | |
6655 * new. | |
6656 */ | |
6657 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6658 read_viminfo_history(vir_T *virp, int writing) |
7 | 6659 { |
6660 int type; | |
6661 long_u len; | |
6662 char_u *val; | |
6663 char_u *p; | |
6664 | |
6665 type = hist_char2type(virp->vir_line[0]); | |
6666 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6667 { | |
6668 val = viminfo_readstring(virp, 1, TRUE); | |
6669 if (val != NULL && *val != NUL) | |
6670 { | |
3316 | 6671 int sep = (*val == ' ' ? NUL : *val); |
6672 | |
7 | 6673 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6674 viminfo_add_at_front, sep, writing)) |
7 | 6675 { |
6676 /* Need to re-allocate to append the separator byte. */ | |
6677 len = STRLEN(val); | |
6678 p = lalloc(len + 2, TRUE); | |
6679 if (p != NULL) | |
6680 { | |
6681 if (type == HIST_SEARCH) | |
6682 { | |
6683 /* Search entry: Move the separator from the first | |
6684 * column to after the NUL. */ | |
6685 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6686 p[len] = sep; |
7 | 6687 } |
6688 else | |
6689 { | |
6690 /* Not a search entry: No separator in the viminfo | |
6691 * file, add a NUL separator. */ | |
6692 mch_memmove(p, val, (size_t)len + 1); | |
6693 p[len + 1] = NUL; | |
6694 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6695 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
|
6696 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
|
6697 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
|
6698 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
|
6699 viminfo_hisidx[type]++; |
7 | 6700 } |
6701 } | |
6702 } | |
6703 vim_free(val); | |
6704 } | |
6705 return viminfo_readline(virp); | |
6706 } | |
6707 | |
4285 | 6708 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6709 * 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
|
6710 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6711 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6712 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6713 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6714 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6715 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6716 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6717 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6718 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6719 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6720 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6721 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
|
6722 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6723 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6724 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6725 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6726 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6727 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6728 || (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
|
6729 || 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
|
6730 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6731 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6732 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6733 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6734 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6735 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
|
6736 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6737 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6738 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6739 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6740 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
|
6741 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6742 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6743 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6744 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6745 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
|
6746 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6747 /* 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
|
6748 * 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
|
6749 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
|
6750 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6751 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6752 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6753 && (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
|
6754 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6755 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6756 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6757 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6758 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6759 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6760 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6761 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6762 /* 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
|
6763 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6764 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6765 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6766 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6767 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6768 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6769 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6770 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
|
6771 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6772 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6773 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
|
6774 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6775 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6776 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
|
6777 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6778 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
|
6779 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6780 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6781 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6782 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6783 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6784 } |
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 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6787 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6788 * 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
|
6789 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6790 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6791 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6792 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6793 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6794 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6795 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6796 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6797 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6798 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6799 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6800 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6801 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6802 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6803 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6804 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6805 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6806 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6807 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6808 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6809 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6810 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6811 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6812 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6813 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6814 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6815 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6816 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6817 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6818 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
|
6819 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6820 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6821 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
|
6822 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6823 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
|
6824 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6825 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6826 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6827 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6828 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6829 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
|
6830 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6831 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6832 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6833 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6834 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6835 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6836 #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
|
6837 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6838 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6839 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6840 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6841 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
|
6842 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6843 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6844 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6845 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6846 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
|
6847 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
|
6848 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6849 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6850 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6851 |
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 * 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
|
6854 * timestamp; |
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 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6857 merge_history(int type) |
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 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6860 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6861 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6862 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6863 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6864 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6865 /* 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
|
6866 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6867 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
|
6868 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
|
6869 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
|
6870 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6871 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6872 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6873 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6874 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6875 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
|
6876 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
|
6877 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6878 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6879 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6880 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6881 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6882 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6883 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
|
6884 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6885 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6886 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6887 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6888 if (i < len) |
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 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6891 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6892 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6893 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6894 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6895 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6896 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6897 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6898 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
|
6899 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6900 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6901 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
|
6902 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
|
6903 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6904 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
6907 vim_free(tot_hist); |
9256
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 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 /* |
4285 | 6911 * Finish reading history lines from viminfo. Not used when writing viminfo. |
6912 */ | |
7 | 6913 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6914 finish_viminfo_history(vir_T *virp) |
7 | 6915 { |
6916 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 6918 |
6919 for (type = 0; type < HIST_COUNT; ++type) | |
6920 { | |
6921 if (history[type] == NULL) | |
4283 | 6922 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6923 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 merge_history(type); |
7 | 6926 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
6929 VIM_CLEAR(viminfo_history[type]); |
4327 | 6930 viminfo_hisidx[type] = 0; |
7 | 6931 } |
6932 } | |
6933 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6934 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6935 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6936 * 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
|
6937 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6938 * 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
|
6939 */ |
7 | 6940 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6941 write_viminfo_history(FILE *fp, int merge) |
7 | 6942 { |
6943 int i; | |
6944 int type; | |
6945 int num_saved; | |
4283 | 6946 int round; |
7 | 6947 |
6948 init_history(); | |
6949 if (hislen == 0) | |
6950 return; | |
6951 for (type = 0; type < HIST_COUNT; ++type) | |
6952 { | |
6953 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
6954 if (num_saved == 0) | |
6955 continue; | |
6956 if (num_saved < 0) /* Use default */ | |
6957 num_saved = hislen; | |
6958 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
6959 type == HIST_CMD ? _("Command Line") : | |
6960 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6961 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6962 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6963 _("Debug Line")); |
7 | 6964 if (num_saved > hislen) |
6965 num_saved = hislen; | |
4283 | 6966 |
6967 /* | |
6968 * Merge typed and viminfo history: | |
6969 * round 1: history of typed commands. | |
6970 * round 2: history from recently read viminfo. | |
6971 */ | |
6972 for (round = 1; round <= 2; ++round) | |
6973 { | |
4307 | 6974 if (round == 1) |
6975 /* start at newest entry, somewhere in the list */ | |
6976 i = hisidx[type]; | |
6977 else if (viminfo_hisidx[type] > 0) | |
6978 /* start at newest entry, first in the list */ | |
6979 i = 0; | |
6980 else | |
6981 /* empty list */ | |
6982 i = -1; | |
4283 | 6983 if (i >= 0) |
6984 while (num_saved > 0 | |
6985 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 6986 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6987 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6988 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6989 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6990 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6991 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6992 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6993 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6994 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6995 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6996 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6997 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6998 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6999 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7000 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7001 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7002 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7003 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7004 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7005 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7006 || !history[type][i].viminfo)) |
7 | 7007 { |
4283 | 7008 --num_saved; |
7009 fputc(hist_type2char(type, TRUE), fp); | |
7010 /* For the search history: put the separator in the | |
7011 * second column; use a space if there isn't one. */ | |
7012 if (type == HIST_SEARCH) | |
7013 { | |
7014 c = p[STRLEN(p) + 1]; | |
7015 putc(c == NUL ? ' ' : c, fp); | |
7016 } | |
7017 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7018 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7019 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7020 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7021 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7022 /* 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
|
7023 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7024 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7025 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7026 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7027 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7028 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
|
7029 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7030 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7031 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7032 } |
7 | 7033 } |
4283 | 7034 if (round == 1) |
7035 { | |
7036 /* Decrement index, loop around and stop when back at | |
7037 * the start. */ | |
7038 if (--i < 0) | |
7039 i = hislen - 1; | |
7040 if (i == hisidx[type]) | |
7041 break; | |
7042 } | |
7043 else | |
7044 { | |
7045 /* Increment index. Stop at the end in the while. */ | |
7046 ++i; | |
7047 } | |
7 | 7048 } |
4283 | 7049 } |
4285 | 7050 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7051 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7052 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
|
7053 VIM_CLEAR(viminfo_history[type]); |
4311 | 7054 viminfo_hisidx[type] = 0; |
7 | 7055 } |
7056 } | |
7057 #endif /* FEAT_VIMINFO */ | |
7058 | |
7059 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7060 /* | |
7061 * Write a character at the current cursor+offset position. | |
7062 * It is directly written into the command buffer block. | |
7063 */ | |
7064 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7065 cmd_pchar(int c, int offset) |
7 | 7066 { |
7067 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7068 { | |
7069 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7070 return; | |
7071 } | |
7072 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7073 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7074 } | |
7075 | |
7076 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7077 cmd_gchar(int offset) |
7 | 7078 { |
7079 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7080 { | |
7081 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7082 return NUL; | |
7083 } | |
7084 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7085 } | |
7086 #endif | |
7087 | |
7088 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7089 /* | |
7090 * Open a window on the current command line and history. Allow editing in | |
7091 * the window. Returns when the window is closed. | |
7092 * Returns: | |
7093 * CR if the command is to be executed | |
7094 * Ctrl_C if it is to be abandoned | |
7095 * K_IGNORE if editing continues | |
7096 */ | |
7097 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
|
7098 open_cmdwin(void) |
7 | 7099 { |
7100 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7101 bufref_T old_curbuf; |
7 | 7102 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7103 bufref_T bufref; |
7 | 7104 win_T *wp; |
7105 int i; | |
7106 linenr_T lnum; | |
7107 int histtype; | |
7108 garray_T winsizes; | |
7109 int save_restart_edit = restart_edit; | |
7110 int save_State = State; | |
7111 int save_exmode = exmode_active; | |
510 | 7112 #ifdef FEAT_RIGHTLEFT |
7113 int save_cmdmsg_rl = cmdmsg_rl; | |
7114 #endif | |
6145 | 7115 #ifdef FEAT_FOLDING |
7116 int save_KeyTyped; | |
7117 #endif | |
7 | 7118 |
7119 /* Can't do this recursively. Can't do it when typing a password. */ | |
7120 if (cmdwin_type != 0 | |
7121 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7122 || cmdline_star > 0 | |
7123 # endif | |
7124 ) | |
7125 { | |
7126 beep_flush(); | |
7127 return K_IGNORE; | |
7128 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7129 set_bufref(&old_curbuf, curbuf); |
7 | 7130 |
7131 /* Save current window sizes. */ | |
7132 win_size_save(&winsizes); | |
7133 | |
7134 /* Don't execute autocommands while creating the window. */ | |
1410 | 7135 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7136 |
683 | 7137 /* don't use a new tab page */ |
7138 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
|
7139 cmdmod.noswapfile = 1; |
683 | 7140 |
7 | 7141 /* Create a window for the command-line buffer. */ |
7142 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7143 { | |
7144 beep_flush(); | |
1410 | 7145 unblock_autocmds(); |
7 | 7146 return K_IGNORE; |
7147 } | |
1831 | 7148 cmdwin_type = get_cmdline_type(); |
7 | 7149 |
7150 /* Create the command-line buffer empty. */ | |
1743 | 7151 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7152 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7153 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7154 curbuf->b_p_ma = TRUE; | |
1865 | 7155 #ifdef FEAT_FOLDING |
7156 curwin->w_p_fen = FALSE; | |
7157 #endif | |
7 | 7158 # ifdef FEAT_RIGHTLEFT |
510 | 7159 curwin->w_p_rl = cmdmsg_rl; |
7160 cmdmsg_rl = FALSE; | |
7 | 7161 # endif |
2583 | 7162 RESET_BINDING(curwin); |
7 | 7163 |
7164 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7165 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7166 /* 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
|
7167 ++curbuf_lock; |
7 | 7168 |
510 | 7169 /* Showing the prompt may have set need_wait_return, reset it. */ |
7170 need_wait_return = FALSE; | |
7171 | |
1831 | 7172 histtype = hist_char2type(cmdwin_type); |
7 | 7173 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7174 { | |
7175 if (p_wc == TAB) | |
7176 { | |
7177 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7178 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7179 } | |
7180 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7181 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7182 --curbuf_lock; |
7 | 7183 |
10 | 7184 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7185 * sets 'textwidth' to 78). */ | |
7186 curbuf->b_p_tw = 0; | |
7187 | |
7 | 7188 /* Fill the buffer with the history. */ |
7189 init_history(); | |
7190 if (hislen > 0) | |
7191 { | |
7192 i = hisidx[histtype]; | |
7193 if (i >= 0) | |
7194 { | |
7195 lnum = 0; | |
7196 do | |
7197 { | |
7198 if (++i == hislen) | |
7199 i = 0; | |
7200 if (history[histtype][i].hisstr != NULL) | |
7201 ml_append(lnum++, history[histtype][i].hisstr, | |
7202 (colnr_T)0, FALSE); | |
7203 } | |
7204 while (i != hisidx[histtype]); | |
7205 } | |
7206 } | |
7207 | |
7208 /* Replace the empty last line with the current command-line and put the | |
7209 * cursor there. */ | |
7210 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7211 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7212 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7213 changed_line_abv_curs(); |
7214 invalidate_botline(); | |
743 | 7215 redraw_later(SOME_VALID); |
7 | 7216 |
7217 /* 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
|
7218 save_cmdline(&save_ccline); |
7 | 7219 |
7220 /* No Ex mode here! */ | |
7221 exmode_active = 0; | |
7222 | |
7223 State = NORMAL; | |
7224 # ifdef FEAT_MOUSE | |
7225 setmouse(); | |
7226 # endif | |
7227 | |
7228 /* 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
|
7229 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7230 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7231 stuffcharReadbuff(K_NOP); | |
7 | 7232 |
7233 i = RedrawingDisabled; | |
7234 RedrawingDisabled = 0; | |
7235 | |
7236 /* | |
7237 * Call the main loop until <CR> or CTRL-C is typed. | |
7238 */ | |
7239 cmdwin_result = 0; | |
168 | 7240 main_loop(TRUE, FALSE); |
7 | 7241 |
7242 RedrawingDisabled = i; | |
7243 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7244 # ifdef FEAT_FOLDING |
6145 | 7245 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7246 # endif |
6145 | 7247 |
7 | 7248 /* 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
|
7249 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7250 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7251 # ifdef FEAT_FOLDING |
6145 | 7252 /* Restore KeyTyped in case it is modified by autocommands */ |
7253 KeyTyped = save_KeyTyped; | |
7 | 7254 # endif |
7255 | |
1214 | 7256 /* 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
|
7257 restore_cmdline(&save_ccline); |
7 | 7258 cmdwin_type = 0; |
7259 | |
7260 exmode_active = save_exmode; | |
7261 | |
1612 | 7262 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7263 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7264 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7265 { |
7266 cmdwin_result = Ctrl_C; | |
7267 EMSG(_("E199: Active window or buffer deleted")); | |
7268 } | |
7269 else | |
7270 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7271 # if defined(FEAT_EVAL) |
7 | 7272 /* autocmds may abort script processing */ |
7273 if (aborting() && cmdwin_result != K_IGNORE) | |
7274 cmdwin_result = Ctrl_C; | |
7275 # endif | |
7276 /* Set the new command line from the cmdline buffer. */ | |
7277 vim_free(ccline.cmdbuff); | |
510 | 7278 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7279 { |
510 | 7280 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7281 | |
7282 if (histtype == HIST_CMD) | |
7283 { | |
7284 /* Execute the command directly. */ | |
7285 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7286 cmdwin_result = CAR; | |
7287 } | |
7288 else | |
7289 { | |
7290 /* First need to cancel what we were doing. */ | |
7291 ccline.cmdbuff = NULL; | |
7292 stuffcharReadbuff(':'); | |
7293 stuffReadbuff((char_u *)p); | |
7294 stuffcharReadbuff(CAR); | |
7295 } | |
7 | 7296 } |
7297 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7298 { | |
7299 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7300 cmdwin_result = CAR; | |
7301 } | |
2839 | 7302 else if (cmdwin_result == Ctrl_C) |
7303 { | |
7304 /* :q or :close, don't execute any command | |
7305 * and don't modify the cmd window. */ | |
7306 ccline.cmdbuff = NULL; | |
7307 } | |
7 | 7308 else |
7309 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7310 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
|
7311 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7312 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
|
7313 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
|
7314 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
|
7315 ccline.cmdpos = 0; |
7 | 7316 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
|
7317 } |
7 | 7318 else |
7319 { | |
7320 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7321 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7322 ccline.cmdpos = curwin->w_cursor.col; | |
7323 if (ccline.cmdpos > ccline.cmdlen) | |
7324 ccline.cmdpos = ccline.cmdlen; | |
7325 if (cmdwin_result == K_IGNORE) | |
7326 { | |
7327 set_cmdspos_cursor(); | |
7328 redrawcmd(); | |
7329 } | |
7330 } | |
7331 | |
7332 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7333 block_autocmds(); |
6876 | 7334 # ifdef FEAT_CONCEAL |
7335 /* Avoid command-line window first character being concealed. */ | |
7336 curwin->w_p_cole = 0; | |
7337 # endif | |
7 | 7338 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7339 set_bufref(&bufref, curbuf); |
7 | 7340 win_goto(old_curwin); |
7341 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7342 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7343 /* 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
|
7344 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7345 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7346 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7347 |
7348 /* Restore window sizes. */ | |
7349 win_size_restore(&winsizes); | |
7350 | |
1410 | 7351 unblock_autocmds(); |
7 | 7352 } |
7353 | |
7354 ga_clear(&winsizes); | |
7355 restart_edit = save_restart_edit; | |
510 | 7356 # ifdef FEAT_RIGHTLEFT |
7357 cmdmsg_rl = save_cmdmsg_rl; | |
7358 # endif | |
7 | 7359 |
7360 State = save_State; | |
7361 # ifdef FEAT_MOUSE | |
7362 setmouse(); | |
7363 # endif | |
7364 | |
7365 return cmdwin_result; | |
7366 } | |
7367 #endif /* FEAT_CMDWIN */ | |
7368 | |
7369 /* | |
7370 * Used for commands that either take a simple command string argument, or: | |
7371 * cmd << endmarker | |
7372 * {script} | |
7373 * endmarker | |
7374 * Returns a pointer to allocated memory with {script} or NULL. | |
7375 */ | |
7376 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7377 script_get(exarg_T *eap, char_u *cmd) |
7 | 7378 { |
7379 char_u *theline; | |
7380 char *end_pattern = NULL; | |
7381 char dot[] = "."; | |
7382 garray_T ga; | |
7383 | |
7384 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7385 return NULL; | |
7386 | |
7387 ga_init2(&ga, 1, 0x400); | |
7388 | |
7389 if (cmd[2] != NUL) | |
7390 end_pattern = (char *)skipwhite(cmd + 2); | |
7391 else | |
7392 end_pattern = dot; | |
7393 | |
7394 for (;;) | |
7395 { | |
7396 theline = eap->getline( | |
7397 #ifdef FEAT_EVAL | |
75 | 7398 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7399 #endif |
7400 NUL, eap->cookie, 0); | |
7401 | |
7402 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7403 { |
7404 vim_free(theline); | |
7 | 7405 break; |
1694 | 7406 } |
7 | 7407 |
7408 ga_concat(&ga, theline); | |
7409 ga_append(&ga, '\n'); | |
7410 vim_free(theline); | |
7411 } | |
21 | 7412 ga_append(&ga, NUL); |
7 | 7413 |
7414 return (char_u *)ga.ga_data; | |
7415 } |