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