Mercurial > vim
annotate src/ex_getln.c @ 14534:8fa7f5ff2649 v8.1.0280
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
commit https://github.com/vim/vim/commit/def7b1dc6104a6ce6d7c3e3a615231178601b124
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Aug 13 22:54:35 2018 +0200
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Problem: 'incsearch' highlighting does not work for ":g!/".
Solution: Skip the exclamation mark. (Hirohito Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 13 Aug 2018 23:00:05 +0200 |
parents | 58cc47fae12e |
children | 213f1a519378 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 /* | |
17 * Variables shared between getcmdline(), redrawcmdline() and others. | |
18 * These need to be saved when using CTRL-R |, that's why they are in a | |
19 * structure. | |
20 */ | |
21 struct cmdline_info | |
22 { | |
23 char_u *cmdbuff; /* pointer to command line buffer */ | |
24 int cmdbufflen; /* length of cmdbuff */ | |
25 int cmdlen; /* number of chars in command line */ | |
26 int cmdpos; /* current cursor position */ | |
27 int cmdspos; /* cursor column on screen */ | |
3503 | 28 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 29 int cmdindent; /* number of spaces before cmdline */ |
30 char_u *cmdprompt; /* message in front of cmdline */ | |
31 int cmdattr; /* attributes for prompt */ | |
32 int overstrike; /* Typing mode on the command line. Shared by | |
33 getcmdline() and put_on_cmdline(). */ | |
1718 | 34 expand_T *xpc; /* struct being used for expansion, xp_pattern |
35 may point into cmdbuff */ | |
531 | 36 int xp_context; /* type of expansion */ |
37 # ifdef FEAT_EVAL | |
38 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 39 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 40 # endif |
7 | 41 }; |
42 | |
1718 | 43 /* The current cmdline_info. It is initialized in getcmdline() and after that |
44 * used by other functions. When invoking getcmdline() recursively it needs | |
45 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
46 * TODO: make it local to getcmdline() and pass it around. */ | |
47 static struct cmdline_info ccline; | |
7 | 48 |
49 static int cmd_showtail; /* Only show path tail in lists ? */ | |
50 | |
51 #ifdef FEAT_EVAL | |
52 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
53 #endif | |
54 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
55 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
56 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
57 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
58 |
7 | 59 #ifdef FEAT_CMDHIST |
60 typedef struct hist_entry | |
61 { | |
62 int hisnum; /* identifying number */ | |
4258 | 63 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 64 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
65 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 66 } histentry_T; |
67 | |
68 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
69 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
70 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
71 /* identifying (unique) number of newest history entry */ | |
72 static int hislen = 0; /* actual length of history tables */ | |
73 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
74 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
75 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
76 static int in_history(int, char_u *, int, int, int); |
7 | 77 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int calc_hist_idx(int histype, int num); |
7 | 79 # endif |
80 #endif | |
81 | |
82 #ifdef FEAT_RIGHTLEFT | |
83 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
84 #endif | |
85 | |
86 #ifdef FEAT_FKMAP | |
87 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
88 #endif | |
89 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
90 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
91 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
92 static void set_cmdspos_cursor(void); |
7 | 93 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
97 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void draw_cmdline(int start, int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 static void save_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void restore_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 102 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 static void redrawcmd_preedit(void); |
7 | 104 #endif |
105 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
106 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
108 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
109 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 static int nextwild(expand_T *xp, int type, int options, int escape); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void escape_fname(char_u **pp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static int showmatches(expand_T *xp, int wildmenu); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static void set_expand_context(expand_T *xp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
116 static int expand_showtail(expand_T *xp); |
7 | 117 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
119 static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
120 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 121 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 123 # endif |
7 | 124 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
125 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 127 # endif |
128 #endif | |
4265 | 129 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 131 #endif |
7 | 132 |
133 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
134 static int open_cmdwin(void); |
7 | 135 #endif |
136 | |
3164 | 137 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
138 static int | |
139 #ifdef __BORLANDC__ | |
140 _RTLENTRYF | |
141 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
142 sort_func_compare(const void *s1, const void *s2); |
3164 | 143 #endif |
144 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
145 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
146 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
147 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
148 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
150 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
153 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
155 |
7 | 156 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
157 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
158 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
159 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
160 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
162 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
166 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
169 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
171 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
172 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
173 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
174 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
177 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
181 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
185 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
186 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
187 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
188 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
189 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
190 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
223 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
224 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
225 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
226 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 int incsearch_postponed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
238 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 is_state->incsearch_postponed = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
247 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
267 * Sets search_first_line and search_last_line to the address range. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
270 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
271 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
274 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
275 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
276 if (p_is && !cmd_silent) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
278 // by default search all lines |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
279 search_first_line = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
280 search_last_line = MAXLNUM; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
281 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
282 if (firstc == '/' || firstc == '?') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
283 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
284 if (firstc == ':') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
285 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
286 char_u *cmd = skip_range(ccline.cmdbuff, NULL); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
287 char_u *p; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
288 int delim; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
289 char_u *end; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
290 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
291 if (*cmd == 's' || *cmd == 'g' || *cmd == 'v') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
292 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
293 // Skip over "substitute" to find the pattern separator. |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
294 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
295 ; |
14532
58cc47fae12e
patch 8.1.0279: 'incsearch' highlighting does not skip white space
Christian Brabandt <cb@256bit.org>
parents:
14530
diff
changeset
|
296 if (*skipwhite(p) != NUL |
14522
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
297 && (STRNCMP(cmd, "substitute", p - cmd) == 0 |
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
298 || STRNCMP(cmd, "global", p - cmd) == 0 |
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
299 || STRNCMP(cmd, "vglobal", p - cmd) == 0)) |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
300 { |
14534
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
301 // Check for "global!/". |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
302 if (*cmd == 'g' && *p == '!') |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
303 { |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
304 p++; |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
305 if (*skipwhite(p) == NUL) |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
306 return FALSE; |
8fa7f5ff2649
patch 8.1.0280: 'incsearch' highlighting does not work for ":g!/"
Christian Brabandt <cb@256bit.org>
parents:
14532
diff
changeset
|
307 } |
14532
58cc47fae12e
patch 8.1.0279: 'incsearch' highlighting does not skip white space
Christian Brabandt <cb@256bit.org>
parents:
14530
diff
changeset
|
308 p = skipwhite(p); |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
309 delim = *p++; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
310 end = skip_regexp(p, delim, p_magic, NULL); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
311 if (end > p || *end == delim) |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
312 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
313 char_u *dummy; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
314 exarg_T ea; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
315 pos_T save_cursor = curwin->w_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
316 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
317 // found a non-empty pattern |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
318 *skiplen = (int)(p - ccline.cmdbuff); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
319 *patlen = (int)(end - p); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
320 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
321 // parse the address range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
322 vim_memset(&ea, 0, sizeof(ea)); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
323 ea.line1 = 1; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
324 ea.line2 = 1; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
325 ea.cmd = ccline.cmdbuff; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
326 ea.addr_type = ADDR_LINES; |
14524
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
327 curwin->w_cursor = is_state->search_start; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
328 parse_cmd_address(&ea, &dummy); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
329 if (ea.addr_count > 0) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
330 { |
14530
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
331 // Allow for reverse match. |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
332 if (ea.line2 < ea.line1) |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
333 { |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
334 search_first_line = ea.line2; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
335 search_last_line = ea.line1; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
336 } |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
337 else |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
338 { |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
339 search_first_line = ea.line1; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
340 search_last_line = ea.line2; |
60e0022e6e5d
patch 8.1.0278: 'incsearch' highlighting does not accept reverse range
Christian Brabandt <cb@256bit.org>
parents:
14528
diff
changeset
|
341 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
342 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
343 else if (*cmd == 's') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
344 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
345 // :s defaults to the current line |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
346 search_first_line = curwin->w_cursor.lnum; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
347 search_last_line = curwin->w_cursor.lnum; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
348 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
349 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
350 curwin->w_cursor = save_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
351 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
352 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
353 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
354 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
355 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
356 } |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
357 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
358 return FALSE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
359 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
360 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
361 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
362 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
363 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
364 incsearch_state_T *is_state, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
365 int call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
366 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
367 if (is_state->did_incsearch) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
368 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
369 is_state->did_incsearch = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
370 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
371 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
372 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
373 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
374 if (!EQUAL_POS(is_state->save_cursor, is_state->search_start)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
375 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
376 // put the '" mark at the original position |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
377 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
378 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
379 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
380 curwin->w_cursor = is_state->search_start; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
381 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
382 restore_viewstate(&is_state->old_viewstate); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
383 highlight_match = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
384 validate_cursor(); /* needed for TAB */ |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
385 if (call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
386 update_screen(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
387 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
388 redraw_all_later(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
389 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
390 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
391 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
392 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
393 * Do 'incsearch' highlighting if desired. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
394 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
395 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
396 may_do_incsearch_highlighting( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
397 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
398 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
399 incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
400 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
401 int skiplen, patlen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
402 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
403 pos_T end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
404 struct cmdline_info save_ccline; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
405 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
406 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
407 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
408 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
409 int use_last_pat; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
410 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
411 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
412 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
413 finish_incsearch_highlighting(FALSE, is_state, TRUE); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
414 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
415 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
416 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
417 // If there is a character waiting, search and redraw later. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
418 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
419 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
420 is_state->incsearch_postponed = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
421 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
422 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
423 is_state->incsearch_postponed = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
424 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
425 if (search_first_line == 0) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
426 // start at the original cursor position |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
427 curwin->w_cursor = is_state->search_start; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
428 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
429 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
430 // start at the first line in the range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
431 curwin->w_cursor.lnum = search_first_line; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
432 curwin->w_cursor.col = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
433 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
434 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
435 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
436 // Use the previous pattern for ":s//". |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
437 next_char = ccline.cmdbuff[skiplen + patlen]; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
438 use_last_pat = patlen == 0 && skiplen > 0 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
439 && ccline.cmdbuff[skiplen - 1] == next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
440 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
441 // If there is no pattern, don't do anything. |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
442 if (patlen == 0 && !use_last_pat) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
443 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
444 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
445 set_no_hlsearch(TRUE); // turn off previous highlight |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
446 redraw_all_later(SOME_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
447 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
448 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
449 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
450 int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
451 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
452 cursor_off(); // so the user knows we're busy |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
453 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
454 ++emsg_off; // so it doesn't beep if bad expr |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
456 // Set the time limit to half a second. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
457 profile_setlimit(500L, &tm); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
458 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
459 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
460 search_flags += SEARCH_KEEP; |
14524
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
461 if (search_first_line != 0) |
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
462 search_flags += SEARCH_START; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
463 ccline.cmdbuff[skiplen + patlen] = NUL; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
464 i = do_search(NULL, firstc == ':' ? '/' : firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
465 ccline.cmdbuff + skiplen, count, search_flags, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
466 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
467 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
468 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
469 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
470 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
471 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
472 ccline.cmdbuff[skiplen + patlen] = next_char; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
473 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
474 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
475 if (curwin->w_cursor.lnum < search_first_line |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
476 || curwin->w_cursor.lnum > search_last_line) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
477 // match outside of address range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
478 i = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
479 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
480 // if interrupted while searching, behave like it failed |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
481 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
482 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
483 (void)vpeekc(); // remove <C-C> from input stream |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
484 got_int = FALSE; // don't abandon the command line |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
485 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
486 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
487 else if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
488 // cancelled searching because a char was typed |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
489 is_state->incsearch_postponed = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
490 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
491 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
492 highlight_match = TRUE; // highlight position |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
493 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
494 highlight_match = FALSE; // remove highlight |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
495 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
496 // First restore the old curwin values, so the screen is positioned in the |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
497 // same way as the actual search command. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
498 restore_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
499 changed_cline_bef_curs(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
500 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
501 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
502 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
503 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
504 pos_T save_pos = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
505 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
506 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
507 set_search_match(&curwin->w_cursor); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
508 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
509 end_pos = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
510 is_state->match_end = end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
511 curwin->w_cursor = save_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
512 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
513 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
514 end_pos = curwin->w_cursor; // shutup gcc 4 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
516 // Disable 'hlsearch' highlighting if the pattern matches everything. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
517 // Avoids a flash when typing "foo\|". |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
518 if (!use_last_pat) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
519 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
520 next_char = ccline.cmdbuff[skiplen + patlen]; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
521 ccline.cmdbuff[skiplen + patlen] = NUL; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
522 if (empty_pattern(ccline.cmdbuff)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
523 set_no_hlsearch(TRUE); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
524 ccline.cmdbuff[skiplen + patlen] = next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
525 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
527 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
528 // May redraw the status line to show the cursor position. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
529 if (p_ru && curwin->w_status_height > 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
530 curwin->w_redr_status = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
531 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
532 save_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
533 update_screen(SOME_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
534 restore_cmdline(&save_ccline); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
535 restore_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
536 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
537 // Leave it at the end to make CTRL-R CTRL-W work. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
538 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
539 curwin->w_cursor = end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
540 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
541 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
542 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
543 is_state->did_incsearch = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
544 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
545 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
546 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
547 * May adjust 'incsearch' highlighting for typing CTRL-G and CTRL-T, go to next |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
549 * Returns FAIL when jumping to cmdline_not_changed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
551 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
552 may_adjust_incsearch_highlighting( |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
553 int firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
554 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
555 incsearch_state_T *is_state, |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
556 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
557 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
558 int skiplen, patlen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
559 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
560 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
561 int search_flags = SEARCH_NOOF; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
562 int i; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
563 int save; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
564 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
565 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
566 return OK; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
567 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
568 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
569 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
570 if (firstc == ccline.cmdbuff[skiplen]) |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
571 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
572 pat = last_search_pattern(); |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
573 skiplen = 0; |
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
574 patlen = STRLEN(pat); |
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
575 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
576 else |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
577 pat = ccline.cmdbuff + skiplen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
578 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
579 save_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
580 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
581 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
582 if (c == Ctrl_G) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
583 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
584 t = is_state->match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
585 if (LT_POS(is_state->match_start, is_state->match_end)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
586 // Start searching at the end of the match not at the beginning of |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
587 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
588 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
589 search_flags += SEARCH_COL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
590 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
591 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
592 t = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
593 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
594 search_flags += SEARCH_KEEP; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
595 ++emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
596 save = pat[patlen]; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
597 pat[patlen] = NUL; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
598 i = searchit(curwin, curbuf, &t, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
599 c == Ctrl_G ? FORWARD : BACKWARD, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
600 pat, count, search_flags, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
601 RE_SEARCH, 0, NULL, NULL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
602 --emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
603 pat[patlen] = save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
604 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
605 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
606 is_state->search_start = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
607 is_state->match_end = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
608 is_state->match_start = t; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
609 if (c == Ctrl_T && firstc != '?') |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
610 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
611 // Move just before the current match, so that when nv_search |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
612 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
613 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 (void)decl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 else if (c == Ctrl_G && firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
618 // Move just after the current match, so that when nv_search |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
619 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
621 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
622 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
623 if (LT_POS(t, is_state->search_start) && c == Ctrl_G) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
624 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
625 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
626 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
627 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
628 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
629 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
630 (void)decl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
631 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
632 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
633 set_search_match(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
634 curwin->w_cursor = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
635 changed_cline_bef_curs(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
636 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
637 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
638 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
639 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
640 update_screen(NOT_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
641 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
642 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
643 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
644 vim_beep(BO_ERROR); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
645 restore_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
646 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
647 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
648 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
649 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
650 * When CTRL-L typed: add character from the match to the pattern. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
651 * May set "*c" to the added character. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
652 * Return OK when jumping to cmdline_not_changed. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
653 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
654 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
655 may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
656 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
657 int skiplen, patlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
658 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
659 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
660 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
661 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
662 // Add a character from under the cursor for 'incsearch'. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
663 if (is_state->did_incsearch) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
664 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
665 curwin->w_cursor = is_state->match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
666 if (!EQUAL_POS(curwin->w_cursor, is_state->search_start)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
667 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
668 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
669 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
670 // If 'ignorecase' and 'smartcase' are set and the |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 // command line has no uppercase characters, convert |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
672 // the character to lowercase. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
673 if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
674 *c = MB_TOLOWER(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
675 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
676 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
677 if (*c == firstc || vim_strchr((char_u *)( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
678 p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
679 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
680 // put a backslash before special characters |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
681 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
682 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
683 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
684 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
685 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
686 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
687 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
688 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
689 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
690 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
691 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
692 /* |
7 | 693 * getcmdline() - accept a command line starting with firstc. |
694 * | |
695 * firstc == ':' get ":" command line. | |
696 * firstc == '/' or '?' get search pattern | |
697 * firstc == '=' get expression | |
698 * firstc == '@' get text for input() function | |
699 * firstc == '>' get text for debug mode | |
700 * firstc == NUL get text for :insert command | |
701 * firstc == -1 like NUL, and break on CTRL-C | |
702 * | |
703 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
704 * command line. | |
705 * | |
706 * Careful: getcmdline() can be called recursively! | |
707 * | |
708 * Return pointer to allocated string if there is a commandline, NULL | |
709 * otherwise. | |
710 */ | |
711 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
712 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
713 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
714 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
|
715 int indent) /* indent for inside conditionals */ |
7 | 716 { |
717 int c; | |
718 int i; | |
719 int j; | |
720 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
721 int do_abbr; /* when TRUE check for abbr. */ | |
722 #ifdef FEAT_CMDHIST | |
723 char_u *lookfor = NULL; /* string to match */ | |
724 int hiscnt; /* current history line in use */ | |
725 int histype; /* history type to be used */ | |
726 #endif | |
727 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
728 incsearch_state_T is_state; |
7 | 729 #endif |
730 int did_wild_list = FALSE; /* did wild_list() recently */ | |
731 int wim_index = 0; /* index in wim_flags[] */ | |
732 int res; | |
733 int save_msg_scroll = msg_scroll; | |
734 int save_State = State; /* remember State when called */ | |
735 int some_key_typed = FALSE; /* one of the keys was typed */ | |
736 #ifdef FEAT_MOUSE | |
737 /* mouse drag and release events are ignored, unless they are | |
738 * preceded with a mouse down event */ | |
739 int ignore_drag_release = TRUE; | |
740 #endif | |
741 #ifdef FEAT_EVAL | |
742 int break_ctrl_c = FALSE; | |
743 #endif | |
744 expand_T xpc; | |
745 long *b_im_ptr = NULL; | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
746 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 747 /* Everything that may work recursively should save and restore the |
748 * current command line in save_ccline. That includes update_screen(), a | |
749 * custom status line may invoke ":normal". */ | |
750 struct cmdline_info save_ccline; | |
751 #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
|
752 int cmdline_type; |
7 | 753 |
754 #ifdef FEAT_EVAL | |
755 if (firstc == -1) | |
756 { | |
757 firstc = NUL; | |
758 break_ctrl_c = TRUE; | |
759 } | |
760 #endif | |
761 #ifdef FEAT_RIGHTLEFT | |
762 /* start without Hebrew mapping for a command line */ | |
763 if (firstc == ':' || firstc == '=' || firstc == '>') | |
764 cmd_hkmap = 0; | |
765 #endif | |
766 | |
767 ccline.overstrike = FALSE; /* always start in insert mode */ | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
768 |
7 | 769 #ifdef FEAT_SEARCH_EXTRA |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
770 init_incsearch_state(&is_state); |
7 | 771 #endif |
772 | |
773 /* | |
774 * set some variables for redrawcmd() | |
775 */ | |
776 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 777 ccline.cmdindent = (firstc > 0 ? indent : 0); |
778 | |
779 /* alloc initial ccline.cmdbuff */ | |
780 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 781 if (ccline.cmdbuff == NULL) |
782 return NULL; /* out of memory */ | |
783 ccline.cmdlen = ccline.cmdpos = 0; | |
784 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
|
785 sb_text_start_cmdline(); |
7 | 786 |
164 | 787 /* autoindent for :insert and :append */ |
788 if (firstc <= 0) | |
789 { | |
6929 | 790 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 791 ccline.cmdbuff[indent] = NUL; |
792 ccline.cmdpos = indent; | |
793 ccline.cmdspos = indent; | |
794 ccline.cmdlen = indent; | |
795 } | |
796 | |
7 | 797 ExpandInit(&xpc); |
1718 | 798 ccline.xpc = &xpc; |
7 | 799 |
800 #ifdef FEAT_RIGHTLEFT | |
801 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
802 && (firstc == '/' || firstc == '?')) | |
803 cmdmsg_rl = TRUE; | |
804 else | |
805 cmdmsg_rl = FALSE; | |
806 #endif | |
807 | |
808 redir_off = TRUE; /* don't redirect the typed command */ | |
809 if (!cmd_silent) | |
810 { | |
811 i = msg_scrolled; | |
812 msg_scrolled = 0; /* avoid wait_return message */ | |
813 gotocmdline(TRUE); | |
814 msg_scrolled += i; | |
815 redrawcmdprompt(); /* draw prompt or indent */ | |
816 set_cmdspos(); | |
817 } | |
818 xpc.xp_context = EXPAND_NOTHING; | |
819 xpc.xp_backslash = XP_BS_NONE; | |
632 | 820 #ifndef BACKSLASH_IN_FILENAME |
821 xpc.xp_shell = FALSE; | |
822 #endif | |
7 | 823 |
531 | 824 #if defined(FEAT_EVAL) |
825 if (ccline.input_fn) | |
826 { | |
827 xpc.xp_context = ccline.xp_context; | |
828 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 829 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 830 xpc.xp_arg = ccline.xp_arg; |
1322 | 831 # endif |
531 | 832 } |
833 #endif | |
834 | |
7 | 835 /* |
836 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
837 * doing ":@0" when register 0 doesn't contain a CR. | |
838 */ | |
839 msg_scroll = FALSE; | |
840 | |
841 State = CMDLINE; | |
842 | |
843 if (firstc == '/' || firstc == '?' || firstc == '@') | |
844 { | |
845 /* Use ":lmap" mappings for search pattern and input(). */ | |
846 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
847 b_im_ptr = &curbuf->b_p_iminsert; | |
848 else | |
849 b_im_ptr = &curbuf->b_p_imsearch; | |
850 if (*b_im_ptr == B_IMODE_LMAP) | |
851 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
852 #ifdef HAVE_INPUT_METHOD |
7 | 853 im_set_active(*b_im_ptr == B_IMODE_IM); |
854 #endif | |
855 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
856 #ifdef HAVE_INPUT_METHOD |
7 | 857 else if (p_imcmdline) |
858 im_set_active(TRUE); | |
859 #endif | |
860 | |
861 #ifdef FEAT_MOUSE | |
862 setmouse(); | |
863 #endif | |
864 #ifdef CURSOR_SHAPE | |
865 ui_cursor_shape(); /* may show different cursor shape */ | |
866 #endif | |
867 | |
571 | 868 /* When inside an autocommand for writing "exiting" may be set and |
869 * terminal mode set to cooked. Need to set raw mode here then. */ | |
870 settmode(TMODE_RAW); | |
871 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
872 /* 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
|
873 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
|
874 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
|
875 |
7 | 876 #ifdef FEAT_CMDHIST |
877 init_history(); | |
878 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
879 histype = hist_char2type(firstc); | |
880 #endif | |
881 | |
882 #ifdef FEAT_DIGRAPHS | |
1868 | 883 do_digraph(-1); /* init digraph typeahead */ |
7 | 884 #endif |
885 | |
5993 | 886 /* If something above caused an error, reset the flags, we do want to type |
887 * and execute commands. Display may be messed up a bit. */ | |
888 if (did_emsg) | |
889 redrawcmd(); | |
890 did_emsg = FALSE; | |
891 got_int = FALSE; | |
892 | |
7 | 893 /* |
894 * Collect the command string, handling editing keys. | |
895 */ | |
896 for (;;) | |
897 { | |
972 | 898 redir_off = TRUE; /* Don't redirect the typed command. |
899 Repeated, because a ":redir" inside | |
900 completion may switch it on. */ | |
7 | 901 #ifdef USE_ON_FLY_SCROLL |
902 dont_scroll = FALSE; /* allow scrolling here */ | |
903 #endif | |
904 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
905 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
906 did_emsg = FALSE; /* There can't really be a reason why an error |
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
907 that occurs while typing a command should |
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
908 cause the command not to be executed. */ |
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
909 |
7 | 910 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 911 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
912 /* 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
|
913 * anything, such as stop completion. */ |
1472 | 914 do |
915 { | |
916 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
|
917 } while (c == K_IGNORE || c == K_NOP); |
1472 | 918 |
7 | 919 if (KeyTyped) |
920 { | |
921 some_key_typed = TRUE; | |
922 #ifdef FEAT_RIGHTLEFT | |
923 if (cmd_hkmap) | |
924 c = hkmap(c); | |
925 # ifdef FEAT_FKMAP | |
926 if (cmd_fkmap) | |
927 c = cmdl_fkmap(c); | |
928 # endif | |
929 if (cmdmsg_rl && !KeyStuffed) | |
930 { | |
931 /* Invert horizontal movements and operations. Only when | |
932 * typed by the user directly, not when the result of a | |
933 * mapping. */ | |
934 switch (c) | |
935 { | |
936 case K_RIGHT: c = K_LEFT; break; | |
937 case K_S_RIGHT: c = K_S_LEFT; break; | |
938 case K_C_RIGHT: c = K_C_LEFT; break; | |
939 case K_LEFT: c = K_RIGHT; break; | |
940 case K_S_LEFT: c = K_S_RIGHT; break; | |
941 case K_C_LEFT: c = K_C_RIGHT; break; | |
942 } | |
943 } | |
944 #endif | |
945 } | |
946 | |
947 /* | |
948 * Ignore got_int when CTRL-C was typed here. | |
949 * Don't ignore it in :global, we really need to break then, e.g., for | |
950 * ":g/pat/normal /pat" (without the <CR>). | |
951 * Don't ignore it for the input() function. | |
952 */ | |
953 if ((c == Ctrl_C | |
954 #ifdef UNIX | |
955 || c == intr_char | |
956 #endif | |
957 ) | |
958 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
959 && firstc != '@' | |
960 #endif | |
961 #ifdef FEAT_EVAL | |
962 && !break_ctrl_c | |
963 #endif | |
964 && !global_busy) | |
965 got_int = FALSE; | |
966 | |
967 #ifdef FEAT_CMDHIST | |
968 /* free old command line when finished moving around in the history | |
969 * list */ | |
970 if (lookfor != NULL | |
180 | 971 && c != K_S_DOWN && c != K_S_UP |
230 | 972 && c != K_DOWN && c != K_UP |
7 | 973 && c != K_PAGEDOWN && c != K_PAGEUP |
974 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 975 && c != K_LEFT && c != K_RIGHT |
7 | 976 && (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N))) |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
977 VIM_CLEAR(lookfor); |
7 | 978 #endif |
979 | |
980 /* | |
1718 | 981 * When there are matching completions to select <S-Tab> works like |
982 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 983 */ |
1718 | 984 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 985 c = Ctrl_P; |
986 | |
987 #ifdef FEAT_WILDMENU | |
988 /* Special translations for 'wildmenu' */ | |
989 if (did_wild_list && p_wmnu) | |
990 { | |
230 | 991 if (c == K_LEFT) |
7 | 992 c = Ctrl_P; |
230 | 993 else if (c == K_RIGHT) |
7 | 994 c = Ctrl_N; |
995 } | |
996 /* Hitting CR after "emenu Name.": complete submenu */ | |
997 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
998 && ccline.cmdpos > 1 | |
999 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1000 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1001 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1002 c = K_DOWN; | |
1003 #endif | |
1004 | |
1005 /* free expanded names when finished walking through matches */ | |
1006 if (xpc.xp_numfiles != -1 | |
1007 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1008 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1009 && c != Ctrl_L) | |
1010 { | |
1011 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1012 did_wild_list = FALSE; | |
1013 #ifdef FEAT_WILDMENU | |
230 | 1014 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1015 #endif |
1016 xpc.xp_context = EXPAND_NOTHING; | |
1017 wim_index = 0; | |
1018 #ifdef FEAT_WILDMENU | |
1019 if (p_wmnu && wild_menu_showing != 0) | |
1020 { | |
1021 int skt = KeyTyped; | |
532 | 1022 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1023 |
1024 if (ccline.input_fn) | |
1025 RedrawingDisabled = 0; | |
7 | 1026 |
1027 if (wild_menu_showing == WM_SCROLLED) | |
1028 { | |
1029 /* Entered command line, move it up */ | |
1030 cmdline_row--; | |
1031 redrawcmd(); | |
1032 } | |
1033 else if (save_p_ls != -1) | |
1034 { | |
1035 /* restore 'laststatus' and 'winminheight' */ | |
1036 p_ls = save_p_ls; | |
1037 p_wmh = save_p_wmh; | |
1038 last_status(FALSE); | |
195 | 1039 save_cmdline(&save_ccline); |
7 | 1040 update_screen(VALID); /* redraw the screen NOW */ |
195 | 1041 restore_cmdline(&save_ccline); |
7 | 1042 redrawcmd(); |
1043 save_p_ls = -1; | |
1044 } | |
1045 else | |
1046 { | |
1047 win_redraw_last_status(topframe); | |
1048 redraw_statuslines(); | |
1049 } | |
532 | 1050 KeyTyped = skt; |
1051 wild_menu_showing = 0; | |
531 | 1052 if (ccline.input_fn) |
1053 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1054 } |
1055 #endif | |
1056 } | |
1057 | |
1058 #ifdef FEAT_WILDMENU | |
1059 /* Special translations for 'wildmenu' */ | |
1060 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1061 { | |
1062 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1063 if (c == K_DOWN && ccline.cmdpos > 0 |
1064 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1065 c = p_wc; |
230 | 1066 else if (c == K_UP) |
7 | 1067 { |
1068 /* Hitting <Up>: Remove one submenu name in front of the | |
1069 * cursor */ | |
1070 int found = FALSE; | |
1071 | |
1072 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1073 i = 0; | |
1074 while (--j > 0) | |
1075 { | |
1076 /* check for start of menu name */ | |
1077 if (ccline.cmdbuff[j] == ' ' | |
1078 && ccline.cmdbuff[j - 1] != '\\') | |
1079 { | |
1080 i = j + 1; | |
1081 break; | |
1082 } | |
1083 /* check for start of submenu name */ | |
1084 if (ccline.cmdbuff[j] == '.' | |
1085 && ccline.cmdbuff[j - 1] != '\\') | |
1086 { | |
1087 if (found) | |
1088 { | |
1089 i = j + 1; | |
1090 break; | |
1091 } | |
1092 else | |
1093 found = TRUE; | |
1094 } | |
1095 } | |
1096 if (i > 0) | |
1097 cmdline_del(i); | |
1098 c = p_wc; | |
1099 xpc.xp_context = EXPAND_NOTHING; | |
1100 } | |
1101 } | |
714 | 1102 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1103 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1104 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1105 { |
1106 char_u upseg[5]; | |
1107 | |
1108 upseg[0] = PATHSEP; | |
1109 upseg[1] = '.'; | |
1110 upseg[2] = '.'; | |
1111 upseg[3] = PATHSEP; | |
1112 upseg[4] = NUL; | |
1113 | |
1318 | 1114 if (c == K_DOWN |
1115 && ccline.cmdpos > 0 | |
1116 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1117 && (ccline.cmdpos < 3 | |
1118 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1119 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1120 { | |
1121 /* go down a directory */ | |
1122 c = p_wc; | |
1123 } | |
230 | 1124 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1125 { |
1126 /* If in a direct ancestor, strip off one ../ to go down */ | |
1127 int found = FALSE; | |
1128 | |
1129 j = ccline.cmdpos; | |
1130 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1131 while (--j > i) | |
1132 { | |
39 | 1133 #ifdef FEAT_MBYTE |
1134 if (has_mbyte) | |
1135 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1136 #endif | |
7 | 1137 if (vim_ispathsep(ccline.cmdbuff[j])) |
1138 { | |
1139 found = TRUE; | |
1140 break; | |
1141 } | |
1142 } | |
1143 if (found | |
1144 && ccline.cmdbuff[j - 1] == '.' | |
1145 && ccline.cmdbuff[j - 2] == '.' | |
1146 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1147 { | |
1148 cmdline_del(j - 2); | |
1149 c = p_wc; | |
1150 } | |
1151 } | |
230 | 1152 else if (c == K_UP) |
7 | 1153 { |
1154 /* go up a directory */ | |
1155 int found = FALSE; | |
1156 | |
1157 j = ccline.cmdpos - 1; | |
1158 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1159 while (--j > i) | |
1160 { | |
1161 #ifdef FEAT_MBYTE | |
1162 if (has_mbyte) | |
1163 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1164 #endif | |
1165 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1166 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1167 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1168 ccline.cmdbuff[j + 1]) == NULL |
7 | 1169 #endif |
1170 ) | |
1171 { | |
1172 if (found) | |
1173 { | |
1174 i = j + 1; | |
1175 break; | |
1176 } | |
1177 else | |
1178 found = TRUE; | |
1179 } | |
1180 } | |
1181 | |
1182 if (!found) | |
1183 j = i; | |
1184 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1185 j += 4; | |
1186 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1187 && j == i) | |
1188 j += 3; | |
1189 else | |
1190 j = 0; | |
1191 if (j > 0) | |
1192 { | |
1193 /* TODO this is only for DOS/UNIX systems - need to put in | |
1194 * machine-specific stuff here and in upseg init */ | |
1195 cmdline_del(j); | |
1196 put_on_cmdline(upseg + 1, 3, FALSE); | |
1197 } | |
1198 else if (ccline.cmdpos > i) | |
1199 cmdline_del(i); | |
3204 | 1200 |
1201 /* Now complete in the new directory. Set KeyTyped in case the | |
1202 * Up key came from a mapping. */ | |
7 | 1203 c = p_wc; |
3204 | 1204 KeyTyped = TRUE; |
7 | 1205 } |
1206 } | |
1207 | |
1208 #endif /* FEAT_WILDMENU */ | |
1209 | |
1210 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1211 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1212 if (c == Ctrl_BSL) | |
1213 { | |
1214 ++no_mapping; | |
1215 ++allow_keys; | |
1389 | 1216 c = plain_vgetc(); |
7 | 1217 --no_mapping; |
1218 --allow_keys; | |
3859 | 1219 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1220 * is in a mapping. */ | |
1221 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1222 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1223 { |
1224 vungetc(c); | |
1225 c = Ctrl_BSL; | |
1226 } | |
1227 #ifdef FEAT_EVAL | |
1228 else if (c == 'e') | |
1229 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1230 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1231 int len; |
7 | 1232 |
1233 /* | |
1234 * Replace the command line with the result of an expression. | |
625 | 1235 * Need to save and restore the current command line, to be |
1236 * able to enter a new one... | |
7 | 1237 */ |
1238 if (ccline.cmdpos == ccline.cmdlen) | |
1239 new_cmdpos = 99999; /* keep it at the end */ | |
1240 else | |
1241 new_cmdpos = ccline.cmdpos; | |
95 | 1242 |
1243 save_cmdline(&save_ccline); | |
7 | 1244 c = get_expr_register(); |
95 | 1245 restore_cmdline(&save_ccline); |
7 | 1246 if (c == '=') |
1247 { | |
634 | 1248 /* Need to save and restore ccline. And set "textlock" |
632 | 1249 * to avoid nasty things like going to another buffer when |
1250 * evaluating an expression. */ | |
95 | 1251 save_cmdline(&save_ccline); |
634 | 1252 ++textlock; |
7 | 1253 p = get_expr_line(); |
634 | 1254 --textlock; |
95 | 1255 restore_cmdline(&save_ccline); |
2617 | 1256 |
1257 if (p != NULL) | |
7 | 1258 { |
2617 | 1259 len = (int)STRLEN(p); |
1260 if (realloc_cmdbuff(len + 1) == OK) | |
1261 { | |
1262 ccline.cmdlen = len; | |
1263 STRCPY(ccline.cmdbuff, p); | |
1264 vim_free(p); | |
1265 | |
1266 /* Restore the cursor or use the position set with | |
1267 * set_cmdline_pos(). */ | |
1268 if (new_cmdpos > ccline.cmdlen) | |
1269 ccline.cmdpos = ccline.cmdlen; | |
1270 else | |
1271 ccline.cmdpos = new_cmdpos; | |
1272 | |
1273 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1274 redrawcmd(); | |
1275 goto cmdline_changed; | |
1276 } | |
7 | 1277 } |
1278 } | |
1279 beep_flush(); | |
2636 | 1280 got_int = FALSE; /* don't abandon the command line */ |
1281 did_emsg = FALSE; | |
1282 emsg_on_display = FALSE; | |
1283 redrawcmd(); | |
1284 goto cmdline_not_changed; | |
7 | 1285 } |
1286 #endif | |
1287 else | |
1288 { | |
1289 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1290 restart_edit = 'a'; | |
1291 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1292 in history */ | |
1293 goto returncmd; /* back to Normal mode */ | |
1294 } | |
1295 } | |
1296 | |
1297 #ifdef FEAT_CMDWIN | |
1298 if (c == cedit_key || c == K_CMDWIN) | |
1299 { | |
6211 | 1300 if (ex_normal_busy == 0 && got_int == FALSE) |
1301 { | |
1302 /* | |
1303 * Open a window to edit the command line (and history). | |
1304 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1305 c = open_cmdwin(); |
6211 | 1306 some_key_typed = TRUE; |
1307 } | |
7 | 1308 } |
1309 # ifdef FEAT_DIGRAPHS | |
1310 else | |
1311 # endif | |
1312 #endif | |
1313 #ifdef FEAT_DIGRAPHS | |
1314 c = do_digraph(c); | |
1315 #endif | |
1316 | |
1317 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1318 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1319 { | |
168 | 1320 /* In Ex mode a backslash escapes a newline. */ |
1321 if (exmode_active | |
1322 && c != ESC | |
1318 | 1323 && ccline.cmdpos == ccline.cmdlen |
168 | 1324 && ccline.cmdpos > 0 |
1325 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1326 { | |
1327 if (c == K_KENTER) | |
1328 c = '\n'; | |
1329 } | |
1330 else | |
7 | 1331 { |
168 | 1332 gotesc = FALSE; /* Might have typed ESC previously, don't |
1333 truncate the cmdline now. */ | |
1334 if (ccheck_abbr(c + ABBR_OFF)) | |
1335 goto cmdline_changed; | |
1336 if (!cmd_silent) | |
1337 { | |
1338 windgoto(msg_row, 0); | |
1339 out_flush(); | |
1340 } | |
1341 break; | |
7 | 1342 } |
1343 } | |
1344 | |
1345 /* | |
1346 * Completion for 'wildchar' or 'wildcharm' key. | |
1347 * - hitting <ESC> twice means: abandon command line. | |
1348 * - wildcard expansion is only done when the 'wildchar' key is really | |
1349 * typed, not when it comes from a macro | |
1350 */ | |
1351 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1352 { | |
1353 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1354 { | |
1355 /* if 'wildmode' contains "list" may still need to list */ | |
1356 if (xpc.xp_numfiles > 1 | |
1357 && !did_wild_list | |
1358 && (wim_flags[wim_index] & WIM_LIST)) | |
1359 { | |
1360 (void)showmatches(&xpc, FALSE); | |
1361 redrawcmd(); | |
1362 did_wild_list = TRUE; | |
1363 } | |
1364 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1365 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1366 firstc != '@'); | |
7 | 1367 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1368 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1369 firstc != '@'); | |
7 | 1370 else |
1371 res = OK; /* don't insert 'wildchar' now */ | |
1372 } | |
1373 else /* typed p_wc first time */ | |
1374 { | |
1375 wim_index = 0; | |
1376 j = ccline.cmdpos; | |
1377 /* if 'wildmode' first contains "longest", get longest | |
1378 * common part */ | |
1379 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1380 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1381 firstc != '@'); | |
7 | 1382 else |
3961 | 1383 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1384 firstc != '@'); | |
7 | 1385 |
1386 /* if interrupted while completing, behave like it failed */ | |
1387 if (got_int) | |
1388 { | |
1389 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1390 got_int = FALSE; /* don't abandon the command line */ | |
1391 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1392 #ifdef FEAT_WILDMENU | |
1393 xpc.xp_context = EXPAND_NOTHING; | |
1394 #endif | |
1395 goto cmdline_changed; | |
1396 } | |
1397 | |
1398 /* when more than one match, and 'wildmode' first contains | |
1399 * "list", or no change and 'wildmode' contains "longest,list", | |
1400 * list all matches */ | |
1401 if (res == OK && xpc.xp_numfiles > 1) | |
1402 { | |
1403 /* a "longest" that didn't do anything is skipped (but not | |
1404 * "list:longest") */ | |
1405 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1406 wim_index = 1; | |
1407 if ((wim_flags[wim_index] & WIM_LIST) | |
1408 #ifdef FEAT_WILDMENU | |
1409 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1410 #endif | |
1411 ) | |
1412 { | |
1413 if (!(wim_flags[0] & WIM_LONGEST)) | |
1414 { | |
1415 #ifdef FEAT_WILDMENU | |
1416 int p_wmnu_save = p_wmnu; | |
1417 p_wmnu = 0; | |
1418 #endif | |
3961 | 1419 /* remove match */ |
1420 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1421 #ifdef FEAT_WILDMENU |
1422 p_wmnu = p_wmnu_save; | |
1423 #endif | |
1424 } | |
1425 #ifdef FEAT_WILDMENU | |
1426 (void)showmatches(&xpc, p_wmnu | |
1427 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1428 #else | |
1429 (void)showmatches(&xpc, FALSE); | |
1430 #endif | |
1431 redrawcmd(); | |
1432 did_wild_list = TRUE; | |
1433 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1434 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1435 firstc != '@'); | |
7 | 1436 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1437 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1438 firstc != '@'); | |
7 | 1439 } |
1440 else | |
6949 | 1441 vim_beep(BO_WILD); |
7 | 1442 } |
1443 #ifdef FEAT_WILDMENU | |
1444 else if (xpc.xp_numfiles == -1) | |
1445 xpc.xp_context = EXPAND_NOTHING; | |
1446 #endif | |
1447 } | |
1448 if (wim_index < 3) | |
1449 ++wim_index; | |
1450 if (c == ESC) | |
1451 gotesc = TRUE; | |
1452 if (res == OK) | |
1453 goto cmdline_changed; | |
1454 } | |
1455 | |
1456 gotesc = FALSE; | |
1457 | |
1458 /* <S-Tab> goes to last match, in a clumsy way */ | |
1459 if (c == K_S_TAB && KeyTyped) | |
1460 { | |
3961 | 1461 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1462 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1463 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1464 goto cmdline_changed; |
1465 } | |
1466 | |
1467 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1468 c = NL; | |
1469 | |
1470 do_abbr = TRUE; /* default: check for abbreviation */ | |
1471 | |
1472 /* | |
1473 * Big switch for a typed command line character. | |
1474 */ | |
1475 switch (c) | |
1476 { | |
1477 case K_BS: | |
1478 case Ctrl_H: | |
1479 case K_DEL: | |
1480 case K_KDEL: | |
1481 case Ctrl_W: | |
1482 #ifdef FEAT_FKMAP | |
1483 if (cmd_fkmap && c == K_BS) | |
1484 c = K_DEL; | |
1485 #endif | |
1486 if (c == K_KDEL) | |
1487 c = K_DEL; | |
1488 | |
1489 /* | |
1490 * delete current character is the same as backspace on next | |
1491 * character, except at end of line | |
1492 */ | |
1493 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1494 ++ccline.cmdpos; | |
1495 #ifdef FEAT_MBYTE | |
1496 if (has_mbyte && c == K_DEL) | |
1497 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1498 ccline.cmdbuff + ccline.cmdpos); | |
1499 #endif | |
1500 if (ccline.cmdpos > 0) | |
1501 { | |
1502 char_u *p; | |
1503 | |
1504 j = ccline.cmdpos; | |
1505 p = ccline.cmdbuff + j; | |
1506 #ifdef FEAT_MBYTE | |
1507 if (has_mbyte) | |
1508 { | |
1509 p = mb_prevptr(ccline.cmdbuff, p); | |
1510 if (c == Ctrl_W) | |
1511 { | |
1512 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1513 p = mb_prevptr(ccline.cmdbuff, p); | |
1514 i = mb_get_class(p); | |
1515 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1516 p = mb_prevptr(ccline.cmdbuff, p); | |
1517 if (mb_get_class(p) != i) | |
474 | 1518 p += (*mb_ptr2len)(p); |
7 | 1519 } |
1520 } | |
1521 else | |
1522 #endif | |
1523 if (c == Ctrl_W) | |
1524 { | |
1525 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1526 --p; | |
1527 i = vim_iswordc(p[-1]); | |
1528 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1529 && vim_iswordc(p[-1]) == i) | |
1530 --p; | |
1531 } | |
1532 else | |
1533 --p; | |
1534 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1535 ccline.cmdlen -= j - ccline.cmdpos; | |
1536 i = ccline.cmdpos; | |
1537 while (i < ccline.cmdlen) | |
1538 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1539 | |
1540 /* Truncate at the end, required for multi-byte chars. */ | |
1541 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1542 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1543 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1544 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1545 is_state.search_start = is_state.save_cursor; |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1546 /* 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
|
1547 * won't be restored at the wrong position */ |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1548 is_state.old_viewstate = is_state.init_viewstate; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1549 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1550 #endif |
7 | 1551 redrawcmd(); |
1552 } | |
1553 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1554 && ccline.cmdprompt == NULL && indent == 0) | |
1555 { | |
1556 /* In ex and debug mode it doesn't make sense to return. */ | |
1557 if (exmode_active | |
1558 #ifdef FEAT_EVAL | |
1559 || ccline.cmdfirstc == '>' | |
1560 #endif | |
1561 ) | |
1562 goto cmdline_not_changed; | |
1563 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1564 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1565 if (!cmd_silent) |
1566 { | |
1567 #ifdef FEAT_RIGHTLEFT | |
1568 if (cmdmsg_rl) | |
1569 msg_col = Columns; | |
1570 else | |
1571 #endif | |
1572 msg_col = 0; | |
1573 msg_putchar(' '); /* delete ':' */ | |
1574 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1575 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1576 if (ccline.cmdlen == 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1577 is_state.search_start = is_state.save_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1578 #endif |
7 | 1579 redraw_cmdline = TRUE; |
1580 goto returncmd; /* back to cmd mode */ | |
1581 } | |
1582 goto cmdline_changed; | |
1583 | |
1584 case K_INS: | |
1585 case K_KINS: | |
1586 #ifdef FEAT_FKMAP | |
1587 /* if Farsi mode set, we are in reverse insert mode - | |
1588 Do not change the mode */ | |
1589 if (cmd_fkmap) | |
1590 beep_flush(); | |
1591 else | |
1592 #endif | |
1593 ccline.overstrike = !ccline.overstrike; | |
1594 #ifdef CURSOR_SHAPE | |
1595 ui_cursor_shape(); /* may show different cursor shape */ | |
1596 #endif | |
1597 goto cmdline_not_changed; | |
1598 | |
1599 case Ctrl_HAT: | |
782 | 1600 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1601 { |
1602 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1603 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1604 #ifdef HAVE_INPUT_METHOD |
7 | 1605 im_set_active(FALSE); /* Disable input method */ |
1606 #endif | |
1607 if (b_im_ptr != NULL) | |
1608 { | |
1609 if (State & LANGMAP) | |
1610 *b_im_ptr = B_IMODE_LMAP; | |
1611 else | |
1612 *b_im_ptr = B_IMODE_NONE; | |
1613 } | |
1614 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1615 #ifdef HAVE_INPUT_METHOD |
7 | 1616 else |
1617 { | |
1618 /* There are no ":lmap" mappings, toggle IM. When | |
1619 * 'imdisable' is set don't try getting the status, it's | |
1620 * always off. */ | |
1621 if ((p_imdisable && b_im_ptr != NULL) | |
1622 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1623 { | |
1624 im_set_active(FALSE); /* Disable input method */ | |
1625 if (b_im_ptr != NULL) | |
1626 *b_im_ptr = B_IMODE_NONE; | |
1627 } | |
1628 else | |
1629 { | |
1630 im_set_active(TRUE); /* Enable input method */ | |
1631 if (b_im_ptr != NULL) | |
1632 *b_im_ptr = B_IMODE_IM; | |
1633 } | |
1634 } | |
1635 #endif | |
1636 if (b_im_ptr != NULL) | |
1637 { | |
1638 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1639 set_iminsert_global(); | |
1640 else | |
1641 set_imsearch_global(); | |
1642 } | |
1643 #ifdef CURSOR_SHAPE | |
1644 ui_cursor_shape(); /* may show different cursor shape */ | |
1645 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1646 #if defined(FEAT_KEYMAP) |
7 | 1647 /* Show/unshow value of 'keymap' in status lines later. */ |
1648 status_redraw_curbuf(); | |
1649 #endif | |
1650 goto cmdline_not_changed; | |
1651 | |
1652 /* case '@': only in very old vi */ | |
1653 case Ctrl_U: | |
1654 /* delete all characters left of the cursor */ | |
1655 j = ccline.cmdpos; | |
1656 ccline.cmdlen -= j; | |
1657 i = ccline.cmdpos = 0; | |
1658 while (i < ccline.cmdlen) | |
1659 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1660 /* Truncate at the end, required for multi-byte chars. */ | |
1661 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1662 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1663 if (ccline.cmdlen == 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1664 is_state.search_start = is_state.save_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1665 #endif |
7 | 1666 redrawcmd(); |
1667 goto cmdline_changed; | |
1668 | |
1669 #ifdef FEAT_CLIPBOARD | |
1670 case Ctrl_Y: | |
1671 /* Copy the modeless selection, if there is one. */ | |
1672 if (clip_star.state != SELECT_CLEARED) | |
1673 { | |
1674 if (clip_star.state == SELECT_DONE) | |
1675 clip_copy_modeless_selection(TRUE); | |
1676 goto cmdline_not_changed; | |
1677 } | |
1678 break; | |
1679 #endif | |
1680 | |
1681 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1682 case Ctrl_C: | |
571 | 1683 /* In exmode it doesn't make sense to return. Except when |
161 | 1684 * ":normal" runs out of characters. */ |
1685 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1686 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1687 goto cmdline_not_changed; |
1688 | |
1689 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1690 putting it in history */ | |
1691 goto returncmd; /* back to cmd mode */ | |
1692 | |
1693 case Ctrl_R: /* insert register */ | |
1694 #ifdef USE_ON_FLY_SCROLL | |
1695 dont_scroll = TRUE; /* disallow scrolling here */ | |
1696 #endif | |
1697 putcmdline('"', TRUE); | |
1698 ++no_mapping; | |
1389 | 1699 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1700 if (i == Ctrl_O) |
1701 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1702 if (i == Ctrl_R) | |
1389 | 1703 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
|
1704 extra_char = NUL; |
7 | 1705 --no_mapping; |
1706 #ifdef FEAT_EVAL | |
1707 /* | |
1708 * Insert the result of an expression. | |
1709 * Need to save the current command line, to be able to enter | |
1710 * a new one... | |
1711 */ | |
1712 new_cmdpos = -1; | |
1713 if (c == '=') | |
1714 { | |
1715 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1716 { | |
1717 beep_flush(); | |
1718 c = ESC; | |
1719 } | |
1720 else | |
1721 { | |
95 | 1722 save_cmdline(&save_ccline); |
7 | 1723 c = get_expr_register(); |
95 | 1724 restore_cmdline(&save_ccline); |
7 | 1725 } |
1726 } | |
1727 #endif | |
1728 if (c != ESC) /* use ESC to cancel inserting register */ | |
1729 { | |
1015 | 1730 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1731 |
613 | 1732 #ifdef FEAT_EVAL |
606 | 1733 /* When there was a serious error abort getting the |
1734 * command line. */ | |
1735 if (aborting()) | |
1736 { | |
1737 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1738 putting it in history */ | |
1739 goto returncmd; /* back to cmd mode */ | |
1740 } | |
613 | 1741 #endif |
7 | 1742 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1743 #ifdef FEAT_EVAL | |
1744 if (new_cmdpos >= 0) | |
1745 { | |
1746 /* set_cmdline_pos() was used */ | |
1747 if (new_cmdpos > ccline.cmdlen) | |
1748 ccline.cmdpos = ccline.cmdlen; | |
1749 else | |
1750 ccline.cmdpos = new_cmdpos; | |
1751 } | |
1752 #endif | |
1753 } | |
1754 redrawcmd(); | |
1755 goto cmdline_changed; | |
1756 | |
1757 case Ctrl_D: | |
1758 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1759 break; /* Use ^D as normal char instead */ | |
1760 | |
1761 redrawcmd(); | |
1762 continue; /* don't do incremental search now */ | |
1763 | |
1764 case K_RIGHT: | |
1765 case K_S_RIGHT: | |
1766 case K_C_RIGHT: | |
1767 do | |
1768 { | |
1769 if (ccline.cmdpos >= ccline.cmdlen) | |
1770 break; | |
1771 i = cmdline_charsize(ccline.cmdpos); | |
1772 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1773 break; | |
1774 ccline.cmdspos += i; | |
1775 #ifdef FEAT_MBYTE | |
1776 if (has_mbyte) | |
474 | 1777 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1778 + ccline.cmdpos); |
1779 else | |
1780 #endif | |
1781 ++ccline.cmdpos; | |
1782 } | |
180 | 1783 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1784 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1785 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1786 #ifdef FEAT_MBYTE | |
1787 if (has_mbyte) | |
1788 set_cmdspos_cursor(); | |
1789 #endif | |
1790 goto cmdline_not_changed; | |
1791 | |
1792 case K_LEFT: | |
1793 case K_S_LEFT: | |
1794 case K_C_LEFT: | |
1456 | 1795 if (ccline.cmdpos == 0) |
1796 goto cmdline_not_changed; | |
7 | 1797 do |
1798 { | |
1799 --ccline.cmdpos; | |
1800 #ifdef FEAT_MBYTE | |
1801 if (has_mbyte) /* move to first byte of char */ | |
1802 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1803 ccline.cmdbuff + ccline.cmdpos); | |
1804 #endif | |
1805 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1806 } | |
1456 | 1807 while (ccline.cmdpos > 0 |
1808 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1809 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1810 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1811 #ifdef FEAT_MBYTE | |
1812 if (has_mbyte) | |
1813 set_cmdspos_cursor(); | |
1814 #endif | |
1815 goto cmdline_not_changed; | |
1816 | |
1817 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
|
1818 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1819 goto cmdline_not_changed; |
7 | 1820 |
625 | 1821 #ifdef FEAT_GUI_W32 |
1822 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1823 * cancelled. */ | |
1824 case K_F4: | |
1825 if (mod_mask == MOD_MASK_ALT) | |
1826 { | |
1827 redrawcmd(); /* somehow the cmdline is cleared */ | |
1828 goto cmdline_not_changed; | |
1829 } | |
1830 break; | |
1831 #endif | |
1832 | |
7 | 1833 #ifdef FEAT_MOUSE |
1834 case K_MIDDLEDRAG: | |
1835 case K_MIDDLERELEASE: | |
1836 goto cmdline_not_changed; /* Ignore mouse */ | |
1837 | |
1838 case K_MIDDLEMOUSE: | |
1839 # ifdef FEAT_GUI | |
1840 /* When GUI is active, also paste when 'mouse' is empty */ | |
1841 if (!gui.in_use) | |
1842 # endif | |
1843 if (!mouse_has(MOUSE_COMMAND)) | |
1844 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1845 # ifdef FEAT_CLIPBOARD |
7 | 1846 if (clip_star.available) |
1015 | 1847 cmdline_paste('*', TRUE, TRUE); |
7 | 1848 else |
692 | 1849 # endif |
1015 | 1850 cmdline_paste(0, TRUE, TRUE); |
7 | 1851 redrawcmd(); |
1852 goto cmdline_changed; | |
1853 | |
692 | 1854 # ifdef FEAT_DND |
7 | 1855 case K_DROP: |
1015 | 1856 cmdline_paste('~', TRUE, FALSE); |
7 | 1857 redrawcmd(); |
1858 goto cmdline_changed; | |
692 | 1859 # endif |
7 | 1860 |
1861 case K_LEFTDRAG: | |
1862 case K_LEFTRELEASE: | |
1863 case K_RIGHTDRAG: | |
1864 case K_RIGHTRELEASE: | |
1865 /* Ignore drag and release events when the button-down wasn't | |
1866 * seen before. */ | |
1867 if (ignore_drag_release) | |
1868 goto cmdline_not_changed; | |
1869 /* FALLTHROUGH */ | |
1870 case K_LEFTMOUSE: | |
1871 case K_RIGHTMOUSE: | |
1872 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1873 ignore_drag_release = TRUE; | |
1874 else | |
1875 ignore_drag_release = FALSE; | |
1876 # ifdef FEAT_GUI | |
1877 /* When GUI is active, also move when 'mouse' is empty */ | |
1878 if (!gui.in_use) | |
1879 # endif | |
1880 if (!mouse_has(MOUSE_COMMAND)) | |
1881 goto cmdline_not_changed; /* Ignore mouse */ | |
1882 # ifdef FEAT_CLIPBOARD | |
1883 if (mouse_row < cmdline_row && clip_star.available) | |
1884 { | |
1885 int button, is_click, is_drag; | |
1886 | |
1887 /* | |
1888 * Handle modeless selection. | |
1889 */ | |
1890 button = get_mouse_button(KEY2TERMCAP1(c), | |
1891 &is_click, &is_drag); | |
1892 if (mouse_model_popup() && button == MOUSE_LEFT | |
1893 && (mod_mask & MOD_MASK_SHIFT)) | |
1894 { | |
1895 /* Translate shift-left to right button. */ | |
1896 button = MOUSE_RIGHT; | |
1897 mod_mask &= ~MOD_MASK_SHIFT; | |
1898 } | |
1899 clip_modeless(button, is_click, is_drag); | |
1900 goto cmdline_not_changed; | |
1901 } | |
1902 # endif | |
1903 | |
1904 set_cmdspos(); | |
1905 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1906 ++ccline.cmdpos) | |
1907 { | |
1908 i = cmdline_charsize(ccline.cmdpos); | |
1909 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1910 && mouse_col < ccline.cmdspos % Columns + i) | |
1911 break; | |
692 | 1912 # ifdef FEAT_MBYTE |
7 | 1913 if (has_mbyte) |
1914 { | |
1915 /* Count ">" for double-wide char that doesn't fit. */ | |
1916 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1917 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1918 + ccline.cmdpos) - 1; |
1919 } | |
692 | 1920 # endif |
7 | 1921 ccline.cmdspos += i; |
1922 } | |
1923 goto cmdline_not_changed; | |
1924 | |
1925 /* Mouse scroll wheel: ignored here */ | |
1926 case K_MOUSEDOWN: | |
1927 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1928 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1929 case K_MOUSERIGHT: |
7 | 1930 /* Alternate buttons ignored here */ |
1931 case K_X1MOUSE: | |
1932 case K_X1DRAG: | |
1933 case K_X1RELEASE: | |
1934 case K_X2MOUSE: | |
1935 case K_X2DRAG: | |
1936 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1937 case K_MOUSEMOVE: |
7 | 1938 goto cmdline_not_changed; |
1939 | |
1940 #endif /* FEAT_MOUSE */ | |
1941 | |
1942 #ifdef FEAT_GUI | |
1943 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
1944 case K_LEFTRELEASE_NM: | |
1945 goto cmdline_not_changed; | |
1946 | |
1947 case K_VER_SCROLLBAR: | |
540 | 1948 if (msg_scrolled == 0) |
7 | 1949 { |
1950 gui_do_scroll(); | |
1951 redrawcmd(); | |
1952 } | |
1953 goto cmdline_not_changed; | |
1954 | |
1955 case K_HOR_SCROLLBAR: | |
540 | 1956 if (msg_scrolled == 0) |
7 | 1957 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1958 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 1959 redrawcmd(); |
1960 } | |
1961 goto cmdline_not_changed; | |
1962 #endif | |
692 | 1963 #ifdef FEAT_GUI_TABLINE |
1964 case K_TABLINE: | |
1965 case K_TABMENU: | |
1966 /* Don't want to change any tabs here. Make sure the same tab | |
1967 * is still selected. */ | |
1968 if (gui_use_tabline()) | |
1969 gui_mch_set_curtab(tabpage_index(curtab)); | |
1970 goto cmdline_not_changed; | |
1971 #endif | |
1972 | |
7 | 1973 case K_SELECT: /* end of Select mode mapping - ignore */ |
1974 goto cmdline_not_changed; | |
1975 | |
1976 case Ctrl_B: /* begin of command line */ | |
1977 case K_HOME: | |
1978 case K_KHOME: | |
1979 case K_S_HOME: | |
1980 case K_C_HOME: | |
1981 ccline.cmdpos = 0; | |
1982 set_cmdspos(); | |
1983 goto cmdline_not_changed; | |
1984 | |
1985 case Ctrl_E: /* end of command line */ | |
1986 case K_END: | |
1987 case K_KEND: | |
1988 case K_S_END: | |
1989 case K_C_END: | |
1990 ccline.cmdpos = ccline.cmdlen; | |
1991 set_cmdspos_cursor(); | |
1992 goto cmdline_not_changed; | |
1993 | |
1994 case Ctrl_A: /* all matches */ | |
3961 | 1995 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 1996 break; |
1997 goto cmdline_changed; | |
1998 | |
772 | 1999 case Ctrl_L: |
2000 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2001 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2002 goto cmdline_not_changed; |
2003 #endif | |
2004 | |
2005 /* completion: longest common part */ | |
3961 | 2006 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2007 break; |
2008 goto cmdline_changed; | |
2009 | |
2010 case Ctrl_N: /* next match */ | |
2011 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2012 if (xpc.xp_numfiles > 0) |
7 | 2013 { |
3961 | 2014 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2015 0, firstc != '@') == FAIL) | |
7 | 2016 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2017 goto cmdline_not_changed; |
7 | 2018 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2019 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2020 /* FALLTHROUGH */ |
7 | 2021 case K_UP: |
2022 case K_DOWN: | |
2023 case K_S_UP: | |
2024 case K_S_DOWN: | |
2025 case K_PAGEUP: | |
2026 case K_KPAGEUP: | |
2027 case K_PAGEDOWN: | |
2028 case K_KPAGEDOWN: | |
2029 if (hislen == 0 || firstc == NUL) /* no history */ | |
2030 goto cmdline_not_changed; | |
2031 | |
2032 i = hiscnt; | |
2033 | |
2034 /* save current command string so it can be restored later */ | |
2035 if (lookfor == NULL) | |
2036 { | |
2037 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2038 goto cmdline_not_changed; | |
2039 lookfor[ccline.cmdpos] = NUL; | |
2040 } | |
2041 | |
2042 j = (int)STRLEN(lookfor); | |
2043 for (;;) | |
2044 { | |
2045 /* one step backwards */ | |
230 | 2046 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2047 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2048 { |
2049 if (hiscnt == hislen) /* first time */ | |
2050 hiscnt = hisidx[histype]; | |
2051 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2052 hiscnt = hislen - 1; | |
2053 else if (hiscnt != hisidx[histype] + 1) | |
2054 --hiscnt; | |
2055 else /* at top of list */ | |
2056 { | |
2057 hiscnt = i; | |
2058 break; | |
2059 } | |
2060 } | |
2061 else /* one step forwards */ | |
2062 { | |
2063 /* on last entry, clear the line */ | |
2064 if (hiscnt == hisidx[histype]) | |
2065 { | |
2066 hiscnt = hislen; | |
2067 break; | |
2068 } | |
2069 | |
2070 /* not on a history line, nothing to do */ | |
2071 if (hiscnt == hislen) | |
2072 break; | |
2073 if (hiscnt == hislen - 1) /* wrap around */ | |
2074 hiscnt = 0; | |
2075 else | |
2076 ++hiscnt; | |
2077 } | |
2078 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2079 { | |
2080 hiscnt = i; | |
2081 break; | |
2082 } | |
230 | 2083 if ((c != K_UP && c != K_DOWN) |
180 | 2084 || hiscnt == i |
7 | 2085 || STRNCMP(history[histype][hiscnt].hisstr, |
2086 lookfor, (size_t)j) == 0) | |
2087 break; | |
2088 } | |
2089 | |
2090 if (hiscnt != i) /* jumped to other entry */ | |
2091 { | |
2092 char_u *p; | |
2093 int len; | |
2094 int old_firstc; | |
2095 | |
2096 vim_free(ccline.cmdbuff); | |
1718 | 2097 xpc.xp_context = EXPAND_NOTHING; |
7 | 2098 if (hiscnt == hislen) |
2099 p = lookfor; /* back to the old one */ | |
2100 else | |
2101 p = history[histype][hiscnt].hisstr; | |
2102 | |
2103 if (histype == HIST_SEARCH | |
2104 && p != lookfor | |
2105 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2106 { | |
2107 /* Correct for the separator character used when | |
2108 * adding the history entry vs the one used now. | |
2109 * First loop: count length. | |
2110 * Second loop: copy the characters. */ | |
2111 for (i = 0; i <= 1; ++i) | |
2112 { | |
2113 len = 0; | |
2114 for (j = 0; p[j] != NUL; ++j) | |
2115 { | |
2116 /* Replace old sep with new sep, unless it is | |
2117 * escaped. */ | |
2118 if (p[j] == old_firstc | |
2119 && (j == 0 || p[j - 1] != '\\')) | |
2120 { | |
2121 if (i > 0) | |
2122 ccline.cmdbuff[len] = firstc; | |
2123 } | |
2124 else | |
2125 { | |
2126 /* Escape new sep, unless it is already | |
2127 * escaped. */ | |
2128 if (p[j] == firstc | |
2129 && (j == 0 || p[j - 1] != '\\')) | |
2130 { | |
2131 if (i > 0) | |
2132 ccline.cmdbuff[len] = '\\'; | |
2133 ++len; | |
2134 } | |
2135 if (i > 0) | |
2136 ccline.cmdbuff[len] = p[j]; | |
2137 } | |
2138 ++len; | |
2139 } | |
2140 if (i == 0) | |
2141 { | |
2142 alloc_cmdbuff(len); | |
2143 if (ccline.cmdbuff == NULL) | |
2144 goto returncmd; | |
2145 } | |
2146 } | |
2147 ccline.cmdbuff[len] = NUL; | |
2148 } | |
2149 else | |
2150 { | |
2151 alloc_cmdbuff((int)STRLEN(p)); | |
2152 if (ccline.cmdbuff == NULL) | |
2153 goto returncmd; | |
2154 STRCPY(ccline.cmdbuff, p); | |
2155 } | |
2156 | |
2157 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2158 redrawcmd(); | |
2159 goto cmdline_changed; | |
2160 } | |
2161 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2162 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2163 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2164 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2165 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2166 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2167 case Ctrl_T: /* previous match */ |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2168 if (may_adjust_incsearch_highlighting( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2169 firstc, count, &is_state, c) == FAIL) |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2170 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2171 break; |
7 | 2172 #endif |
2173 | |
2174 case Ctrl_V: | |
2175 case Ctrl_Q: | |
2176 #ifdef FEAT_MOUSE | |
2177 ignore_drag_release = TRUE; | |
2178 #endif | |
2179 putcmdline('^', TRUE); | |
2180 c = get_literal(); /* get next (two) character(s) */ | |
2181 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
|
2182 extra_char = NUL; |
7 | 2183 #ifdef FEAT_MBYTE |
2184 /* may need to remove ^ when composing char was typed */ | |
2185 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2186 { | |
2187 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2188 msg_putchar(' '); | |
2189 cursorcmd(); | |
2190 } | |
2191 #endif | |
2192 break; | |
2193 | |
2194 #ifdef FEAT_DIGRAPHS | |
2195 case Ctrl_K: | |
2196 #ifdef FEAT_MOUSE | |
2197 ignore_drag_release = TRUE; | |
2198 #endif | |
2199 putcmdline('?', TRUE); | |
2200 #ifdef USE_ON_FLY_SCROLL | |
2201 dont_scroll = TRUE; /* disallow scrolling here */ | |
2202 #endif | |
2203 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
|
2204 extra_char = NUL; |
7 | 2205 if (c != NUL) |
2206 break; | |
2207 | |
2208 redrawcmd(); | |
2209 goto cmdline_not_changed; | |
2210 #endif /* FEAT_DIGRAPHS */ | |
2211 | |
2212 #ifdef FEAT_RIGHTLEFT | |
2213 case Ctrl__: /* CTRL-_: switch language mode */ | |
2214 if (!p_ari) | |
2215 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2216 # ifdef FEAT_FKMAP |
7 | 2217 if (p_altkeymap) |
2218 { | |
2219 cmd_fkmap = !cmd_fkmap; | |
2220 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2221 ccline.overstrike = FALSE; | |
2222 } | |
2223 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2224 # endif |
7 | 2225 cmd_hkmap = !cmd_hkmap; |
2226 goto cmdline_not_changed; | |
2227 #endif | |
2228 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2229 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
|
2230 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
|
2231 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
|
2232 |
7 | 2233 default: |
2234 #ifdef UNIX | |
2235 if (c == intr_char) | |
2236 { | |
2237 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2238 putting it in history */ | |
2239 goto returncmd; /* back to Normal mode */ | |
2240 } | |
2241 #endif | |
2242 /* | |
2243 * Normal character with no special meaning. Just set mod_mask | |
2244 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2245 * the string <S-Space>. This should only happen after ^V. | |
2246 */ | |
2247 if (!IS_SPECIAL(c)) | |
2248 mod_mask = 0x0; | |
2249 break; | |
2250 } | |
2251 /* | |
2252 * End of switch on command line character. | |
2253 * We come here if we have a normal character. | |
2254 */ | |
2255 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2256 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2257 #ifdef FEAT_MBYTE |
2258 /* Add ABBR_OFF for characters above 0x100, this is | |
2259 * what check_abbr() expects. */ | |
2260 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2261 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2262 c) || c == Ctrl_RSB)) |
7 | 2263 goto cmdline_changed; |
2264 | |
2265 /* | |
2266 * put the character in the command line | |
2267 */ | |
2268 if (IS_SPECIAL(c) || mod_mask != 0) | |
2269 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2270 else | |
2271 { | |
2272 #ifdef FEAT_MBYTE | |
2273 if (has_mbyte) | |
2274 { | |
2275 j = (*mb_char2bytes)(c, IObuff); | |
2276 IObuff[j] = NUL; /* exclude composing chars */ | |
2277 put_on_cmdline(IObuff, j, TRUE); | |
2278 } | |
2279 else | |
2280 #endif | |
2281 { | |
2282 IObuff[0] = c; | |
2283 put_on_cmdline(IObuff, 1, TRUE); | |
2284 } | |
2285 } | |
2286 goto cmdline_changed; | |
2287 | |
2288 /* | |
2289 * This part implements incremental searches for "/" and "?" | |
2290 * Jump to cmdline_not_changed when a character has been read but the command | |
2291 * line did not change. Then we only search and redraw if something changed in | |
2292 * the past. | |
2293 * Jump to cmdline_changed when the command line did change. | |
2294 * (Sorry for the goto's, I know it is ugly). | |
2295 */ | |
2296 cmdline_not_changed: | |
2297 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2298 if (!is_state.incsearch_postponed) |
7 | 2299 continue; |
2300 #endif | |
2301 | |
2302 cmdline_changed: | |
13142
59a16624400a
patch 8.0.1445: cannot act on edits in the command line
Christian Brabandt <cb@256bit.org>
parents:
13107
diff
changeset
|
2303 /* Trigger CmdlineChanged autocommands. */ |
59a16624400a
patch 8.0.1445: cannot act on edits in the command line
Christian Brabandt <cb@256bit.org>
parents:
13107
diff
changeset
|
2304 trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED); |
59a16624400a
patch 8.0.1445: cannot act on edits in the command line
Christian Brabandt <cb@256bit.org>
parents:
13107
diff
changeset
|
2305 |
7 | 2306 #ifdef FEAT_SEARCH_EXTRA |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2307 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2308 #endif |
2309 | |
2310 #ifdef FEAT_RIGHTLEFT | |
2311 if (cmdmsg_rl | |
2312 # ifdef FEAT_ARABIC | |
534 | 2313 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2314 # endif |
2315 ) | |
2316 /* Always redraw the whole command line to fix shaping and | |
3374 | 2317 * right-left typing. Not efficient, but it works. |
2318 * Do it only when there are no characters left to read | |
2319 * to avoid useless intermediate redraws. */ | |
2320 if (vpeekc() == NUL) | |
2321 redrawcmd(); | |
7 | 2322 #endif |
2323 } | |
2324 | |
2325 returncmd: | |
2326 | |
2327 #ifdef FEAT_RIGHTLEFT | |
2328 cmdmsg_rl = FALSE; | |
2329 #endif | |
2330 | |
2331 #ifdef FEAT_FKMAP | |
2332 cmd_fkmap = 0; | |
2333 #endif | |
2334 | |
2335 ExpandCleanup(&xpc); | |
1718 | 2336 ccline.xpc = NULL; |
7 | 2337 |
2338 #ifdef FEAT_SEARCH_EXTRA | |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
2339 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2340 #endif |
2341 | |
2342 if (ccline.cmdbuff != NULL) | |
2343 { | |
2344 /* | |
2345 * Put line in history buffer (":" and "=" only when it was typed). | |
2346 */ | |
2347 #ifdef FEAT_CMDHIST | |
2348 if (ccline.cmdlen && firstc != NUL | |
2349 && (some_key_typed || histype == HIST_SEARCH)) | |
2350 { | |
2351 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2352 histype == HIST_SEARCH ? firstc : NUL); | |
2353 if (firstc == ':') | |
2354 { | |
2355 vim_free(new_last_cmdline); | |
2356 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2357 } | |
2358 } | |
2359 #endif | |
2360 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2361 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
|
2362 abandon_cmdline(); |
7 | 2363 } |
2364 | |
2365 /* | |
2366 * If the screen was shifted up, redraw the whole screen (later). | |
2367 * If the line is too long, clear it, so ruler and shown command do | |
2368 * not get printed in the middle of it. | |
2369 */ | |
2370 msg_check(); | |
2371 msg_scroll = save_msg_scroll; | |
2372 redir_off = FALSE; | |
2373 | |
2374 /* When the command line was typed, no need for a wait-return prompt. */ | |
2375 if (some_key_typed) | |
2376 need_wait_return = FALSE; | |
2377 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2378 /* 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
|
2379 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
|
2380 |
7 | 2381 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2382 #ifdef HAVE_INPUT_METHOD |
7 | 2383 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2384 im_save_status(b_im_ptr); | |
2385 im_set_active(FALSE); | |
2386 #endif | |
2387 #ifdef FEAT_MOUSE | |
2388 setmouse(); | |
2389 #endif | |
2390 #ifdef CURSOR_SHAPE | |
2391 ui_cursor_shape(); /* may show different cursor shape */ | |
2392 #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
|
2393 sb_text_end_cmdline(); |
7 | 2394 |
95 | 2395 { |
2396 char_u *p = ccline.cmdbuff; | |
2397 | |
2398 /* Make ccline empty, getcmdline() may try to use it. */ | |
2399 ccline.cmdbuff = NULL; | |
2400 return p; | |
2401 } | |
7 | 2402 } |
2403 | |
2404 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2405 /* | |
2406 * Get a command line with a prompt. | |
2407 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2408 * f_input() when evaluating an expression from CTRL-R =). | |
2409 * Returns the command line in allocated memory, or NULL. | |
2410 */ | |
2411 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2412 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2413 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2414 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2415 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2416 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2417 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2418 { |
2419 char_u *s; | |
2420 struct cmdline_info save_ccline; | |
2421 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
|
2422 int msg_silent_save = msg_silent; |
7 | 2423 |
95 | 2424 save_cmdline(&save_ccline); |
7 | 2425 ccline.cmdprompt = prompt; |
2426 ccline.cmdattr = attr; | |
531 | 2427 # ifdef FEAT_EVAL |
2428 ccline.xp_context = xp_context; | |
2429 ccline.xp_arg = xp_arg; | |
2430 ccline.input_fn = (firstc == '@'); | |
2431 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2432 msg_silent = 0; |
7 | 2433 s = getcmdline(firstc, 1L, 0); |
95 | 2434 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2435 msg_silent = msg_silent_save; |
3020 | 2436 /* Restore msg_col, the prompt from input() may have changed it. |
2437 * But only if called recursively and the commandline is therefore being | |
2438 * restored to an old one; if not, the input() prompt stays on the screen, | |
2439 * so we need its modified msg_col left intact. */ | |
2440 if (ccline.cmdbuff != NULL) | |
2441 msg_col = msg_col_save; | |
7 | 2442 |
2443 return s; | |
2444 } | |
2445 #endif | |
2446 | |
632 | 2447 /* |
634 | 2448 * Return TRUE when the text must not be changed and we can't switch to |
2449 * another window or buffer. Used when editing the command line, evaluating | |
2450 * 'balloonexpr', etc. | |
632 | 2451 */ |
2452 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2453 text_locked(void) |
632 | 2454 { |
2455 #ifdef FEAT_CMDWIN | |
2456 if (cmdwin_type != 0) | |
2457 return TRUE; | |
2458 #endif | |
634 | 2459 return textlock != 0; |
632 | 2460 } |
2461 | |
2462 /* | |
2463 * Give an error message for a command that isn't allowed while the cmdline | |
2464 * window is open or editing the cmdline in another way. | |
2465 */ | |
2466 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2467 text_locked_msg(void) |
632 | 2468 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2469 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2470 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2471 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2472 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2473 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2474 { |
632 | 2475 #ifdef FEAT_CMDWIN |
2476 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2477 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2478 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2479 return e_secure; |
632 | 2480 } |
2481 | |
819 | 2482 /* |
1834 | 2483 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2484 * and give an error message. | |
819 | 2485 */ |
2486 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2487 curbuf_locked(void) |
819 | 2488 { |
2489 if (curbuf_lock > 0) | |
2490 { | |
2491 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2492 return TRUE; | |
2493 } | |
1834 | 2494 return allbuf_locked(); |
2495 } | |
2496 | |
2497 /* | |
2498 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2499 * message. | |
2500 */ | |
2501 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2502 allbuf_locked(void) |
1834 | 2503 { |
2504 if (allbuf_lock > 0) | |
2505 { | |
2506 EMSG(_("E811: Not allowed to change buffer information now")); | |
2507 return TRUE; | |
2508 } | |
819 | 2509 return FALSE; |
2510 } | |
2511 | |
7 | 2512 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2513 cmdline_charsize(int idx) |
7 | 2514 { |
2515 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2516 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2517 return 1; | |
2518 #endif | |
2519 return ptr2cells(ccline.cmdbuff + idx); | |
2520 } | |
2521 | |
2522 /* | |
2523 * Compute the offset of the cursor on the command line for the prompt and | |
2524 * indent. | |
2525 */ | |
2526 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2527 set_cmdspos(void) |
7 | 2528 { |
531 | 2529 if (ccline.cmdfirstc != NUL) |
7 | 2530 ccline.cmdspos = 1 + ccline.cmdindent; |
2531 else | |
2532 ccline.cmdspos = 0 + ccline.cmdindent; | |
2533 } | |
2534 | |
2535 /* | |
2536 * Compute the screen position for the cursor on the command line. | |
2537 */ | |
2538 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2539 set_cmdspos_cursor(void) |
7 | 2540 { |
2541 int i, m, c; | |
2542 | |
2543 set_cmdspos(); | |
2544 if (KeyTyped) | |
534 | 2545 { |
7 | 2546 m = Columns * Rows; |
534 | 2547 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2548 m = MAXCOL; | |
2549 } | |
7 | 2550 else |
2551 m = MAXCOL; | |
2552 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2553 { | |
2554 c = cmdline_charsize(i); | |
2555 #ifdef FEAT_MBYTE | |
2556 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2557 if (has_mbyte) | |
2558 correct_cmdspos(i, c); | |
2559 #endif | |
1612 | 2560 /* If the cmdline doesn't fit, show cursor on last visible char. |
2561 * Don't move the cursor itself, so we can still append. */ | |
7 | 2562 if ((ccline.cmdspos += c) >= m) |
2563 { | |
2564 ccline.cmdspos -= c; | |
2565 break; | |
2566 } | |
2567 #ifdef FEAT_MBYTE | |
2568 if (has_mbyte) | |
474 | 2569 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2570 #endif |
2571 } | |
2572 } | |
2573 | |
2574 #ifdef FEAT_MBYTE | |
2575 /* | |
2576 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2577 * character that doesn't fit, so that a ">" must be displayed. | |
2578 */ | |
2579 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2580 correct_cmdspos(int idx, int cells) |
7 | 2581 { |
474 | 2582 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2583 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2584 && ccline.cmdspos % Columns + cells > Columns) | |
2585 ccline.cmdspos++; | |
2586 } | |
2587 #endif | |
2588 | |
2589 /* | |
2590 * Get an Ex command line for the ":" command. | |
2591 */ | |
2592 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2593 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2594 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2595 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2596 int indent) /* indent for inside conditionals */ |
7 | 2597 { |
2598 /* When executing a register, remove ':' that's in front of each line. */ | |
2599 if (exec_from_reg && vpeekc() == ':') | |
2600 (void)vgetc(); | |
2601 return getcmdline(c, 1L, indent); | |
2602 } | |
2603 | |
2604 /* | |
2605 * Get an Ex command line for Ex mode. | |
2606 * In Ex mode we only use the OS supplied line editing features and no | |
2607 * mappings or abbreviations. | |
168 | 2608 * Returns a string in allocated memory or NULL. |
7 | 2609 */ |
2610 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2611 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2612 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2613 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2614 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2615 int indent) /* indent for inside conditionals */ |
7 | 2616 { |
168 | 2617 garray_T line_ga; |
2618 char_u *pend; | |
2619 int startcol = 0; | |
1329 | 2620 int c1 = 0; |
168 | 2621 int escaped = FALSE; /* CTRL-V typed */ |
2622 int vcol = 0; | |
2623 char_u *p; | |
1329 | 2624 int prev_char; |
5966 | 2625 int len; |
7 | 2626 |
2627 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2628 * confuses the system function that computes tabstops. */ | |
2629 cursor_on(); | |
2630 | |
2631 /* always start in column 0; write a newline if necessary */ | |
2632 compute_cmdrow(); | |
168 | 2633 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2634 msg_putchar('\n'); |
168 | 2635 if (promptc == ':') |
7 | 2636 { |
164 | 2637 /* indent that is only displayed, not in the line itself */ |
168 | 2638 if (p_prompt) |
2639 msg_putchar(':'); | |
7 | 2640 while (indent-- > 0) |
2641 msg_putchar(' '); | |
2642 startcol = msg_col; | |
2643 } | |
2644 | |
2645 ga_init2(&line_ga, 1, 30); | |
2646 | |
164 | 2647 /* autoindent for :insert and :append is in the line itself */ |
168 | 2648 if (promptc <= 0) |
164 | 2649 { |
2650 vcol = indent; | |
2651 while (indent >= 8) | |
2652 { | |
2653 ga_append(&line_ga, TAB); | |
2654 msg_puts((char_u *)" "); | |
2655 indent -= 8; | |
2656 } | |
2657 while (indent-- > 0) | |
2658 { | |
2659 ga_append(&line_ga, ' '); | |
2660 msg_putchar(' '); | |
2661 } | |
2662 } | |
168 | 2663 ++no_mapping; |
2664 ++allow_keys; | |
164 | 2665 |
7 | 2666 /* |
2667 * Get the line, one character at a time. | |
2668 */ | |
2669 got_int = FALSE; | |
168 | 2670 while (!got_int) |
7 | 2671 { |
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
|
2672 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
|
2673 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
|
2674 |
7 | 2675 if (ga_grow(&line_ga, 40) == FAIL) |
2676 break; | |
2677 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2678 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2679 * 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
|
2680 */ |
1329 | 2681 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
|
2682 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2683 /* 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
|
2684 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
|
2685 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
|
2686 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2687 c1 = vgetc(); |
7 | 2688 |
2689 /* | |
168 | 2690 * Handle line editing. |
2691 * Previously this was left to the system, putting the terminal in | |
2692 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2693 */ |
168 | 2694 if (got_int) |
2695 { | |
2696 msg_putchar('\n'); | |
2697 break; | |
2698 } | |
2699 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2700 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
|
2701 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2702 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
|
2703 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
|
2704 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2705 |
168 | 2706 if (!escaped) |
7 | 2707 { |
168 | 2708 /* CR typed means "enter", which is NL */ |
2709 if (c1 == '\r') | |
2710 c1 = '\n'; | |
2711 | |
2712 if (c1 == BS || c1 == K_BS | |
2713 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2714 { |
168 | 2715 if (line_ga.ga_len > 0) |
2716 { | |
5966 | 2717 #ifdef FEAT_MBYTE |
2718 if (has_mbyte) | |
2719 { | |
2720 p = (char_u *)line_ga.ga_data; | |
2721 p[line_ga.ga_len] = NUL; | |
2722 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2723 line_ga.ga_len -= len; | |
2724 } | |
2725 else | |
2726 #endif | |
2727 --line_ga.ga_len; | |
168 | 2728 goto redraw; |
2729 } | |
2730 continue; | |
7 | 2731 } |
2732 | |
168 | 2733 if (c1 == Ctrl_U) |
7 | 2734 { |
168 | 2735 msg_col = startcol; |
2736 msg_clr_eos(); | |
2737 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
|
2738 goto redraw; |
168 | 2739 } |
2740 | |
2741 if (c1 == Ctrl_T) | |
2742 { | |
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
|
2743 sw = get_sw_value(curbuf); |
168 | 2744 p = (char_u *)line_ga.ga_data; |
2745 p[line_ga.ga_len] = NUL; | |
5995 | 2746 indent = get_indent_str(p, 8, FALSE); |
3740 | 2747 indent += sw - indent % sw; |
168 | 2748 add_indent: |
5995 | 2749 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2750 { |
7009 | 2751 (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
|
2752 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
|
2753 s = skipwhite(p); |
168 | 2754 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2755 *s = ' '; | |
2756 ++line_ga.ga_len; | |
7 | 2757 } |
168 | 2758 redraw: |
2759 /* redraw the line */ | |
2760 msg_col = startcol; | |
2761 vcol = 0; | |
5966 | 2762 p = (char_u *)line_ga.ga_data; |
2763 p[line_ga.ga_len] = NUL; | |
2764 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2765 { |
168 | 2766 if (*p == TAB) |
7 | 2767 { |
168 | 2768 do |
7 | 2769 { |
168 | 2770 msg_putchar(' '); |
2771 } while (++vcol % 8); | |
5966 | 2772 ++p; |
7 | 2773 } |
168 | 2774 else |
164 | 2775 { |
5966 | 2776 len = MB_PTR2LEN(p); |
2777 msg_outtrans_len(p, len); | |
2778 vcol += ptr2cells(p); | |
2779 p += len; | |
7 | 2780 } |
2781 } | |
168 | 2782 msg_clr_eos(); |
1329 | 2783 windgoto(msg_row, msg_col); |
168 | 2784 continue; |
2785 } | |
2786 | |
2787 if (c1 == Ctrl_D) | |
2788 { | |
2789 /* Delete one shiftwidth. */ | |
2790 p = (char_u *)line_ga.ga_data; | |
2791 if (prev_char == '0' || prev_char == '^') | |
7 | 2792 { |
168 | 2793 if (prev_char == '^') |
2794 ex_keep_indent = TRUE; | |
2795 indent = 0; | |
2796 p[--line_ga.ga_len] = NUL; | |
7 | 2797 } |
2798 else | |
2799 { | |
168 | 2800 p[line_ga.ga_len] = NUL; |
5995 | 2801 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
|
2802 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
|
2803 { |
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
|
2804 --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
|
2805 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
|
2806 } |
168 | 2807 } |
5995 | 2808 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2809 { |
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
|
2810 s = skipwhite(p); |
168 | 2811 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2812 --line_ga.ga_len; | |
7 | 2813 } |
168 | 2814 goto add_indent; |
2815 } | |
2816 | |
2817 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2818 { | |
2819 escaped = TRUE; | |
2820 continue; | |
7 | 2821 } |
168 | 2822 |
2823 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2824 if (IS_SPECIAL(c1)) | |
2825 continue; | |
7 | 2826 } |
168 | 2827 |
2828 if (IS_SPECIAL(c1)) | |
2829 c1 = '?'; | |
5966 | 2830 #ifdef FEAT_MBYTE |
2831 if (has_mbyte) | |
2832 len = (*mb_char2bytes)(c1, | |
2833 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2834 else | |
2835 #endif | |
2836 { | |
2837 len = 1; | |
2838 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2839 } | |
168 | 2840 if (c1 == '\n') |
2841 msg_putchar('\n'); | |
2842 else if (c1 == TAB) | |
2843 { | |
2844 /* Don't use chartabsize(), 'ts' can be different */ | |
2845 do | |
2846 { | |
2847 msg_putchar(' '); | |
2848 } while (++vcol % 8); | |
2849 } | |
7 | 2850 else |
2851 { | |
168 | 2852 msg_outtrans_len( |
5966 | 2853 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2854 vcol += char2cells(c1); |
7 | 2855 } |
5966 | 2856 line_ga.ga_len += len; |
168 | 2857 escaped = FALSE; |
2858 | |
2859 windgoto(msg_row, msg_col); | |
164 | 2860 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2861 |
2590 | 2862 /* We are done when a NL is entered, but not when it comes after an |
2863 * odd number of backslashes, that results in a NUL. */ | |
2864 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2865 { |
2590 | 2866 int bcount = 0; |
2867 | |
2868 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2869 ++bcount; | |
2870 | |
2871 if (bcount > 0) | |
2872 { | |
2873 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2874 * "\NL", etc. */ | |
2875 line_ga.ga_len -= (bcount + 1) / 2; | |
2876 pend -= (bcount + 1) / 2; | |
2877 pend[-1] = '\n'; | |
2878 } | |
2879 | |
2880 if ((bcount & 1) == 0) | |
2881 { | |
2882 --line_ga.ga_len; | |
2883 --pend; | |
2884 *pend = NUL; | |
2885 break; | |
2886 } | |
7 | 2887 } |
2888 } | |
2889 | |
168 | 2890 --no_mapping; |
2891 --allow_keys; | |
2892 | |
7 | 2893 /* make following messages go to the next line */ |
2894 msg_didout = FALSE; | |
2895 msg_col = 0; | |
2896 if (msg_row < Rows - 1) | |
2897 ++msg_row; | |
2898 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2899 | |
2900 if (got_int) | |
2901 ga_clear(&line_ga); | |
2902 | |
2903 return (char_u *)line_ga.ga_data; | |
2904 } | |
2905 | |
502 | 2906 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2907 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2908 /* |
2909 * Return TRUE if ccline.overstrike is on. | |
2910 */ | |
2911 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2912 cmdline_overstrike(void) |
7 | 2913 { |
2914 return ccline.overstrike; | |
2915 } | |
2916 | |
2917 /* | |
2918 * Return TRUE if the cursor is at the end of the cmdline. | |
2919 */ | |
2920 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2921 cmdline_at_end(void) |
7 | 2922 { |
2923 return (ccline.cmdpos >= ccline.cmdlen); | |
2924 } | |
2925 #endif | |
2926 | |
574 | 2927 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2928 /* |
2929 * Return the virtual column number at the current cursor position. | |
2930 * This is used by the IM code to obtain the start of the preedit string. | |
2931 */ | |
2932 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2933 cmdline_getvcol_cursor(void) |
7 | 2934 { |
2935 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2936 return MAXCOL; | |
2937 | |
2938 # ifdef FEAT_MBYTE | |
2939 if (has_mbyte) | |
2940 { | |
2941 colnr_T col; | |
2942 int i = 0; | |
2943 | |
2944 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 2945 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 2946 |
2947 return col; | |
2948 } | |
2949 else | |
2950 # endif | |
2951 return ccline.cmdpos; | |
2952 } | |
2953 #endif | |
2954 | |
2955 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
2956 /* | |
2957 * If part of the command line is an IM preedit string, redraw it with | |
2958 * IM feedback attributes. The cursor position is restored after drawing. | |
2959 */ | |
2960 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2961 redrawcmd_preedit(void) |
7 | 2962 { |
2963 if ((State & CMDLINE) | |
2964 && xic != NULL | |
976 | 2965 /* && im_get_status() doesn't work when using SCIM */ |
7 | 2966 && !p_imdisable |
2967 && im_is_preediting()) | |
2968 { | |
2969 int cmdpos = 0; | |
2970 int cmdspos; | |
2971 int old_row; | |
2972 int old_col; | |
2973 colnr_T col; | |
2974 | |
2975 old_row = msg_row; | |
2976 old_col = msg_col; | |
531 | 2977 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 2978 |
2979 # ifdef FEAT_MBYTE | |
2980 if (has_mbyte) | |
2981 { | |
2982 for (col = 0; col < preedit_start_col | |
2983 && cmdpos < ccline.cmdlen; ++col) | |
2984 { | |
2985 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 2986 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2987 } |
2988 } | |
2989 else | |
2990 # endif | |
2991 { | |
2992 cmdspos += preedit_start_col; | |
2993 cmdpos += preedit_start_col; | |
2994 } | |
2995 | |
2996 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
2997 msg_col = cmdspos % (int)Columns; | |
2998 if (msg_row >= Rows) | |
2999 msg_row = Rows - 1; | |
3000 | |
3001 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3002 { | |
3003 int char_len; | |
3004 int char_attr; | |
3005 | |
3006 char_attr = im_get_feedback_attr(col); | |
3007 if (char_attr < 0) | |
3008 break; /* end of preedit string */ | |
3009 | |
3010 # ifdef FEAT_MBYTE | |
3011 if (has_mbyte) | |
474 | 3012 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3013 else |
3014 # endif | |
3015 char_len = 1; | |
3016 | |
3017 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3018 cmdpos += char_len; | |
3019 } | |
3020 | |
3021 msg_row = old_row; | |
3022 msg_col = old_col; | |
3023 } | |
3024 } | |
3025 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3026 | |
3027 /* | |
3028 * Allocate a new command line buffer. | |
3029 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3030 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
3031 */ | |
3032 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3033 alloc_cmdbuff(int len) |
7 | 3034 { |
3035 /* | |
3036 * give some extra space to avoid having to allocate all the time | |
3037 */ | |
3038 if (len < 80) | |
3039 len = 100; | |
3040 else | |
3041 len += 20; | |
3042 | |
3043 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3044 ccline.cmdbufflen = len; | |
3045 } | |
3046 | |
3047 /* | |
3048 * Re-allocate the command line to length len + something extra. | |
3049 * return FAIL for failure, OK otherwise | |
3050 */ | |
3051 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3052 realloc_cmdbuff(int len) |
7 | 3053 { |
3054 char_u *p; | |
3055 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3056 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3057 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
|
3058 |
7 | 3059 p = ccline.cmdbuff; |
3060 alloc_cmdbuff(len); /* will get some more */ | |
3061 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3062 { | |
3063 ccline.cmdbuff = p; /* keep the old one */ | |
3064 return FAIL; | |
3065 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3066 /* 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
|
3067 * 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
|
3068 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
|
3069 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3070 vim_free(p); |
1718 | 3071 |
3072 if (ccline.xpc != NULL | |
3073 && ccline.xpc->xp_pattern != NULL | |
3074 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3075 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3076 { | |
1754 | 3077 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3078 |
3079 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3080 * to point into the newly allocated memory. */ | |
3081 if (i >= 0 && i <= ccline.cmdlen) | |
3082 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3083 } | |
3084 | |
7 | 3085 return OK; |
3086 } | |
3087 | |
359 | 3088 #if defined(FEAT_ARABIC) || defined(PROTO) |
3089 static char_u *arshape_buf = NULL; | |
3090 | |
3091 # if defined(EXITFREE) || defined(PROTO) | |
3092 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3093 free_cmdline_buf(void) |
359 | 3094 { |
3095 vim_free(arshape_buf); | |
3096 } | |
3097 # endif | |
3098 #endif | |
3099 | |
7 | 3100 /* |
3101 * Draw part of the cmdline at the current cursor position. But draw stars | |
3102 * when cmdline_star is TRUE. | |
3103 */ | |
3104 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3105 draw_cmdline(int start, int len) |
7 | 3106 { |
3107 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3108 int i; | |
3109 | |
3110 if (cmdline_star > 0) | |
3111 for (i = 0; i < len; ++i) | |
3112 { | |
3113 msg_putchar('*'); | |
3114 # ifdef FEAT_MBYTE | |
3115 if (has_mbyte) | |
474 | 3116 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3117 # endif |
3118 } | |
3119 else | |
3120 #endif | |
3121 #ifdef FEAT_ARABIC | |
3122 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3123 { | |
3124 static int buflen = 0; | |
3125 char_u *p; | |
3126 int j; | |
3127 int newlen = 0; | |
3128 int mb_l; | |
719 | 3129 int pc, pc1 = 0; |
7 | 3130 int prev_c = 0; |
3131 int prev_c1 = 0; | |
714 | 3132 int u8c; |
3133 int u8cc[MAX_MCO]; | |
7 | 3134 int nc = 0; |
3135 | |
3136 /* | |
3137 * Do arabic shaping into a temporary buffer. This is very | |
3138 * inefficient! | |
3139 */ | |
507 | 3140 if (len * 2 + 2 > buflen) |
7 | 3141 { |
3142 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3143 * alloc()/free() calls. */ | |
359 | 3144 vim_free(arshape_buf); |
507 | 3145 buflen = len * 2 + 2; |
359 | 3146 arshape_buf = alloc(buflen); |
3147 if (arshape_buf == NULL) | |
7 | 3148 return; /* out of memory */ |
3149 } | |
3150 | |
507 | 3151 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3152 { | |
3153 /* Prepend a space to draw the leading composing char on. */ | |
3154 arshape_buf[0] = ' '; | |
3155 newlen = 1; | |
3156 } | |
3157 | |
7 | 3158 for (j = start; j < start + len; j += mb_l) |
3159 { | |
3160 p = ccline.cmdbuff + j; | |
714 | 3161 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3162 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3163 if (ARABIC_CHAR(u8c)) |
3164 { | |
3165 /* Do Arabic shaping. */ | |
3166 if (cmdmsg_rl) | |
3167 { | |
3168 /* displaying from right to left */ | |
3169 pc = prev_c; | |
3170 pc1 = prev_c1; | |
714 | 3171 prev_c1 = u8cc[0]; |
7 | 3172 if (j + mb_l >= start + len) |
3173 nc = NUL; | |
3174 else | |
3175 nc = utf_ptr2char(p + mb_l); | |
3176 } | |
3177 else | |
3178 { | |
3179 /* displaying from left to right */ | |
3180 if (j + mb_l >= start + len) | |
3181 pc = NUL; | |
3182 else | |
714 | 3183 { |
3184 int pcc[MAX_MCO]; | |
3185 | |
3186 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3187 start + len - j - mb_l); |
714 | 3188 pc1 = pcc[0]; |
3189 } | |
7 | 3190 nc = prev_c; |
3191 } | |
3192 prev_c = u8c; | |
3193 | |
714 | 3194 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3195 |
359 | 3196 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3197 if (u8cc[0] != 0) |
7 | 3198 { |
714 | 3199 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3200 if (u8cc[1] != 0) | |
3201 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3202 arshape_buf + newlen); |
7 | 3203 } |
3204 } | |
3205 else | |
3206 { | |
3207 prev_c = u8c; | |
359 | 3208 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3209 newlen += mb_l; |
3210 } | |
3211 } | |
3212 | |
359 | 3213 msg_outtrans_len(arshape_buf, newlen); |
7 | 3214 } |
3215 else | |
3216 #endif | |
3217 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3218 } | |
3219 | |
3220 /* | |
3221 * Put a character on the command line. Shifts the following text to the | |
3222 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3223 * "c" must be printable (fit in one display cell)! | |
3224 */ | |
3225 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3226 putcmdline(int c, int shift) |
7 | 3227 { |
3228 if (cmd_silent) | |
3229 return; | |
3230 msg_no_more = TRUE; | |
3231 msg_putchar(c); | |
3232 if (shift) | |
3233 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3234 msg_no_more = FALSE; | |
3235 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3236 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3237 extra_char_shift = shift; |
7 | 3238 } |
3239 | |
3240 /* | |
3241 * Undo a putcmdline(c, FALSE). | |
3242 */ | |
3243 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3244 unputcmdline(void) |
7 | 3245 { |
3246 if (cmd_silent) | |
3247 return; | |
3248 msg_no_more = TRUE; | |
3249 if (ccline.cmdlen == ccline.cmdpos) | |
3250 msg_putchar(' '); | |
3558 | 3251 #ifdef FEAT_MBYTE |
3252 else if (has_mbyte) | |
3253 draw_cmdline(ccline.cmdpos, | |
3254 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3255 #endif | |
7 | 3256 else |
3257 draw_cmdline(ccline.cmdpos, 1); | |
3258 msg_no_more = FALSE; | |
3259 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3260 extra_char = NUL; |
7 | 3261 } |
3262 | |
3263 /* | |
3264 * Put the given string, of the given length, onto the command line. | |
3265 * If len is -1, then STRLEN() is used to calculate the length. | |
3266 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3267 * part will be redrawn, otherwise it will not. If this function is called | |
3268 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3269 * called afterwards. | |
3270 */ | |
3271 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3272 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3273 { |
3274 int retval; | |
3275 int i; | |
3276 int m; | |
3277 int c; | |
3278 | |
3279 if (len < 0) | |
3280 len = (int)STRLEN(str); | |
3281 | |
3282 /* Check if ccline.cmdbuff needs to be longer */ | |
3283 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
|
3284 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3285 else |
3286 retval = OK; | |
3287 if (retval == OK) | |
3288 { | |
3289 if (!ccline.overstrike) | |
3290 { | |
3291 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3292 ccline.cmdbuff + ccline.cmdpos, | |
3293 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3294 ccline.cmdlen += len; | |
3295 } | |
3296 else | |
3297 { | |
3298 #ifdef FEAT_MBYTE | |
3299 if (has_mbyte) | |
3300 { | |
3301 /* Count nr of characters in the new string. */ | |
3302 m = 0; | |
474 | 3303 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3304 ++m; |
3305 /* Count nr of bytes in cmdline that are overwritten by these | |
3306 * characters. */ | |
3307 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3308 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3309 --m; |
3310 if (i < ccline.cmdlen) | |
3311 { | |
3312 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3313 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3314 ccline.cmdlen += ccline.cmdpos + len - i; | |
3315 } | |
3316 else | |
3317 ccline.cmdlen = ccline.cmdpos + len; | |
3318 } | |
3319 else | |
3320 #endif | |
3321 if (ccline.cmdpos + len > ccline.cmdlen) | |
3322 ccline.cmdlen = ccline.cmdpos + len; | |
3323 } | |
3324 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3325 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3326 | |
3327 #ifdef FEAT_MBYTE | |
3328 if (enc_utf8) | |
3329 { | |
3330 /* When the inserted text starts with a composing character, | |
3331 * backup to the character before it. There could be two of them. | |
3332 */ | |
3333 i = 0; | |
3334 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3335 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3336 { | |
3337 i = (*mb_head_off)(ccline.cmdbuff, | |
3338 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3339 ccline.cmdpos -= i; | |
3340 len += i; | |
3341 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3342 } | |
3343 # ifdef FEAT_ARABIC | |
3344 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3345 { | |
3346 /* Check the previous character for Arabic combining pair. */ | |
3347 i = (*mb_head_off)(ccline.cmdbuff, | |
3348 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3349 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3350 + ccline.cmdpos - i), c)) | |
3351 { | |
3352 ccline.cmdpos -= i; | |
3353 len += i; | |
3354 } | |
3355 else | |
3356 i = 0; | |
3357 } | |
3358 # endif | |
3359 if (i != 0) | |
3360 { | |
3361 /* Also backup the cursor position. */ | |
3362 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3363 ccline.cmdspos -= i; | |
3364 msg_col -= i; | |
3365 if (msg_col < 0) | |
3366 { | |
3367 msg_col += Columns; | |
3368 --msg_row; | |
3369 } | |
3370 } | |
3371 } | |
3372 #endif | |
3373 | |
3374 if (redraw && !cmd_silent) | |
3375 { | |
3376 msg_no_more = TRUE; | |
3377 i = cmdline_row; | |
3114 | 3378 cursorcmd(); |
7 | 3379 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3380 /* Avoid clearing the rest of the line too often. */ | |
3381 if (cmdline_row != i || ccline.overstrike) | |
3382 msg_clr_eos(); | |
3383 msg_no_more = FALSE; | |
3384 } | |
3385 #ifdef FEAT_FKMAP | |
3386 /* | |
3387 * If we are in Farsi command mode, the character input must be in | |
3388 * Insert mode. So do not advance the cmdpos. | |
3389 */ | |
3390 if (!cmd_fkmap) | |
3391 #endif | |
3392 { | |
3393 if (KeyTyped) | |
534 | 3394 { |
7 | 3395 m = Columns * Rows; |
534 | 3396 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3397 m = MAXCOL; | |
3398 } | |
7 | 3399 else |
3400 m = MAXCOL; | |
3401 for (i = 0; i < len; ++i) | |
3402 { | |
3403 c = cmdline_charsize(ccline.cmdpos); | |
3404 #ifdef FEAT_MBYTE | |
3405 /* count ">" for a double-wide char that doesn't fit. */ | |
3406 if (has_mbyte) | |
3407 correct_cmdspos(ccline.cmdpos, c); | |
3408 #endif | |
1612 | 3409 /* Stop cursor at the end of the screen, but do increment the |
3410 * insert position, so that entering a very long command | |
3411 * works, even though you can't see it. */ | |
3412 if (ccline.cmdspos + c < m) | |
3413 ccline.cmdspos += c; | |
7 | 3414 #ifdef FEAT_MBYTE |
3415 if (has_mbyte) | |
3416 { | |
474 | 3417 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3418 if (c > len - i - 1) |
3419 c = len - i - 1; | |
3420 ccline.cmdpos += c; | |
3421 i += c; | |
3422 } | |
3423 #endif | |
3424 ++ccline.cmdpos; | |
3425 } | |
3426 } | |
3427 } | |
3428 if (redraw) | |
3429 msg_check(); | |
3430 return retval; | |
3431 } | |
3432 | |
95 | 3433 static struct cmdline_info prev_ccline; |
3434 static int prev_ccline_used = FALSE; | |
3435 | |
3436 /* | |
3437 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3438 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3439 * available globally in prev_ccline. | |
3440 */ | |
3441 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3442 save_cmdline(struct cmdline_info *ccp) |
95 | 3443 { |
3444 if (!prev_ccline_used) | |
3445 { | |
3446 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3447 prev_ccline_used = TRUE; | |
3448 } | |
3449 *ccp = prev_ccline; | |
3450 prev_ccline = ccline; | |
3451 ccline.cmdbuff = NULL; | |
3452 ccline.cmdprompt = NULL; | |
1718 | 3453 ccline.xpc = NULL; |
95 | 3454 } |
3455 | |
3456 /* | |
1214 | 3457 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3458 */ |
3459 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3460 restore_cmdline(struct cmdline_info *ccp) |
95 | 3461 { |
3462 ccline = prev_ccline; | |
3463 prev_ccline = *ccp; | |
3464 } | |
3465 | |
849 | 3466 #if defined(FEAT_EVAL) || defined(PROTO) |
3467 /* | |
3468 * Save the command line into allocated memory. Returns a pointer to be | |
3469 * passed to restore_cmdline_alloc() later. | |
3470 * Returns NULL when failed. | |
3471 */ | |
3472 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3473 save_cmdline_alloc(void) |
849 | 3474 { |
3475 struct cmdline_info *p; | |
3476 | |
3477 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3478 if (p != NULL) | |
3479 save_cmdline(p); | |
3480 return (char_u *)p; | |
3481 } | |
3482 | |
3483 /* | |
3484 * Restore the command line from the return value of save_cmdline_alloc(). | |
3485 */ | |
3486 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3487 restore_cmdline_alloc(char_u *p) |
849 | 3488 { |
3489 if (p != NULL) | |
3490 { | |
3491 restore_cmdline((struct cmdline_info *)p); | |
3492 vim_free(p); | |
3493 } | |
3494 } | |
3495 #endif | |
3496 | |
15 | 3497 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3498 * 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
|
3499 * Used by CTRL-R command in command-line mode. |
15 | 3500 * insert_reg() can't be used here, because special characters from the |
3501 * register contents will be interpreted as commands. | |
3502 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3503 * Return FAIL for failure, OK otherwise. |
15 | 3504 */ |
3505 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3506 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3507 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3508 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
|
3509 int remcr) /* remove trailing CR */ |
15 | 3510 { |
3511 long i; | |
3512 char_u *arg; | |
772 | 3513 char_u *p; |
15 | 3514 int allocated; |
3515 struct cmdline_info save_ccline; | |
3516 | |
3517 /* check for valid regname; also accept special characters for CTRL-R in | |
3518 * the command line */ | |
3519 if (regname != Ctrl_F && regname != Ctrl_P && regname != Ctrl_W | |
13831
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13794
diff
changeset
|
3520 && regname != Ctrl_A && regname != Ctrl_L |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13794
diff
changeset
|
3521 && !valid_yank_reg(regname, FALSE)) |
15 | 3522 return FAIL; |
3523 | |
3524 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3525 * CTRL-C to break the loop. */ | |
3526 line_breakcheck(); | |
3527 if (got_int) | |
3528 return FAIL; | |
3529 | |
3530 #ifdef FEAT_CLIPBOARD | |
3531 regname = may_get_selection(regname); | |
3532 #endif | |
3533 | |
634 | 3534 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3535 * things like going to another buffer when evaluating an expression. */ |
95 | 3536 save_cmdline(&save_ccline); |
634 | 3537 ++textlock; |
15 | 3538 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3539 --textlock; |
95 | 3540 restore_cmdline(&save_ccline); |
15 | 3541 |
3542 if (i) | |
3543 { | |
3544 /* Got the value of a special register in "arg". */ | |
3545 if (arg == NULL) | |
3546 return FAIL; | |
772 | 3547 |
3548 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3549 * part of the word. */ | |
3550 p = arg; | |
3551 if (p_is && regname == Ctrl_W) | |
3552 { | |
3553 char_u *w; | |
3554 int len; | |
3555 | |
3556 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3557 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3558 { |
3559 #ifdef FEAT_MBYTE | |
3560 if (has_mbyte) | |
3561 { | |
3562 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3563 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3564 break; | |
3565 w -= len; | |
3566 } | |
3567 else | |
3568 #endif | |
3569 { | |
3570 if (!vim_iswordc(w[-1])) | |
3571 break; | |
3572 --w; | |
3573 } | |
3574 } | |
2937 | 3575 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3576 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3577 p += len; | |
3578 } | |
3579 | |
3580 cmdline_paste_str(p, literally); | |
15 | 3581 if (allocated) |
3582 vim_free(arg); | |
3583 return OK; | |
3584 } | |
3585 | |
1015 | 3586 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3587 } |
3588 | |
3589 /* | |
3590 * Put a string on the command line. | |
3591 * When "literally" is TRUE, insert literally. | |
3592 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3593 * line. | |
3594 */ | |
3595 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3596 cmdline_paste_str(char_u *s, int literally) |
15 | 3597 { |
3598 int c, cv; | |
3599 | |
3600 if (literally) | |
3601 put_on_cmdline(s, -1, TRUE); | |
3602 else | |
3603 while (*s != NUL) | |
3604 { | |
3605 cv = *s; | |
3606 if (cv == Ctrl_V && s[1]) | |
3607 ++s; | |
3608 #ifdef FEAT_MBYTE | |
3609 if (has_mbyte) | |
1606 | 3610 c = mb_cptr2char_adv(&s); |
15 | 3611 else |
3612 #endif | |
3613 c = *s++; | |
3628 | 3614 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3615 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3616 #ifdef UNIX |
3617 || c == intr_char | |
3618 #endif | |
3619 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3620 stuffcharReadbuff(Ctrl_V); | |
3621 stuffcharReadbuff(c); | |
3622 } | |
3623 } | |
3624 | |
7 | 3625 #ifdef FEAT_WILDMENU |
3626 /* | |
3627 * Delete characters on the command line, from "from" to the current | |
3628 * position. | |
3629 */ | |
3630 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3631 cmdline_del(int from) |
7 | 3632 { |
3633 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3634 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3635 ccline.cmdlen -= ccline.cmdpos - from; | |
3636 ccline.cmdpos = from; | |
3637 } | |
3638 #endif | |
3639 | |
3640 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3641 * 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
|
3642 * 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
|
3643 * overwritten. |
7 | 3644 */ |
3645 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3646 redrawcmdline(void) |
7 | 3647 { |
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
|
3648 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
|
3649 } |
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
|
3650 |
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
|
3651 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
|
3652 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
|
3653 { |
7 | 3654 if (cmd_silent) |
3655 return; | |
3656 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
|
3657 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
|
3658 compute_cmdrow(); |
7 | 3659 redrawcmd(); |
3660 cursorcmd(); | |
3661 } | |
3662 | |
3663 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3664 redrawcmdprompt(void) |
7 | 3665 { |
3666 int i; | |
3667 | |
3668 if (cmd_silent) | |
3669 return; | |
531 | 3670 if (ccline.cmdfirstc != NUL) |
7 | 3671 msg_putchar(ccline.cmdfirstc); |
3672 if (ccline.cmdprompt != NULL) | |
3673 { | |
3674 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3675 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3676 /* do the reverse of set_cmdspos() */ | |
531 | 3677 if (ccline.cmdfirstc != NUL) |
7 | 3678 --ccline.cmdindent; |
3679 } | |
3680 else | |
3681 for (i = ccline.cmdindent; i > 0; --i) | |
3682 msg_putchar(' '); | |
3683 } | |
3684 | |
3685 /* | |
3686 * Redraw what is currently on the command line. | |
3687 */ | |
3688 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3689 redrawcmd(void) |
7 | 3690 { |
3691 if (cmd_silent) | |
3692 return; | |
3693 | |
683 | 3694 /* when 'incsearch' is set there may be no command line while redrawing */ |
3695 if (ccline.cmdbuff == NULL) | |
3696 { | |
3697 windgoto(cmdline_row, 0); | |
3698 msg_clr_eos(); | |
3699 return; | |
3700 } | |
3701 | |
7 | 3702 msg_start(); |
3703 redrawcmdprompt(); | |
3704 | |
3705 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3706 msg_no_more = TRUE; | |
3707 draw_cmdline(0, ccline.cmdlen); | |
3708 msg_clr_eos(); | |
3709 msg_no_more = FALSE; | |
3710 | |
3711 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
|
3712 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
|
3713 putcmdline(extra_char, extra_char_shift); |
7 | 3714 |
3715 /* | |
3716 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3717 * in cmdline mode we can reset them now. | |
3718 */ | |
3719 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3720 | |
3721 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3722 * in cmdline mode */ | |
3723 skip_redraw = FALSE; | |
3724 } | |
3725 | |
3726 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3727 compute_cmdrow(void) |
7 | 3728 { |
540 | 3729 if (exmode_active || msg_scrolled != 0) |
7 | 3730 cmdline_row = Rows - 1; |
3731 else | |
3732 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
|
3733 + lastwin->w_status_height; |
7 | 3734 } |
3735 | |
3736 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3737 cursorcmd(void) |
7 | 3738 { |
3739 if (cmd_silent) | |
3740 return; | |
3741 | |
3742 #ifdef FEAT_RIGHTLEFT | |
3743 if (cmdmsg_rl) | |
3744 { | |
3745 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3746 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3747 if (msg_row <= 0) | |
3748 msg_row = Rows - 1; | |
3749 } | |
3750 else | |
3751 #endif | |
3752 { | |
3753 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3754 msg_col = ccline.cmdspos % (int)Columns; | |
3755 if (msg_row >= Rows) | |
3756 msg_row = Rows - 1; | |
3757 } | |
3758 | |
3759 windgoto(msg_row, msg_col); | |
3760 #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
|
3761 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
|
3762 redrawcmd_preedit(); |
7 | 3763 #endif |
3764 #ifdef MCH_CURSOR_SHAPE | |
3765 mch_update_cursor(); | |
3766 #endif | |
3767 } | |
3768 | |
3769 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3770 gotocmdline(int clr) |
7 | 3771 { |
3772 msg_start(); | |
3773 #ifdef FEAT_RIGHTLEFT | |
3774 if (cmdmsg_rl) | |
3775 msg_col = Columns - 1; | |
3776 else | |
3777 #endif | |
3778 msg_col = 0; /* always start in column 0 */ | |
3779 if (clr) /* clear the bottom line(s) */ | |
3780 msg_clr_eos(); /* will reset clear_cmdline */ | |
3781 windgoto(cmdline_row, 0); | |
3782 } | |
3783 | |
3784 /* | |
3785 * Check the word in front of the cursor for an abbreviation. | |
3786 * Called when the non-id character "c" has been entered. | |
3787 * When an abbreviation is recognized it is removed from the text with | |
3788 * backspaces and the replacement string is inserted, followed by "c". | |
3789 */ | |
3790 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3791 ccheck_abbr(int c) |
7 | 3792 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3793 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3794 |
7 | 3795 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3796 return FALSE; | |
3797 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3798 /* Do not consider '<,'> be part of the mapping, skip leading whitespace. |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3799 * Actually accepts any mark. */ |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3800 while (VIM_ISWHITE(ccline.cmdbuff[spos]) && spos < ccline.cmdlen) |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3801 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3802 if (ccline.cmdlen - spos > 5 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3803 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3804 && ccline.cmdbuff[spos + 2] == ',' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3805 && ccline.cmdbuff[spos + 3] == '\'') |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3806 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3807 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3808 /* check abbreviation from the beginning of the commandline */ |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3809 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3810 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3811 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3812 } |
3813 | |
3164 | 3814 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3815 static int | |
3816 #ifdef __BORLANDC__ | |
3817 _RTLENTRYF | |
3818 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3819 sort_func_compare(const void *s1, const void *s2) |
3164 | 3820 { |
3821 char_u *p1 = *(char_u **)s1; | |
3822 char_u *p2 = *(char_u **)s2; | |
3823 | |
3824 if (*p1 != '<' && *p2 == '<') return -1; | |
3825 if (*p1 == '<' && *p2 != '<') return 1; | |
3826 return STRCMP(p1, p2); | |
3827 } | |
3828 #endif | |
3829 | |
7 | 3830 /* |
3831 * Return FAIL if this is not an appropriate context in which to do | |
3832 * completion of anything, return OK if it is (even if there are no matches). | |
3833 * For the caller, this means that the character is just passed through like a | |
3834 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3835 */ | |
3836 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3837 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3838 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3839 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3840 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3841 int escape) /* if TRUE, escape the returned matches */ |
7 | 3842 { |
3843 int i, j; | |
3844 char_u *p1; | |
3845 char_u *p2; | |
3846 int difflen; | |
3847 int v; | |
3848 | |
3849 if (xp->xp_numfiles == -1) | |
3850 { | |
3851 set_expand_context(xp); | |
3852 cmd_showtail = expand_showtail(xp); | |
3853 } | |
3854 | |
3855 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3856 { | |
3857 beep_flush(); | |
3858 return OK; /* Something illegal on command line */ | |
3859 } | |
3860 if (xp->xp_context == EXPAND_NOTHING) | |
3861 { | |
3862 /* Caller can use the character as a normal char instead */ | |
3863 return FAIL; | |
3864 } | |
3865 | |
3866 MSG_PUTS("..."); /* show that we are busy */ | |
3867 out_flush(); | |
3868 | |
3869 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3870 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3871 |
3872 if (type == WILD_NEXT || type == WILD_PREV) | |
3873 { | |
3874 /* | |
3875 * Get next/previous match for a previous expanded pattern. | |
3876 */ | |
3877 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3878 } | |
3879 else | |
3880 { | |
3881 /* | |
3882 * Translate string into pattern and expand it. | |
3883 */ | |
1965 | 3884 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3885 xp->xp_context)) == NULL) | |
7 | 3886 p2 = NULL; |
3887 else | |
3888 { | |
2652 | 3889 int use_options = options | |
3961 | 3890 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3891 if (escape) | |
3892 use_options |= WILD_ESCAPE; | |
2652 | 3893 |
3894 if (p_wic) | |
3895 use_options += WILD_ICASE; | |
1965 | 3896 p2 = ExpandOne(xp, p1, |
3897 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3898 use_options, type); |
7 | 3899 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3900 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3901 if (p2 != NULL && type == WILD_LONGEST) |
3902 { | |
1965 | 3903 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3904 if (ccline.cmdbuff[i + j] == '*' |
3905 || ccline.cmdbuff[i + j] == '?') | |
3906 break; | |
3907 if ((int)STRLEN(p2) < j) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
3908 VIM_CLEAR(p2); |
7 | 3909 } |
3910 } | |
3911 } | |
3912 | |
3913 if (p2 != NULL && !got_int) | |
3914 { | |
1965 | 3915 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
|
3916 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3917 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3918 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3919 xp->xp_pattern = ccline.cmdbuff + i; |
3920 } | |
3921 else | |
3922 v = OK; | |
3923 if (v == OK) | |
3924 { | |
323 | 3925 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3926 &ccline.cmdbuff[ccline.cmdpos], | |
3927 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3928 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3929 ccline.cmdlen += difflen; |
3930 ccline.cmdpos += difflen; | |
3931 } | |
3932 } | |
3933 vim_free(p2); | |
3934 | |
3935 redrawcmd(); | |
33 | 3936 cursorcmd(); |
7 | 3937 |
3938 /* When expanding a ":map" command and no matches are found, assume that | |
3939 * the key is supposed to be inserted literally */ | |
3940 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3941 return FAIL; | |
3942 | |
3943 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
3944 beep_flush(); | |
3945 else if (xp->xp_numfiles == 1) | |
3946 /* free expanded pattern */ | |
3947 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
3948 | |
3949 return OK; | |
3950 } | |
3951 | |
3952 /* | |
3953 * Do wildcard expansion on the string 'str'. | |
3954 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 3955 * Return a pointer to allocated memory containing the new string. |
7 | 3956 * Return NULL for failure. |
3957 * | |
1412 | 3958 * "orig" is the originally expanded string, copied to allocated memory. It |
3959 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
3960 * WILD_PREV "orig" should be NULL. | |
3961 * | |
838 | 3962 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
3963 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 3964 * |
3965 * mode = WILD_FREE: just free previously expanded matches | |
3966 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
3967 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
3968 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
3969 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
3970 * mode = WILD_ALL: return all matches concatenated | |
3971 * mode = WILD_LONGEST: return longest matched part | |
3398 | 3972 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 3973 * |
3974 * options = WILD_LIST_NOTFOUND: list entries without a match | |
3975 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
3976 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
3977 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
3978 * options = WILD_ADD_SLASH: add a slash after directory names | |
3979 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
3980 * options = WILD_SILENT: don't print warning messages | |
3981 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 3982 * options = WILD_ICASE: ignore case for files |
7 | 3983 * |
3984 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
3985 */ | |
3986 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3987 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3988 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3989 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3990 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
|
3991 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3992 int mode) |
7 | 3993 { |
3994 char_u *ss = NULL; | |
3995 static int findex; | |
3996 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 3997 int orig_saved = FALSE; |
7 | 3998 int i; |
3999 long_u len; | |
4000 int non_suf_match; /* number without matching suffix */ | |
4001 | |
4002 /* | |
4003 * first handle the case of using an old match | |
4004 */ | |
4005 if (mode == WILD_NEXT || mode == WILD_PREV) | |
4006 { | |
4007 if (xp->xp_numfiles > 0) | |
4008 { | |
4009 if (mode == WILD_PREV) | |
4010 { | |
4011 if (findex == -1) | |
4012 findex = xp->xp_numfiles; | |
4013 --findex; | |
4014 } | |
4015 else /* mode == WILD_NEXT */ | |
4016 ++findex; | |
4017 | |
4018 /* | |
4019 * When wrapping around, return the original string, set findex to | |
4020 * -1. | |
4021 */ | |
4022 if (findex < 0) | |
4023 { | |
4024 if (orig_save == NULL) | |
4025 findex = xp->xp_numfiles - 1; | |
4026 else | |
4027 findex = -1; | |
4028 } | |
4029 if (findex >= xp->xp_numfiles) | |
4030 { | |
4031 if (orig_save == NULL) | |
4032 findex = 0; | |
4033 else | |
4034 findex = -1; | |
4035 } | |
4036 #ifdef FEAT_WILDMENU | |
4037 if (p_wmnu) | |
4038 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4039 findex, cmd_showtail); | |
4040 #endif | |
4041 if (findex == -1) | |
4042 return vim_strsave(orig_save); | |
4043 return vim_strsave(xp->xp_files[findex]); | |
4044 } | |
4045 else | |
4046 return NULL; | |
4047 } | |
4048 | |
1412 | 4049 /* free old names */ |
7 | 4050 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4051 { | |
4052 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4053 xp->xp_numfiles = -1; | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
4054 VIM_CLEAR(orig_save); |
7 | 4055 } |
4056 findex = 0; | |
4057 | |
4058 if (mode == WILD_FREE) /* only release file name */ | |
4059 return NULL; | |
4060 | |
4061 if (xp->xp_numfiles == -1) | |
4062 { | |
4063 vim_free(orig_save); | |
4064 orig_save = orig; | |
1432 | 4065 orig_saved = TRUE; |
7 | 4066 |
4067 /* | |
4068 * Do the expansion. | |
4069 */ | |
4070 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4071 options) == FAIL) | |
4072 { | |
4073 #ifdef FNAME_ILLEGAL | |
4074 /* Illegal file name has been silently skipped. But when there | |
4075 * are wildcards, the real problem is that there was no match, | |
4076 * causing the pattern to be added, which has illegal characters. | |
4077 */ | |
4078 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4079 EMSG2(_(e_nomatch2), str); | |
4080 #endif | |
4081 } | |
4082 else if (xp->xp_numfiles == 0) | |
4083 { | |
4084 if (!(options & WILD_SILENT)) | |
4085 EMSG2(_(e_nomatch2), str); | |
4086 } | |
4087 else | |
4088 { | |
4089 /* Escape the matches for use on the command line. */ | |
4090 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4091 | |
4092 /* | |
4093 * Check for matching suffixes in file names. | |
4094 */ | |
3398 | 4095 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4096 && mode != WILD_LONGEST) | |
7 | 4097 { |
4098 if (xp->xp_numfiles) | |
4099 non_suf_match = xp->xp_numfiles; | |
4100 else | |
4101 non_suf_match = 1; | |
4102 if ((xp->xp_context == EXPAND_FILES | |
4103 || xp->xp_context == EXPAND_DIRECTORIES) | |
4104 && xp->xp_numfiles > 1) | |
4105 { | |
4106 /* | |
4107 * More than one match; check suffix. | |
4108 * The files will have been sorted on matching suffix in | |
4109 * expand_wildcards, only need to check the first two. | |
4110 */ | |
4111 non_suf_match = 0; | |
4112 for (i = 0; i < 2; ++i) | |
4113 if (match_suffix(xp->xp_files[i])) | |
4114 ++non_suf_match; | |
4115 } | |
4116 if (non_suf_match != 1) | |
4117 { | |
4118 /* Can we ever get here unless it's while expanding | |
4119 * interactively? If not, we can get rid of this all | |
4120 * together. Don't really want to wait for this message | |
4121 * (and possibly have to hit return to continue!). | |
4122 */ | |
4123 if (!(options & WILD_SILENT)) | |
4124 EMSG(_(e_toomany)); | |
4125 else if (!(options & WILD_NO_BEEP)) | |
4126 beep_flush(); | |
4127 } | |
4128 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4129 ss = vim_strsave(xp->xp_files[0]); | |
4130 } | |
4131 } | |
4132 } | |
4133 | |
4134 /* Find longest common part */ | |
4135 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4136 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4137 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4138 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4139 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4140 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4141 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4142 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4143 if (has_mbyte) |
7 | 4144 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4145 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
|
4146 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
|
4147 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4148 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4149 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4150 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
|
4151 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
|
4152 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4153 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4154 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4155 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
|
4156 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4157 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4158 ci = xp->xp_files[i][len]; |
4242 | 4159 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4160 || xp->xp_context == EXPAND_FILES |
714 | 4161 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4162 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4163 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4164 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4165 break; |
4166 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4167 else if (c0 != ci) |
7 | 4168 break; |
4169 } | |
4170 if (i < xp->xp_numfiles) | |
4171 { | |
4172 if (!(options & WILD_NO_BEEP)) | |
6949 | 4173 vim_beep(BO_WILD); |
7 | 4174 break; |
4175 } | |
4176 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4177 |
7 | 4178 ss = alloc((unsigned)len + 1); |
4179 if (ss) | |
419 | 4180 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4181 findex = -1; /* next p_wc gets first one */ |
4182 } | |
4183 | |
4184 /* Concatenate all matching names */ | |
4185 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4186 { | |
4187 len = 0; | |
4188 for (i = 0; i < xp->xp_numfiles; ++i) | |
4189 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4190 ss = lalloc(len, TRUE); | |
4191 if (ss != NULL) | |
4192 { | |
4193 *ss = NUL; | |
4194 for (i = 0; i < xp->xp_numfiles; ++i) | |
4195 { | |
4196 STRCAT(ss, xp->xp_files[i]); | |
4197 if (i != xp->xp_numfiles - 1) | |
4198 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4199 } | |
4200 } | |
4201 } | |
4202 | |
4203 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4204 ExpandCleanup(xp); | |
4205 | |
1412 | 4206 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4207 if (!orig_saved) |
1412 | 4208 vim_free(orig); |
4209 | |
7 | 4210 return ss; |
4211 } | |
4212 | |
4213 /* | |
4214 * Prepare an expand structure for use. | |
4215 */ | |
4216 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4217 ExpandInit(expand_T *xp) |
7 | 4218 { |
1718 | 4219 xp->xp_pattern = NULL; |
1965 | 4220 xp->xp_pattern_len = 0; |
7 | 4221 xp->xp_backslash = XP_BS_NONE; |
632 | 4222 #ifndef BACKSLASH_IN_FILENAME |
4223 xp->xp_shell = FALSE; | |
4224 #endif | |
7 | 4225 xp->xp_numfiles = -1; |
4226 xp->xp_files = NULL; | |
632 | 4227 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4228 xp->xp_arg = NULL; | |
4229 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4230 xp->xp_line = NULL; |
7 | 4231 } |
4232 | |
4233 /* | |
4234 * Cleanup an expand structure after use. | |
4235 */ | |
4236 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4237 ExpandCleanup(expand_T *xp) |
7 | 4238 { |
4239 if (xp->xp_numfiles >= 0) | |
4240 { | |
4241 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4242 xp->xp_numfiles = -1; | |
4243 } | |
4244 } | |
4245 | |
4246 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4247 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4248 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4249 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4250 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4251 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4252 int options) |
7 | 4253 { |
4254 int i; | |
4255 char_u *p; | |
4256 | |
4257 /* | |
4258 * May change home directory back to "~" | |
4259 */ | |
4260 if (options & WILD_HOME_REPLACE) | |
4261 tilde_replace(str, numfiles, files); | |
4262 | |
4263 if (options & WILD_ESCAPE) | |
4264 { | |
4265 if (xp->xp_context == EXPAND_FILES | |
2778 | 4266 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4267 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4268 || xp->xp_context == EXPAND_BUFFERS |
4269 || xp->xp_context == EXPAND_DIRECTORIES) | |
4270 { | |
4271 /* | |
4272 * Insert a backslash into a file name before a space, \, %, # | |
4273 * and wildmatch characters, except '~'. | |
4274 */ | |
4275 for (i = 0; i < numfiles; ++i) | |
4276 { | |
4277 /* for ":set path=" we need to escape spaces twice */ | |
4278 if (xp->xp_backslash == XP_BS_THREE) | |
4279 { | |
4280 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4281 if (p != NULL) | |
4282 { | |
4283 vim_free(files[i]); | |
4284 files[i] = p; | |
719 | 4285 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4286 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4287 if (p != NULL) | |
4288 { | |
4289 vim_free(files[i]); | |
4290 files[i] = p; | |
4291 } | |
4292 #endif | |
4293 } | |
4294 } | |
1589 | 4295 #ifdef BACKSLASH_IN_FILENAME |
4296 p = vim_strsave_fnameescape(files[i], FALSE); | |
4297 #else | |
1586 | 4298 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4299 #endif |
7 | 4300 if (p != NULL) |
4301 { | |
4302 vim_free(files[i]); | |
4303 files[i] = p; | |
4304 } | |
4305 | |
4306 /* If 'str' starts with "\~", replace "~" at start of | |
4307 * files[i] with "\~". */ | |
4308 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4309 escape_fname(&files[i]); |
7 | 4310 } |
4311 xp->xp_backslash = XP_BS_NONE; | |
435 | 4312 |
4313 /* If the first file starts with a '+' escape it. Otherwise it | |
4314 * could be seen as "+cmd". */ | |
4315 if (*files[0] == '+') | |
4316 escape_fname(&files[0]); | |
7 | 4317 } |
4318 else if (xp->xp_context == EXPAND_TAGS) | |
4319 { | |
4320 /* | |
4321 * Insert a backslash before characters in a tag name that | |
4322 * would terminate the ":tag" command. | |
4323 */ | |
4324 for (i = 0; i < numfiles; ++i) | |
4325 { | |
4326 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4327 if (p != NULL) | |
4328 { | |
4329 vim_free(files[i]); | |
4330 files[i] = p; | |
4331 } | |
4332 } | |
4333 } | |
4334 } | |
4335 } | |
4336 | |
4337 /* | |
1586 | 4338 * Escape special characters in "fname" for when used as a file name argument |
4339 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4340 * Returns the result in allocated memory. | |
4341 */ | |
4342 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4343 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4344 { |
1685 | 4345 char_u *p; |
1586 | 4346 #ifdef BACKSLASH_IN_FILENAME |
4347 char_u buf[20]; | |
4348 int j = 0; | |
4349 | |
5481 | 4350 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4351 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4352 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4353 buf[j++] = *p; |
4354 buf[j] = NUL; | |
1700 | 4355 p = vim_strsave_escaped(fname, buf); |
1586 | 4356 #else |
1685 | 4357 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4358 if (shell && csh_like_shell() && p != NULL) | |
4359 { | |
4360 char_u *s; | |
4361 | |
4362 /* For csh and similar shells need to put two backslashes before '!'. | |
4363 * One is taken by Vim, one by the shell. */ | |
4364 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4365 vim_free(p); | |
4366 p = s; | |
4367 } | |
1700 | 4368 #endif |
4369 | |
4370 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4371 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4372 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4373 escape_fname(&p); |
4374 | |
1685 | 4375 return p; |
1586 | 4376 } |
4377 | |
4378 /* | |
435 | 4379 * Put a backslash before the file name in "pp", which is in allocated memory. |
4380 */ | |
4381 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4382 escape_fname(char_u **pp) |
435 | 4383 { |
4384 char_u *p; | |
4385 | |
4386 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4387 if (p != NULL) | |
4388 { | |
4389 p[0] = '\\'; | |
4390 STRCPY(p + 1, *pp); | |
4391 vim_free(*pp); | |
4392 *pp = p; | |
4393 } | |
4394 } | |
4395 | |
4396 /* | |
7 | 4397 * For each file name in files[num_files]: |
4398 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4399 */ | |
4400 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4401 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4402 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4403 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4404 char_u **files) |
7 | 4405 { |
4406 int i; | |
4407 char_u *p; | |
4408 | |
4409 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4410 { | |
4411 for (i = 0; i < num_files; ++i) | |
4412 { | |
4413 p = home_replace_save(NULL, files[i]); | |
4414 if (p != NULL) | |
4415 { | |
4416 vim_free(files[i]); | |
4417 files[i] = p; | |
4418 } | |
4419 } | |
4420 } | |
4421 } | |
4422 | |
4423 /* | |
4424 * Show all matches for completion on the command line. | |
4425 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4426 * be inserted like a normal character. | |
4427 */ | |
4428 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4429 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4430 { |
4431 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4432 int num_files; | |
4433 char_u **files_found; | |
4434 int i, j, k; | |
4435 int maxlen; | |
4436 int lines; | |
4437 int columns; | |
4438 char_u *p; | |
4439 int lastlen; | |
4440 int attr; | |
4441 int showtail; | |
4442 | |
4443 if (xp->xp_numfiles == -1) | |
4444 { | |
4445 set_expand_context(xp); | |
4446 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4447 &num_files, &files_found); | |
4448 showtail = expand_showtail(xp); | |
4449 if (i != EXPAND_OK) | |
4450 return i; | |
4451 | |
4452 } | |
4453 else | |
4454 { | |
4455 num_files = xp->xp_numfiles; | |
4456 files_found = xp->xp_files; | |
4457 showtail = cmd_showtail; | |
4458 } | |
4459 | |
4460 #ifdef FEAT_WILDMENU | |
4461 if (!wildmenu) | |
4462 { | |
4463 #endif | |
4464 msg_didany = FALSE; /* lines_left will be set */ | |
4465 msg_start(); /* prepare for paging */ | |
4466 msg_putchar('\n'); | |
4467 out_flush(); | |
4468 cmdline_row = msg_row; | |
4469 msg_didany = FALSE; /* lines_left will be set again */ | |
4470 msg_start(); /* prepare for paging */ | |
4471 #ifdef FEAT_WILDMENU | |
4472 } | |
4473 #endif | |
4474 | |
4475 if (got_int) | |
4476 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4477 #ifdef FEAT_WILDMENU | |
4478 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
|
4479 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4480 #endif |
4481 else | |
4482 { | |
4483 /* find the length of the longest file name */ | |
4484 maxlen = 0; | |
4485 for (i = 0; i < num_files; ++i) | |
4486 { | |
4487 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4488 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4489 || xp->xp_context == EXPAND_BUFFERS)) |
4490 { | |
4491 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4492 j = vim_strsize(NameBuff); | |
4493 } | |
4494 else | |
4495 j = vim_strsize(L_SHOWFILE(i)); | |
4496 if (j > maxlen) | |
4497 maxlen = j; | |
4498 } | |
4499 | |
4500 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4501 lines = num_files; | |
4502 else | |
4503 { | |
4504 /* compute the number of columns and lines for the listing */ | |
4505 maxlen += 2; /* two spaces between file names */ | |
4506 columns = ((int)Columns + 2) / maxlen; | |
4507 if (columns < 1) | |
4508 columns = 1; | |
4509 lines = (num_files + columns - 1) / columns; | |
4510 } | |
4511 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4512 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4513 |
4514 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4515 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4516 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4517 msg_clr_eos(); |
4518 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
|
4519 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4520 } |
4521 | |
4522 /* list the files line by line */ | |
4523 for (i = 0; i < lines; ++i) | |
4524 { | |
4525 lastlen = 999; | |
4526 for (k = i; k < num_files; k += lines) | |
4527 { | |
4528 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4529 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4530 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4531 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4532 msg_advance(maxlen + 1); | |
4533 msg_puts(p); | |
4534 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
|
4535 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4536 break; |
4537 } | |
4538 for (j = maxlen - lastlen; --j >= 0; ) | |
4539 msg_putchar(' '); | |
4540 if (xp->xp_context == EXPAND_FILES | |
714 | 4541 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4542 || xp->xp_context == EXPAND_BUFFERS) |
4543 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4544 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4545 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4546 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4547 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4548 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4549 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4550 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4551 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4552 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4553 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
|
4554 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4555 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4556 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4557 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4558 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4559 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4560 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4561 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4562 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4563 j = mch_isdir(files_found[k]); |
7 | 4564 if (showtail) |
4565 p = L_SHOWFILE(k); | |
4566 else | |
4567 { | |
4568 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4569 TRUE); | |
4570 p = NameBuff; | |
4571 } | |
4572 } | |
4573 else | |
4574 { | |
4575 j = FALSE; | |
4576 p = L_SHOWFILE(k); | |
4577 } | |
4578 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4579 } | |
4580 if (msg_col > 0) /* when not wrapped around */ | |
4581 { | |
4582 msg_clr_eos(); | |
4583 msg_putchar('\n'); | |
4584 } | |
4585 out_flush(); /* show one line at a time */ | |
4586 if (got_int) | |
4587 { | |
4588 got_int = FALSE; | |
4589 break; | |
4590 } | |
4591 } | |
4592 | |
4593 /* | |
4594 * we redraw the command below the lines that we have just listed | |
4595 * This is a bit tricky, but it saves a lot of screen updating. | |
4596 */ | |
4597 cmdline_row = msg_row; /* will put it back later */ | |
4598 } | |
4599 | |
4600 if (xp->xp_numfiles == -1) | |
4601 FreeWild(num_files, files_found); | |
4602 | |
4603 return EXPAND_OK; | |
4604 } | |
4605 | |
4606 /* | |
4607 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4608 * Find tail of file name path, but ignore trailing "/". | |
4609 */ | |
4610 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4611 sm_gettail(char_u *s) |
7 | 4612 { |
4613 char_u *p; | |
4614 char_u *t = s; | |
4615 int had_sep = FALSE; | |
4616 | |
4617 for (p = s; *p != NUL; ) | |
4618 { | |
4619 if (vim_ispathsep(*p) | |
4620 #ifdef BACKSLASH_IN_FILENAME | |
4621 && !rem_backslash(p) | |
4622 #endif | |
4623 ) | |
4624 had_sep = TRUE; | |
4625 else if (had_sep) | |
4626 { | |
4627 t = p; | |
4628 had_sep = FALSE; | |
4629 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4630 MB_PTR_ADV(p); |
7 | 4631 } |
4632 return t; | |
4633 } | |
4634 | |
4635 /* | |
4636 * Return TRUE if we only need to show the tail of completion matches. | |
4637 * When not completing file names or there is a wildcard in the path FALSE is | |
4638 * returned. | |
4639 */ | |
4640 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4641 expand_showtail(expand_T *xp) |
7 | 4642 { |
4643 char_u *s; | |
4644 char_u *end; | |
4645 | |
4646 /* When not completing file names a "/" may mean something different. */ | |
714 | 4647 if (xp->xp_context != EXPAND_FILES |
4648 && xp->xp_context != EXPAND_SHELLCMD | |
4649 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4650 return FALSE; |
4651 | |
4652 end = gettail(xp->xp_pattern); | |
4653 if (end == xp->xp_pattern) /* there is no path separator */ | |
4654 return FALSE; | |
4655 | |
4656 for (s = xp->xp_pattern; s < end; s++) | |
4657 { | |
4658 /* Skip escaped wildcards. Only when the backslash is not a path | |
4659 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4660 if (rem_backslash(s)) | |
4661 ++s; | |
4662 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4663 return FALSE; | |
4664 } | |
4665 return TRUE; | |
4666 } | |
4667 | |
4668 /* | |
4669 * Prepare a string for expansion. | |
4670 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4671 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4672 * When expanding other names: The string will be used with regcomp(). Copy |
4673 * the name into allocated memory and prepend "^". | |
4674 */ | |
4675 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4676 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4677 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4678 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4679 int context) /* EXPAND_FILES etc. */ |
7 | 4680 { |
4681 char_u *retval; | |
4682 int i, j; | |
4683 int new_len; | |
4684 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4685 int ends_in_star; |
7 | 4686 |
714 | 4687 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4688 && context != EXPAND_FILES_IN_PATH |
714 | 4689 && context != EXPAND_SHELLCMD |
4690 && context != EXPAND_DIRECTORIES) | |
7 | 4691 { |
4692 /* | |
4693 * Matching will be done internally (on something other than files). | |
4694 * So we convert the file-matching-type wildcards into our kind for | |
4695 * use with vim_regcomp(). First work out how long it will be: | |
4696 */ | |
4697 | |
4698 /* For help tags the translation is done in find_help_tags(). | |
4699 * For a tag pattern starting with "/" no translation is needed. */ | |
4700 if (context == EXPAND_HELP | |
4701 || context == EXPAND_COLORS | |
4702 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4703 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4704 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4705 || 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
|
4706 || ((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
|
4707 || 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
|
4708 && fname[0] == '/')) |
7 | 4709 retval = vim_strnsave(fname, len); |
4710 else | |
4711 { | |
4712 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4713 for (i = 0; i < len; i++) | |
4714 { | |
4715 if (fname[i] == '*' || fname[i] == '~') | |
4716 new_len++; /* '*' needs to be replaced by ".*" | |
4717 '~' needs to be replaced by "\~" */ | |
4718 | |
4719 /* Buffer names are like file names. "." should be literal */ | |
4720 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4721 new_len++; /* "." becomes "\." */ | |
4722 | |
4723 /* Custom expansion takes care of special things, match | |
4724 * backslashes literally (perhaps also for other types?) */ | |
634 | 4725 if ((context == EXPAND_USER_DEFINED |
4726 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4727 new_len++; /* '\' becomes "\\" */ |
4728 } | |
4729 retval = alloc(new_len); | |
4730 if (retval != NULL) | |
4731 { | |
4732 retval[0] = '^'; | |
4733 j = 1; | |
4734 for (i = 0; i < len; i++, j++) | |
4735 { | |
4736 /* Skip backslash. But why? At least keep it for custom | |
4737 * expansion. */ | |
4738 if (context != EXPAND_USER_DEFINED | |
407 | 4739 && context != EXPAND_USER_LIST |
4740 && fname[i] == '\\' | |
4741 && ++i == len) | |
7 | 4742 break; |
4743 | |
4744 switch (fname[i]) | |
4745 { | |
4746 case '*': retval[j++] = '.'; | |
4747 break; | |
4748 case '~': retval[j++] = '\\'; | |
4749 break; | |
4750 case '?': retval[j] = '.'; | |
4751 continue; | |
4752 case '.': if (context == EXPAND_BUFFERS) | |
4753 retval[j++] = '\\'; | |
4754 break; | |
407 | 4755 case '\\': if (context == EXPAND_USER_DEFINED |
4756 || context == EXPAND_USER_LIST) | |
7 | 4757 retval[j++] = '\\'; |
4758 break; | |
4759 } | |
4760 retval[j] = fname[i]; | |
4761 } | |
4762 retval[j] = NUL; | |
4763 } | |
4764 } | |
4765 } | |
4766 else | |
4767 { | |
4768 retval = alloc(len + 4); | |
4769 if (retval != NULL) | |
4770 { | |
419 | 4771 vim_strncpy(retval, fname, len); |
7 | 4772 |
4773 /* | |
831 | 4774 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4775 * * would become **, which walks the whole tree. | |
7 | 4776 * ~ would be at the start of the file name, but not the tail. |
4777 * $ could be anywhere in the tail. | |
4778 * ` could be anywhere in the file name. | |
1484 | 4779 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4780 */ |
4781 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4782 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
|
4783 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4784 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4785 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4786 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4787 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4788 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4789 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4790 #endif |
7 | 4791 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4792 && !ends_in_star |
7 | 4793 && vim_strchr(tail, '$') == NULL |
4794 && vim_strchr(retval, '`') == NULL) | |
4795 retval[len++] = '*'; | |
1484 | 4796 else if (len > 0 && retval[len - 1] == '$') |
4797 --len; | |
7 | 4798 retval[len] = NUL; |
4799 } | |
4800 } | |
4801 return retval; | |
4802 } | |
4803 | |
4804 /* | |
4805 * Must parse the command line so far to work out what context we are in. | |
4806 * Completion can then be done based on that context. | |
4807 * This routine sets the variables: | |
4808 * xp->xp_pattern The start of the pattern to be expanded within | |
4809 * the command line (ends at the cursor). | |
4810 * xp->xp_context The type of thing to expand. Will be one of: | |
4811 * | |
4812 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4813 * the command line, like an unknown command. Caller | |
4814 * should beep. | |
4815 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4816 * a normal char, rather than for completion. eg | |
4817 * :s/^I/ | |
4818 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4819 * it. | |
4820 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4821 * EXPAND_FILES After command with XFILE set, or after setting | |
4822 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4823 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4824 * when we know only directories are of interest. eg | |
4825 * :set dir=^I | |
714 | 4826 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4827 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4828 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4829 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4830 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4831 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4832 * EXPAND_EVENTS Complete event names | |
4833 * EXPAND_SYNTAX Complete :syntax command arguments | |
4834 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4835 * EXPAND_AUGROUP Complete autocommand group names | |
4836 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4837 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4838 * eg :unmap a^I , :cunab x^I | |
4839 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4840 * eg :call sub^I | |
4841 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4842 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4843 * names in expressions, eg :while s^I | |
4844 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4845 * EXPAND_USER Complete user names |
7 | 4846 */ |
4847 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4848 set_expand_context(expand_T *xp) |
7 | 4849 { |
168 | 4850 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4851 if (ccline.cmdfirstc != ':' |
4852 #ifdef FEAT_EVAL | |
168 | 4853 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4854 && !ccline.input_fn |
7 | 4855 #endif |
4856 ) | |
4857 { | |
4858 xp->xp_context = EXPAND_NOTHING; | |
4859 return; | |
4860 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4861 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4862 } |
4863 | |
4864 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4865 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4866 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4867 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
|
4868 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
|
4869 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4870 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4871 { |
4872 int old_char = NUL; | |
4873 char_u *nextcomm; | |
4874 | |
4875 /* | |
4876 * Avoid a UMR warning from Purify, only save the character if it has been | |
4877 * written before. | |
4878 */ | |
4879 if (col < len) | |
4880 old_char = str[col]; | |
4881 str[col] = NUL; | |
4882 nextcomm = str; | |
168 | 4883 |
4884 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4885 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4886 { |
4887 # ifdef FEAT_CMDL_COMPL | |
168 | 4888 /* pass CMD_SIZE because there is no real command */ |
4889 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4890 # endif |
4891 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4892 else if (use_ccline && ccline.input_fn) |
531 | 4893 { |
4894 xp->xp_context = ccline.xp_context; | |
4895 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4896 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4897 xp->xp_arg = ccline.xp_arg; |
1322 | 4898 # endif |
531 | 4899 } |
168 | 4900 else |
4901 #endif | |
4902 while (nextcomm != NULL) | |
4903 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4904 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4905 /* 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
|
4906 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4907 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4908 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4909 |
7 | 4910 str[col] = old_char; |
4911 } | |
4912 | |
4913 /* | |
4914 * Expand the command line "str" from context "xp". | |
4915 * "xp" must have been set by set_cmd_context(). | |
4916 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4917 * starts. | |
4918 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4919 * cursor. | |
4920 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4921 * key that triggered expansion literally. | |
4922 * Returns EXPAND_OK otherwise. | |
4923 */ | |
4924 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4925 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4926 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4927 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
|
4928 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4929 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4930 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4931 { |
4932 char_u *file_str = NULL; | |
2652 | 4933 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4934 |
4935 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4936 { | |
4937 beep_flush(); | |
4938 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4939 } | |
4940 if (xp->xp_context == EXPAND_NOTHING) | |
4941 { | |
4942 /* Caller can use the character as a normal char instead */ | |
4943 return EXPAND_NOTHING; | |
4944 } | |
4945 | |
4946 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 4947 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
4948 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 4949 if (file_str == NULL) |
4950 return EXPAND_UNSUCCESSFUL; | |
4951 | |
2652 | 4952 if (p_wic) |
4953 options += WILD_ICASE; | |
4954 | |
7 | 4955 /* find all files that match the description */ |
2652 | 4956 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 4957 { |
4958 *matchcount = 0; | |
4959 *matches = NULL; | |
4960 } | |
4961 vim_free(file_str); | |
4962 | |
4963 return EXPAND_OK; | |
4964 } | |
4965 | |
4966 #ifdef FEAT_MULTI_LANG | |
4967 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4968 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4969 * 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
|
4970 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 4971 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
4972 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 4973 |
4974 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4975 cleanup_help_tags(int num_file, char_u **file) |
7 | 4976 { |
4977 int i, j; | |
4978 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4979 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4980 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4981 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4982 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
|
4983 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4984 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4985 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4986 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4987 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4988 *p = NUL; |
7 | 4989 |
4990 for (i = 0; i < num_file; ++i) | |
4991 { | |
4992 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
|
4993 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4994 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4995 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 4996 { |
4997 /* Sorting on priority means the same item in another language may | |
4998 * be anywhere. Search all items for a match up to the "@en". */ | |
4999 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
|
5000 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
|
5001 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 5002 break; |
5003 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
5004 /* item only exists with @en, remove it */ |
7 | 5005 file[i][len] = NUL; |
5006 } | |
5007 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5008 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5009 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5010 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
|
5011 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5012 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5013 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5014 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5015 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
|
5016 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5017 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5018 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5019 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5020 } |
7 | 5021 } |
5022 #endif | |
5023 | |
5024 /* | |
5025 * Do the expansion based on xp->xp_context and "pat". | |
5026 */ | |
5027 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5028 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5029 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5030 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5031 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5032 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5033 int options) /* EW_ flags */ |
7 | 5034 { |
5035 #ifdef FEAT_CMDL_COMPL | |
5036 regmatch_T regmatch; | |
5037 #endif | |
5038 int ret; | |
5039 int flags; | |
5040 | |
5041 flags = EW_DIR; /* include directories */ | |
5042 if (options & WILD_LIST_NOTFOUND) | |
5043 flags |= EW_NOTFOUND; | |
5044 if (options & WILD_ADD_SLASH) | |
5045 flags |= EW_ADDSLASH; | |
5046 if (options & WILD_KEEP_ALL) | |
5047 flags |= EW_KEEPALL; | |
5048 if (options & WILD_SILENT) | |
5049 flags |= EW_SILENT; | |
6659 | 5050 if (options & WILD_ALLLINKS) |
5051 flags |= EW_ALLLINKS; | |
7 | 5052 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5053 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5054 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5055 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5056 { |
5057 /* | |
5058 * Expand file or directory names. | |
5059 */ | |
5060 int free_pat = FALSE; | |
5061 int i; | |
5062 | |
5063 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5064 * space */ | |
5065 if (xp->xp_backslash != XP_BS_NONE) | |
5066 { | |
5067 free_pat = TRUE; | |
5068 pat = vim_strsave(pat); | |
5069 for (i = 0; pat[i]; ++i) | |
5070 if (pat[i] == '\\') | |
5071 { | |
5072 if (xp->xp_backslash == XP_BS_THREE | |
5073 && pat[i + 1] == '\\' | |
5074 && pat[i + 2] == '\\' | |
5075 && pat[i + 3] == ' ') | |
1621 | 5076 STRMOVE(pat + i, pat + i + 3); |
7 | 5077 if (xp->xp_backslash == XP_BS_ONE |
5078 && pat[i + 1] == ' ') | |
1621 | 5079 STRMOVE(pat + i, pat + i + 1); |
7 | 5080 } |
5081 } | |
5082 | |
5083 if (xp->xp_context == EXPAND_FILES) | |
5084 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5085 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
|
5086 flags |= (EW_FILE | EW_PATH); |
7 | 5087 else |
5088 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5089 if (options & WILD_ICASE) |
5090 flags |= EW_ICASE; | |
5091 | |
2016 | 5092 /* Expand wildcards, supporting %:h and the like. */ |
5093 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5094 if (free_pat) |
5095 vim_free(pat); | |
5096 return ret; | |
5097 } | |
5098 | |
5099 *file = (char_u **)""; | |
5100 *num_file = 0; | |
5101 if (xp->xp_context == EXPAND_HELP) | |
5102 { | |
1696 | 5103 /* With an empty argument we would get all the help tags, which is |
5104 * very slow. Get matches for "help" instead. */ | |
5105 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5106 num_file, file, FALSE) == OK) | |
7 | 5107 { |
5108 #ifdef FEAT_MULTI_LANG | |
5109 cleanup_help_tags(*num_file, *file); | |
5110 #endif | |
5111 return OK; | |
5112 } | |
5113 return FAIL; | |
5114 } | |
5115 | |
5116 #ifndef FEAT_CMDL_COMPL | |
5117 return FAIL; | |
5118 #else | |
716 | 5119 if (xp->xp_context == EXPAND_SHELLCMD) |
5120 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5121 if (xp->xp_context == EXPAND_OLD_SETTING) |
5122 return ExpandOldSetting(num_file, file); | |
5123 if (xp->xp_context == EXPAND_BUFFERS) | |
5124 return ExpandBufnames(pat, num_file, file, options); | |
5125 if (xp->xp_context == EXPAND_TAGS | |
5126 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5127 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5128 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5129 { |
5130 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5131 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
|
5132 directories); |
2929 | 5133 } |
7 | 5134 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5135 { |
3106 | 5136 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5137 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5138 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5139 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5140 { |
5141 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5142 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5143 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5144 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5145 { |
5146 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
|
5147 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5148 } |
407 | 5149 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5150 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5151 return ExpandUserList(xp, num_file, file); |
407 | 5152 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5153 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5154 return ExpandPackAddDir(pat, num_file, file); |
7 | 5155 |
5156 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5157 if (regmatch.regprog == NULL) | |
5158 return FAIL; | |
5159 | |
5160 /* set ignore-case according to p_ic, p_scs and pat */ | |
5161 regmatch.rm_ic = ignorecase(pat); | |
5162 | |
5163 if (xp->xp_context == EXPAND_SETTINGS | |
5164 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5165 ret = ExpandSettings(xp, ®match, num_file, file); | |
5166 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5167 ret = ExpandMappings(®match, num_file, file); | |
5168 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5169 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5170 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5171 # endif | |
5172 else | |
5173 { | |
5174 static struct expgen | |
5175 { | |
5176 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5177 char_u *((*func)(expand_T *, int)); |
7 | 5178 int ic; |
2849 | 5179 int escaped; |
7 | 5180 } tab[] = |
5181 { | |
2849 | 5182 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5183 {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
|
5184 {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
|
5185 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5186 #ifdef FEAT_CMDHIST |
5187 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5188 #endif | |
7 | 5189 #ifdef FEAT_USR_CMDS |
2849 | 5190 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5191 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5192 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5193 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5194 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5195 #endif |
5196 #ifdef FEAT_EVAL | |
2849 | 5197 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5198 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5199 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5200 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5201 #endif |
5202 #ifdef FEAT_MENU | |
2849 | 5203 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5204 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5205 #endif |
5206 #ifdef FEAT_SYN_HL | |
2849 | 5207 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5208 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5209 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5210 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5211 #endif |
2849 | 5212 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5213 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5214 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5215 #ifdef FEAT_CSCOPE |
2849 | 5216 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5217 #endif |
1868 | 5218 #ifdef FEAT_SIGNS |
2849 | 5219 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5220 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5221 #ifdef FEAT_PROFILE |
2849 | 5222 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5223 #endif |
7 | 5224 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5225 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5226 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5227 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5228 #endif | |
5229 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5230 {EXPAND_USER, get_users, TRUE, FALSE}, |
13551
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5231 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5232 }; |
5233 int i; | |
5234 | |
5235 /* | |
5236 * Find a context in the table and call the ExpandGeneric() with the | |
5237 * right function to do the expansion. | |
5238 */ | |
5239 ret = FAIL; | |
1880 | 5240 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5241 if (xp->xp_context == tab[i].context) |
5242 { | |
5243 if (tab[i].ic) | |
5244 regmatch.rm_ic = TRUE; | |
2849 | 5245 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5246 tab[i].func, tab[i].escaped); |
7 | 5247 break; |
5248 } | |
5249 } | |
5250 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5251 vim_regfree(regmatch.regprog); |
7 | 5252 |
5253 return ret; | |
5254 #endif /* FEAT_CMDL_COMPL */ | |
5255 } | |
5256 | |
5257 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5258 /* | |
5259 * Expand a list of names. | |
5260 * | |
5261 * Generic function for command line completion. It calls a function to | |
5262 * obtain strings, one by one. The strings are matched against a regexp | |
5263 * program. Matching strings are copied into an array, which is returned. | |
5264 * | |
5265 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5266 */ | |
5267 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5268 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5269 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5270 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5271 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5272 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5273 char_u *((*func)(expand_T *, int)), |
7 | 5274 /* 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
|
5275 int escaped) |
7 | 5276 { |
5277 int i; | |
5278 int count = 0; | |
480 | 5279 int round; |
7 | 5280 char_u *str; |
5281 | |
5282 /* do this loop twice: | |
480 | 5283 * round == 0: count the number of matching names |
5284 * round == 1: copy the matching names into allocated memory | |
7 | 5285 */ |
480 | 5286 for (round = 0; round <= 1; ++round) |
7 | 5287 { |
5288 for (i = 0; ; ++i) | |
5289 { | |
5290 str = (*func)(xp, i); | |
5291 if (str == NULL) /* end of list */ | |
5292 break; | |
5293 if (*str == NUL) /* skip empty strings */ | |
5294 continue; | |
5295 | |
5296 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5297 { | |
480 | 5298 if (round) |
7 | 5299 { |
2849 | 5300 if (escaped) |
5301 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5302 else | |
5303 str = vim_strsave(str); | |
7 | 5304 (*file)[count] = str; |
5305 #ifdef FEAT_MENU | |
5306 if (func == get_menu_names && str != NULL) | |
5307 { | |
5308 /* test for separator added by get_menu_names() */ | |
5309 str += STRLEN(str) - 1; | |
5310 if (*str == '\001') | |
5311 *str = '.'; | |
5312 } | |
5313 #endif | |
5314 } | |
5315 ++count; | |
5316 } | |
5317 } | |
480 | 5318 if (round == 0) |
7 | 5319 { |
5320 if (count == 0) | |
5321 return OK; | |
5322 *num_file = count; | |
5323 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5324 if (*file == NULL) | |
5325 { | |
5326 *file = (char_u **)""; | |
5327 return FAIL; | |
5328 } | |
5329 count = 0; | |
5330 } | |
5331 } | |
480 | 5332 |
828 | 5333 /* Sort the results. Keep menu's in the specified order. */ |
5334 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5335 { |
5336 if (xp->xp_context == EXPAND_EXPRESSION | |
5337 || xp->xp_context == EXPAND_FUNCTIONS | |
5338 || xp->xp_context == EXPAND_USER_FUNC) | |
5339 /* <SNR> functions should be sorted to the end. */ | |
5340 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5341 sort_func_compare); | |
5342 else | |
5343 sort_strings(*file, *num_file); | |
5344 } | |
480 | 5345 |
1322 | 5346 #ifdef FEAT_CMDL_COMPL |
5347 /* Reset the variables used for special highlight names expansion, so that | |
5348 * they don't show up when getting normal highlight names by ID. */ | |
5349 reset_expand_highlight(); | |
5350 #endif | |
5351 | |
7 | 5352 return OK; |
5353 } | |
5354 | |
716 | 5355 /* |
5356 * Complete a shell command. | |
5357 * Returns FAIL or OK; | |
5358 */ | |
5359 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5360 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5361 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
|
5362 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
|
5363 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
|
5364 int flagsarg) /* EW_ flags */ |
716 | 5365 { |
5366 char_u *pat; | |
5367 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5368 char_u *path = NULL; |
716 | 5369 int mustfree = FALSE; |
5370 garray_T ga; | |
5371 char_u *buf = alloc(MAXPATHL); | |
5372 size_t l; | |
5373 char_u *s, *e; | |
5374 int flags = flagsarg; | |
5375 int ret; | |
6695 | 5376 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5377 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5378 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5379 hash_T hash; |
716 | 5380 |
5381 if (buf == NULL) | |
5382 return FAIL; | |
5383 | |
5384 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5385 * space */ | |
5386 pat = vim_strsave(filepat); | |
5387 for (i = 0; pat[i]; ++i) | |
5388 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5389 STRMOVE(pat + i, pat + i + 1); |
716 | 5390 |
6695 | 5391 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5392 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5393 if (pat[0] == '.' && (vim_ispathsep(pat[1]) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5394 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5395 path = (char_u *)"."; |
5396 else | |
2630 | 5397 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5398 /* For an absolute name we don't use $PATH. */ |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5399 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5400 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5401 if (path == NULL) |
5402 path = (char_u *)""; | |
5403 } | |
716 | 5404 |
5405 /* | |
5406 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5407 * collect them in "ga". When "." is not in $PATH also expand for the |
5408 * current directory, to find "subdir/cmd". | |
716 | 5409 */ |
5410 ga_init2(&ga, (int)sizeof(char *), 10); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5411 hash_init(&found_ht); |
6695 | 5412 for (s = path; ; s = e) |
716 | 5413 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5414 #if defined(MSWIN) |
716 | 5415 e = vim_strchr(s, ';'); |
5416 #else | |
5417 e = vim_strchr(s, ':'); | |
5418 #endif | |
5419 if (e == NULL) | |
5420 e = s + STRLEN(s); | |
5421 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5422 if (*s == NUL) |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5423 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5424 if (did_curdir) |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5425 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5426 // Find directories in the current directory, path is empty. |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5427 did_curdir = TRUE; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5428 flags |= EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5429 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5430 else if (STRNCMP(s, ".", (int)(e - s)) == 0) |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5431 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5432 did_curdir = TRUE; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5433 flags |= EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5434 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5435 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5436 // Do not match directories inside a $PATH item. |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5437 flags &= ~EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5438 |
716 | 5439 l = e - s; |
5440 if (l > MAXPATHL - 5) | |
5441 break; | |
5442 vim_strncpy(buf, s, l); | |
5443 add_pathsep(buf); | |
5444 l = STRLEN(buf); | |
5445 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5446 | |
5447 /* Expand matches in one directory of $PATH. */ | |
5448 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5449 if (ret == OK) | |
5450 { | |
5451 if (ga_grow(&ga, *num_file) == FAIL) | |
5452 FreeWild(*num_file, *file); | |
5453 else | |
5454 { | |
5455 for (i = 0; i < *num_file; ++i) | |
5456 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5457 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5458 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5459 if (STRLEN(name) > l) |
716 | 5460 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5461 // Check if this name was already found. |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5462 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5463 hi = hash_lookup(&found_ht, name + l, hash); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5464 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5465 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5466 // Remove the path that was prepended. |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5467 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5468 ((char_u **)ga.ga_data)[ga.ga_len++] = name; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5469 hash_add_item(&found_ht, hi, name, hash); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5470 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5471 } |
716 | 5472 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5473 vim_free(name); |
716 | 5474 } |
5475 vim_free(*file); | |
5476 } | |
5477 } | |
5478 if (*e != NUL) | |
5479 ++e; | |
5480 } | |
5481 *file = ga.ga_data; | |
5482 *num_file = ga.ga_len; | |
5483 | |
5484 vim_free(buf); | |
5485 vim_free(pat); | |
5486 if (mustfree) | |
5487 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5488 hash_clear(&found_ht); |
716 | 5489 return OK; |
5490 } | |
5491 | |
5492 | |
7 | 5493 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5494 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5495 * 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
|
5496 * return the result (either a string or a List). |
7 | 5497 */ |
407 | 5498 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5499 call_user_expand_func( |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5500 void *(*user_expand_func)(char_u *, int, typval_T *), |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5501 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5502 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5503 char_u ***file) |
7 | 5504 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5505 int keep = 0; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5506 typval_T args[4]; |
7 | 5507 int save_current_SID = current_SID; |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5508 char_u *pat = NULL; |
407 | 5509 void *ret; |
13 | 5510 struct cmdline_info save_ccline; |
7 | 5511 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5512 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5513 return NULL; |
7 | 5514 *num_file = 0; |
5515 *file = NULL; | |
5516 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5517 if (ccline.cmdbuff != NULL) |
1518 | 5518 { |
5519 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5520 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5521 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5522 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5523 pat = vim_strnsave(xp->xp_pattern, xp->xp_pattern_len); |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5524 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5525 args[0].v_type = VAR_STRING; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5526 args[0].vval.v_string = pat; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5527 args[1].v_type = VAR_STRING; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5528 args[1].vval.v_string = xp->xp_line; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5529 args[2].v_type = VAR_NUMBER; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5530 args[2].vval.v_number = xp->xp_col; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5531 args[3].v_type = VAR_UNKNOWN; |
7 | 5532 |
13 | 5533 /* Save the cmdline, we don't know what the function may do. */ |
5534 save_ccline = ccline; | |
5535 ccline.cmdbuff = NULL; | |
5536 ccline.cmdprompt = NULL; | |
7 | 5537 current_SID = xp->xp_scriptID; |
13 | 5538 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5539 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5540 |
5541 ccline = save_ccline; | |
7 | 5542 current_SID = save_current_SID; |
1518 | 5543 if (ccline.cmdbuff != NULL) |
5544 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5545 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5546 vim_free(pat); |
407 | 5547 return ret; |
5548 } | |
5549 | |
5550 /* | |
5551 * Expand names with a function defined by the user. | |
5552 */ | |
5553 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5554 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5555 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5556 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5557 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5558 char_u ***file) |
407 | 5559 { |
5560 char_u *retstr; | |
5561 char_u *s; | |
5562 char_u *e; | |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5563 int keep; |
407 | 5564 garray_T ga; |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5565 int skip; |
407 | 5566 |
5567 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5568 if (retstr == NULL) | |
7 | 5569 return FAIL; |
5570 | |
5571 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5572 for (s = retstr; *s != NUL; s = e) |
7 | 5573 { |
5574 e = vim_strchr(s, '\n'); | |
5575 if (e == NULL) | |
5576 e = s + STRLEN(s); | |
5577 keep = *e; | |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5578 *e = NUL; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5579 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5580 skip = xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5581 *e = keep; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5582 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5583 if (!skip) |
7 | 5584 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5585 if (ga_grow(&ga, 1) == FAIL) |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5586 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5587 ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, (int)(e - s)); |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5588 ++ga.ga_len; |
7 | 5589 } |
5590 | |
5591 if (*e != NUL) | |
5592 ++e; | |
5593 } | |
407 | 5594 vim_free(retstr); |
5595 *file = ga.ga_data; | |
5596 *num_file = ga.ga_len; | |
5597 return OK; | |
5598 } | |
5599 | |
5600 /* | |
5601 * Expand names with a list returned by a function defined by the user. | |
5602 */ | |
5603 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5604 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5605 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5606 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5607 char_u ***file) |
407 | 5608 { |
5609 list_T *retlist; | |
5610 listitem_T *li; | |
5611 garray_T ga; | |
5612 | |
5613 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5614 if (retlist == NULL) | |
5615 return FAIL; | |
5616 | |
5617 ga_init2(&ga, (int)sizeof(char *), 3); | |
5618 /* Loop over the items in the list. */ | |
5619 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5620 { | |
1917 | 5621 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5622 continue; /* Skip non-string items and empty strings */ | |
407 | 5623 |
5624 if (ga_grow(&ga, 1) == FAIL) | |
5625 break; | |
5626 | |
5627 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5628 vim_strsave(li->li_tv.vval.v_string); |
407 | 5629 ++ga.ga_len; |
5630 } | |
5631 list_unref(retlist); | |
5632 | |
7 | 5633 *file = ga.ga_data; |
5634 *num_file = ga.ga_len; | |
5635 return OK; | |
5636 } | |
5637 #endif | |
5638 | |
5639 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5640 * 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
|
5641 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5642 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5643 * 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
|
5644 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5645 * When "flags" has DIP_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
|
5646 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5647 * "dirnames" is an array with one or more directory names. |
7 | 5648 */ |
5649 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5650 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5651 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5652 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5653 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5654 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5655 char *dirnames[]) |
7 | 5656 { |
5657 char_u *s; | |
5658 char_u *e; | |
5873 | 5659 char_u *match; |
7 | 5660 garray_T ga; |
2929 | 5661 int i; |
5662 int pat_len; | |
7 | 5663 |
5664 *num_file = 0; | |
5665 *file = NULL; | |
2931 | 5666 pat_len = (int)STRLEN(pat); |
2929 | 5667 ga_init2(&ga, (int)sizeof(char *), 10); |
5668 | |
5669 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5670 { |
2929 | 5671 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5672 if (s == NULL) | |
5673 { | |
5674 ga_clear_strings(&ga); | |
5675 return FAIL; | |
5676 } | |
5677 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5678 globpath(p_rtp, s, &ga, 0); |
2929 | 5679 vim_free(s); |
5873 | 5680 } |
5681 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5682 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5683 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
|
5684 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5685 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
|
5686 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5687 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5688 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5689 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5690 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5691 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
|
5692 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5693 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5694 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5695 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5696 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5697 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5698 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
|
5699 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5700 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
|
5701 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5702 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5703 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5704 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5705 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5706 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
|
5707 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5708 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5709 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5710 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5711 |
5873 | 5712 for (i = 0; i < ga.ga_len; ++i) |
5713 { | |
5714 match = ((char_u **)ga.ga_data)[i]; | |
5715 s = match; | |
5716 e = s + STRLEN(s); | |
5717 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5718 { |
5873 | 5719 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5720 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5721 if (s < match || vim_ispathsep(*s)) |
5722 break; | |
5723 ++s; | |
5724 *e = NUL; | |
5725 mch_memmove(match, s, e - s + 1); | |
7 | 5726 } |
5727 } | |
5873 | 5728 |
2929 | 5729 if (ga.ga_len == 0) |
3628 | 5730 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5731 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5732 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5733 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5734 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5735 |
7 | 5736 *file = ga.ga_data; |
5737 *num_file = ga.ga_len; | |
5738 return OK; | |
5739 } | |
5740 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5741 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5742 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5743 * 'packpath'/pack/ * /opt/{pat} |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5744 */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5745 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5746 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5747 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5748 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5749 char_u ***file) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5750 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5751 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5752 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5753 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5754 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5755 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5756 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5757 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5758 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5759 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5760 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5761 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
|
5762 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5763 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5764 if (s == NULL) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5765 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5766 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5767 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5768 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5769 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
|
5770 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5771 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5772 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5773 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
|
5774 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5775 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
|
5776 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5777 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5778 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
|
5779 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5780 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5781 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5782 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5783 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5784 /* 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
|
5785 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5786 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5787 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5788 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5789 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5790 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5791 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5792 |
7 | 5793 #endif |
5794 | |
5795 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5796 /* | |
5797 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5798 * Adds the matches to "ga". Caller must init "ga". |
7 | 5799 */ |
5873 | 5800 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5801 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5802 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5803 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5804 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5805 int expand_options) |
7 | 5806 { |
5807 expand_T xpc; | |
5808 char_u *buf; | |
5809 int i; | |
5810 int num_p; | |
5811 char_u **p; | |
5812 | |
5813 buf = alloc(MAXPATHL); | |
5814 if (buf == NULL) | |
5873 | 5815 return; |
7 | 5816 |
632 | 5817 ExpandInit(&xpc); |
7 | 5818 xpc.xp_context = EXPAND_FILES; |
632 | 5819 |
7 | 5820 /* Loop over all entries in {path}. */ |
5821 while (*path != NUL) | |
5822 { | |
5823 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5824 copy_option_part(&path, buf, MAXPATHL, ","); | |
5825 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5826 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5827 # 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
|
5828 /* 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
|
5829 * 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
|
5830 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
|
5831 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5832 # else |
7 | 5833 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
|
5834 # endif |
7 | 5835 STRCAT(buf, file); |
1754 | 5836 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5837 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5838 { |
1754 | 5839 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5840 |
5841 if (ga_grow(ga, num_p) == OK) | |
7 | 5842 { |
5843 for (i = 0; i < num_p; ++i) | |
5844 { | |
5873 | 5845 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5846 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5847 ++ga->ga_len; |
7 | 5848 } |
5849 } | |
5873 | 5850 |
7 | 5851 FreeWild(num_p, p); |
5852 } | |
5853 } | |
5854 } | |
5855 | |
5856 vim_free(buf); | |
5857 } | |
5858 | |
5859 #endif | |
5860 | |
5861 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5862 | |
5863 /********************************* | |
5864 * Command line history stuff * | |
5865 *********************************/ | |
5866 | |
5867 /* | |
5868 * Translate a history character to the associated type number. | |
5869 */ | |
5870 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5871 hist_char2type(int c) |
7 | 5872 { |
5873 if (c == ':') | |
5874 return HIST_CMD; | |
5875 if (c == '=') | |
5876 return HIST_EXPR; | |
5877 if (c == '@') | |
5878 return HIST_INPUT; | |
5879 if (c == '>') | |
5880 return HIST_DEBUG; | |
5881 return HIST_SEARCH; /* must be '?' or '/' */ | |
5882 } | |
5883 | |
5884 /* | |
5885 * Table of history names. | |
5886 * These names are used in :history and various hist...() functions. | |
5887 * It is sufficient to give the significant prefix of a history name. | |
5888 */ | |
5889 | |
5890 static char *(history_names[]) = | |
5891 { | |
5892 "cmd", | |
5893 "search", | |
5894 "expr", | |
5895 "input", | |
5896 "debug", | |
5897 NULL | |
5898 }; | |
5899 | |
3503 | 5900 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5901 /* | |
5902 * Function given to ExpandGeneric() to obtain the possible first | |
5903 * arguments of the ":history command. | |
5904 */ | |
5905 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5906 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5907 { |
5908 static char_u compl[2] = { NUL, NUL }; | |
5909 char *short_names = ":=@>?/"; | |
3529 | 5910 int short_names_count = (int)STRLEN(short_names); |
3503 | 5911 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5912 | |
5913 if (idx < short_names_count) | |
5914 { | |
5915 compl[0] = (char_u)short_names[idx]; | |
5916 return compl; | |
5917 } | |
5918 if (idx < short_names_count + history_name_count) | |
5919 return (char_u *)history_names[idx - short_names_count]; | |
5920 if (idx == short_names_count + history_name_count) | |
5921 return (char_u *)"all"; | |
5922 return NULL; | |
5923 } | |
5924 #endif | |
5925 | |
7 | 5926 /* |
5927 * init_history() - Initialize the command line history. | |
5928 * Also used to re-allocate the history when the size changes. | |
5929 */ | |
356 | 5930 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5931 init_history(void) |
7 | 5932 { |
5933 int newlen; /* new length of history table */ | |
5934 histentry_T *temp; | |
5935 int i; | |
5936 int j; | |
5937 int type; | |
5938 | |
5939 /* | |
5940 * If size of history table changed, reallocate it | |
5941 */ | |
5942 newlen = (int)p_hi; | |
5943 if (newlen != hislen) /* history length changed */ | |
5944 { | |
5945 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
5946 { | |
5947 if (newlen) | |
5948 { | |
5949 temp = (histentry_T *)lalloc( | |
5950 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
5951 if (temp == NULL) /* out of memory! */ | |
5952 { | |
5953 if (type == 0) /* first one: just keep the old length */ | |
5954 { | |
5955 newlen = hislen; | |
5956 break; | |
5957 } | |
5958 /* Already changed one table, now we can only have zero | |
5959 * length for all tables. */ | |
5960 newlen = 0; | |
5961 type = -1; | |
5962 continue; | |
5963 } | |
5964 } | |
5965 else | |
5966 temp = NULL; | |
5967 if (newlen == 0 || temp != NULL) | |
5968 { | |
5969 if (hisidx[type] < 0) /* there are no entries yet */ | |
5970 { | |
5971 for (i = 0; i < newlen; ++i) | |
4258 | 5972 clear_hist_entry(&temp[i]); |
7 | 5973 } |
5974 else if (newlen > hislen) /* array becomes bigger */ | |
5975 { | |
5976 for (i = 0; i <= hisidx[type]; ++i) | |
5977 temp[i] = history[type][i]; | |
5978 j = i; | |
5979 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 5980 clear_hist_entry(&temp[i]); |
7 | 5981 for ( ; j < hislen; ++i, ++j) |
5982 temp[i] = history[type][j]; | |
5983 } | |
5984 else /* array becomes smaller or 0 */ | |
5985 { | |
5986 j = hisidx[type]; | |
5987 for (i = newlen - 1; ; --i) | |
5988 { | |
5989 if (i >= 0) /* copy newest entries */ | |
5990 temp[i] = history[type][j]; | |
5991 else /* remove older entries */ | |
5992 vim_free(history[type][j].hisstr); | |
5993 if (--j < 0) | |
5994 j = hislen - 1; | |
5995 if (j == hisidx[type]) | |
5996 break; | |
5997 } | |
5998 hisidx[type] = newlen - 1; | |
5999 } | |
6000 vim_free(history[type]); | |
6001 history[type] = temp; | |
6002 } | |
6003 } | |
6004 hislen = newlen; | |
6005 } | |
6006 } | |
6007 | |
4258 | 6008 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6009 clear_hist_entry(histentry_T *hisptr) |
4258 | 6010 { |
6011 hisptr->hisnum = 0; | |
6012 hisptr->viminfo = FALSE; | |
6013 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6014 hisptr->time_set = 0; |
4258 | 6015 } |
6016 | |
7 | 6017 /* |
6018 * Check if command line 'str' is already in history. | |
6019 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6020 */ | |
6021 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6022 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6023 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6024 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6025 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
|
6026 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6027 int writing) /* ignore entries read from viminfo */ |
7 | 6028 { |
6029 int i; | |
6030 int last_i = -1; | |
2986 | 6031 char_u *p; |
7 | 6032 |
6033 if (hisidx[type] < 0) | |
6034 return FALSE; | |
6035 i = hisidx[type]; | |
6036 do | |
6037 { | |
6038 if (history[type][i].hisstr == NULL) | |
6039 return FALSE; | |
2986 | 6040 |
6041 /* For search history, check that the separator character matches as | |
6042 * well. */ | |
6043 p = history[type][i].hisstr; | |
6044 if (STRCMP(str, p) == 0 | |
4285 | 6045 && !(writing && history[type][i].viminfo) |
2986 | 6046 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6047 { |
6048 if (!move_to_front) | |
6049 return TRUE; | |
6050 last_i = i; | |
6051 break; | |
6052 } | |
6053 if (--i < 0) | |
6054 i = hislen - 1; | |
6055 } while (i != hisidx[type]); | |
6056 | |
6057 if (last_i >= 0) | |
6058 { | |
6059 str = history[type][i].hisstr; | |
6060 while (i != hisidx[type]) | |
6061 { | |
6062 if (++i >= hislen) | |
6063 i = 0; | |
6064 history[type][last_i] = history[type][i]; | |
6065 last_i = i; | |
6066 } | |
4258 | 6067 history[type][i].hisnum = ++hisnum[type]; |
6068 history[type][i].viminfo = FALSE; | |
7 | 6069 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6070 history[type][i].time_set = vim_time(); |
7 | 6071 return TRUE; |
6072 } | |
6073 return FALSE; | |
6074 } | |
6075 | |
6076 /* | |
6077 * Convert history name (from table above) to its HIST_ equivalent. | |
6078 * When "name" is empty, return "cmd" history. | |
6079 * Returns -1 for unknown history name. | |
6080 */ | |
6081 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6082 get_histtype(char_u *name) |
7 | 6083 { |
6084 int i; | |
6085 int len = (int)STRLEN(name); | |
6086 | |
6087 /* No argument: use current history. */ | |
6088 if (len == 0) | |
6089 return hist_char2type(ccline.cmdfirstc); | |
6090 | |
6091 for (i = 0; history_names[i] != NULL; ++i) | |
6092 if (STRNICMP(name, history_names[i], len) == 0) | |
6093 return i; | |
6094 | |
6095 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6096 return hist_char2type(name[0]); | |
6097 | |
6098 return -1; | |
6099 } | |
6100 | |
6101 static int last_maptick = -1; /* last seen maptick */ | |
6102 | |
6103 /* | |
6104 * Add the given string to the given history. If the string is already in the | |
6105 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6106 * values. | |
6107 */ | |
6108 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6109 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6110 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6111 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6112 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
|
6113 int sep) /* separator character used (search hist) */ |
7 | 6114 { |
6115 histentry_T *hisptr; | |
6116 int len; | |
6117 | |
6118 if (hislen == 0) /* no history */ | |
6119 return; | |
6120 | |
5467 | 6121 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6122 return; | |
6123 | |
7 | 6124 /* |
6125 * Searches inside the same mapping overwrite each other, so that only | |
6126 * the last line is kept. Be careful not to remove a line that was moved | |
6127 * down, only lines that were added. | |
6128 */ | |
6129 if (histype == HIST_SEARCH && in_map) | |
6130 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6131 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6132 { |
6133 /* Current line is from the same mapping, remove it */ | |
6134 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6135 vim_free(hisptr->hisstr); | |
4258 | 6136 clear_hist_entry(hisptr); |
7 | 6137 --hisnum[histype]; |
6138 if (--hisidx[HIST_SEARCH] < 0) | |
6139 hisidx[HIST_SEARCH] = hislen - 1; | |
6140 } | |
6141 last_maptick = -1; | |
6142 } | |
4285 | 6143 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6144 { |
6145 if (++hisidx[histype] == hislen) | |
6146 hisidx[histype] = 0; | |
6147 hisptr = &history[histype][hisidx[histype]]; | |
6148 vim_free(hisptr->hisstr); | |
6149 | |
6150 /* Store the separator after the NUL of the string. */ | |
835 | 6151 len = (int)STRLEN(new_entry); |
7 | 6152 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6153 if (hisptr->hisstr != NULL) | |
6154 hisptr->hisstr[len + 1] = sep; | |
6155 | |
6156 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6157 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6158 hisptr->time_set = vim_time(); |
7 | 6159 if (histype == HIST_SEARCH && in_map) |
6160 last_maptick = maptick; | |
6161 } | |
6162 } | |
6163 | |
6164 #if defined(FEAT_EVAL) || defined(PROTO) | |
6165 | |
6166 /* | |
6167 * Get identifier of newest history entry. | |
6168 * "histype" may be one of the HIST_ values. | |
6169 */ | |
6170 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6171 get_history_idx(int histype) |
7 | 6172 { |
6173 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6174 || hisidx[histype] < 0) | |
6175 return -1; | |
6176 | |
6177 return history[histype][hisidx[histype]].hisnum; | |
6178 } | |
6179 | |
531 | 6180 /* |
7 | 6181 * Calculate history index from a number: |
6182 * num > 0: seen as identifying number of a history entry | |
6183 * num < 0: relative position in history wrt newest entry | |
6184 * "histype" may be one of the HIST_ values. | |
6185 */ | |
6186 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6187 calc_hist_idx(int histype, int num) |
7 | 6188 { |
6189 int i; | |
6190 histentry_T *hist; | |
6191 int wrapped = FALSE; | |
6192 | |
6193 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6194 || (i = hisidx[histype]) < 0 || num == 0) | |
6195 return -1; | |
6196 | |
6197 hist = history[histype]; | |
6198 if (num > 0) | |
6199 { | |
6200 while (hist[i].hisnum > num) | |
6201 if (--i < 0) | |
6202 { | |
6203 if (wrapped) | |
6204 break; | |
6205 i += hislen; | |
6206 wrapped = TRUE; | |
6207 } | |
6208 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6209 return i; | |
6210 } | |
6211 else if (-num <= hislen) | |
6212 { | |
6213 i += num + 1; | |
6214 if (i < 0) | |
6215 i += hislen; | |
6216 if (hist[i].hisstr != NULL) | |
6217 return i; | |
6218 } | |
6219 return -1; | |
6220 } | |
6221 | |
6222 /* | |
6223 * Get a history entry by its index. | |
6224 * "histype" may be one of the HIST_ values. | |
6225 */ | |
6226 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6227 get_history_entry(int histype, int idx) |
7 | 6228 { |
6229 idx = calc_hist_idx(histype, idx); | |
6230 if (idx >= 0) | |
6231 return history[histype][idx].hisstr; | |
6232 else | |
6233 return (char_u *)""; | |
6234 } | |
6235 | |
6236 /* | |
6237 * Clear all entries of a history. | |
6238 * "histype" may be one of the HIST_ values. | |
6239 */ | |
6240 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6241 clr_history(int histype) |
7 | 6242 { |
6243 int i; | |
6244 histentry_T *hisptr; | |
6245 | |
6246 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6247 { | |
6248 hisptr = history[histype]; | |
6249 for (i = hislen; i--;) | |
6250 { | |
6251 vim_free(hisptr->hisstr); | |
4258 | 6252 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6253 hisptr++; |
7 | 6254 } |
6255 hisidx[histype] = -1; /* mark history as cleared */ | |
6256 hisnum[histype] = 0; /* reset identifier counter */ | |
6257 return OK; | |
6258 } | |
6259 return FAIL; | |
6260 } | |
6261 | |
6262 /* | |
6263 * Remove all entries matching {str} from a history. | |
6264 * "histype" may be one of the HIST_ values. | |
6265 */ | |
6266 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6267 del_history_entry(int histype, char_u *str) |
7 | 6268 { |
6269 regmatch_T regmatch; | |
6270 histentry_T *hisptr; | |
6271 int idx; | |
6272 int i; | |
6273 int last; | |
6274 int found = FALSE; | |
6275 | |
6276 regmatch.regprog = NULL; | |
6277 regmatch.rm_ic = FALSE; /* always match case */ | |
6278 if (hislen != 0 | |
6279 && histype >= 0 | |
6280 && histype < HIST_COUNT | |
6281 && *str != NUL | |
6282 && (idx = hisidx[histype]) >= 0 | |
6283 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6284 != NULL) | |
6285 { | |
6286 i = last = idx; | |
6287 do | |
6288 { | |
6289 hisptr = &history[histype][i]; | |
6290 if (hisptr->hisstr == NULL) | |
6291 break; | |
6292 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6293 { | |
6294 found = TRUE; | |
6295 vim_free(hisptr->hisstr); | |
4258 | 6296 clear_hist_entry(hisptr); |
7 | 6297 } |
6298 else | |
6299 { | |
6300 if (i != last) | |
6301 { | |
6302 history[histype][last] = *hisptr; | |
4258 | 6303 clear_hist_entry(hisptr); |
7 | 6304 } |
6305 if (--last < 0) | |
6306 last += hislen; | |
6307 } | |
6308 if (--i < 0) | |
6309 i += hislen; | |
6310 } while (i != idx); | |
6311 if (history[histype][idx].hisstr == NULL) | |
6312 hisidx[histype] = -1; | |
6313 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6314 vim_regfree(regmatch.regprog); |
7 | 6315 return found; |
6316 } | |
6317 | |
6318 /* | |
6319 * Remove an indexed entry from a history. | |
6320 * "histype" may be one of the HIST_ values. | |
6321 */ | |
6322 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6323 del_history_idx(int histype, int idx) |
7 | 6324 { |
6325 int i, j; | |
6326 | |
6327 i = calc_hist_idx(histype, idx); | |
6328 if (i < 0) | |
6329 return FALSE; | |
6330 idx = hisidx[histype]; | |
6331 vim_free(history[histype][i].hisstr); | |
6332 | |
6333 /* When deleting the last added search string in a mapping, reset | |
6334 * last_maptick, so that the last added search string isn't deleted again. | |
6335 */ | |
6336 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6337 last_maptick = -1; | |
6338 | |
6339 while (i != idx) | |
6340 { | |
6341 j = (i + 1) % hislen; | |
6342 history[histype][i] = history[histype][j]; | |
6343 i = j; | |
6344 } | |
4258 | 6345 clear_hist_entry(&history[histype][i]); |
7 | 6346 if (--i < 0) |
6347 i += hislen; | |
6348 hisidx[histype] = i; | |
6349 return TRUE; | |
6350 } | |
6351 | |
6352 #endif /* FEAT_EVAL */ | |
6353 | |
6354 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6355 /* | |
6356 * Very specific function to remove the value in ":set key=val" from the | |
6357 * history. | |
6358 */ | |
6359 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6360 remove_key_from_history(void) |
7 | 6361 { |
6362 char_u *p; | |
6363 int i; | |
6364 | |
6365 i = hisidx[HIST_CMD]; | |
6366 if (i < 0) | |
6367 return; | |
6368 p = history[HIST_CMD][i].hisstr; | |
6369 if (p != NULL) | |
6370 for ( ; *p; ++p) | |
6371 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6372 { | |
6373 p = vim_strchr(p + 3, '='); | |
6374 if (p == NULL) | |
6375 break; | |
6376 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6377 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6378 if (p[i] == '\\' && p[i + 1]) |
6379 ++i; | |
1621 | 6380 STRMOVE(p, p + i); |
7 | 6381 --p; |
6382 } | |
6383 } | |
6384 #endif | |
6385 | |
6386 #endif /* FEAT_CMDHIST */ | |
6387 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6388 #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
|
6389 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6390 * 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
|
6391 * 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
|
6392 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6393 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6394 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6395 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6396 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6397 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6398 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6399 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6400 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
|
6401 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6402 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6403 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6404 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6405 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6406 #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
|
6407 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6408 * 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
|
6409 * 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
|
6410 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6411 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6412 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6413 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6414 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6415 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
|
6416 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6417 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6418 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6419 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
|
6420 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6421 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6422 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6423 * 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
|
6424 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6425 * 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
|
6426 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6427 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6428 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6429 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6430 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6431 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
|
6432 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6433 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6434 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6435 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6436 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6437 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6438 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6439 * 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
|
6440 * 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
|
6441 * 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
|
6442 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6443 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6444 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6445 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6446 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6447 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
|
6448 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6449 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6450 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6451 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6452 /* 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
|
6453 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6454 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6455 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6456 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6457 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6458 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6459 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6460 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6461 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6462 #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
|
6463 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6464 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6465 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6466 * 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
|
6467 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6468 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6469 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6470 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6471 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6472 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
|
6473 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6474 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6475 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6476 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6477 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6478 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6479 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6480 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6481 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6482 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6483 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6484 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6485 |
7 | 6486 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6487 /* | |
6488 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6489 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6490 * Returns OK if parsed successfully, otherwise FAIL. | |
6491 */ | |
6492 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6493 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6494 { |
6495 int len; | |
6496 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6497 varnumber_T num; |
7 | 6498 |
6499 *str = skipwhite(*str); | |
6500 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6501 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6502 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6503 *str += len; |
6504 *num1 = (int)num; | |
6505 first = TRUE; | |
6506 } | |
6507 *str = skipwhite(*str); | |
6508 if (**str == ',') /* parse "to" part of range */ | |
6509 { | |
6510 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6511 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6512 if (len > 0) |
6513 { | |
6514 *num2 = (int)num; | |
6515 *str = skipwhite(*str + len); | |
6516 } | |
6517 else if (!first) /* no number given at all */ | |
6518 return FAIL; | |
6519 } | |
6520 else if (first) /* only one number given */ | |
6521 *num2 = *num1; | |
6522 return OK; | |
6523 } | |
6524 #endif | |
6525 | |
6526 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6527 /* | |
6528 * :history command - print a history | |
6529 */ | |
6530 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6531 ex_history(exarg_T *eap) |
7 | 6532 { |
6533 histentry_T *hist; | |
6534 int histype1 = HIST_CMD; | |
6535 int histype2 = HIST_CMD; | |
6536 int hisidx1 = 1; | |
6537 int hisidx2 = -1; | |
6538 int idx; | |
6539 int i, j, k; | |
6540 char_u *end; | |
6541 char_u *arg = eap->arg; | |
6542 | |
6543 if (hislen == 0) | |
6544 { | |
6545 MSG(_("'history' option is zero")); | |
6546 return; | |
6547 } | |
6548 | |
6549 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6550 { | |
6551 end = arg; | |
6552 while (ASCII_ISALPHA(*end) | |
6553 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6554 end++; | |
6555 i = *end; | |
6556 *end = NUL; | |
6557 histype1 = get_histtype(arg); | |
6558 if (histype1 == -1) | |
6559 { | |
1853 | 6560 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6561 { |
6562 histype1 = 0; | |
6563 histype2 = HIST_COUNT-1; | |
6564 } | |
6565 else | |
6566 { | |
6567 *end = i; | |
6568 EMSG(_(e_trailing)); | |
6569 return; | |
6570 } | |
6571 } | |
6572 else | |
6573 histype2 = histype1; | |
6574 *end = i; | |
6575 } | |
6576 else | |
6577 end = arg; | |
6578 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6579 { | |
6580 EMSG(_(e_trailing)); | |
6581 return; | |
6582 } | |
6583 | |
6584 for (; !got_int && histype1 <= histype2; ++histype1) | |
6585 { | |
6586 STRCPY(IObuff, "\n # "); | |
6587 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6588 MSG_PUTS_TITLE(IObuff); | |
6589 idx = hisidx[histype1]; | |
6590 hist = history[histype1]; | |
6591 j = hisidx1; | |
6592 k = hisidx2; | |
6593 if (j < 0) | |
6594 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6595 if (k < 0) | |
6596 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6597 if (idx >= 0 && j <= k) | |
6598 for (i = idx + 1; !got_int; ++i) | |
6599 { | |
6600 if (i == hislen) | |
6601 i = 0; | |
6602 if (hist[i].hisstr != NULL | |
6603 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6604 { | |
6605 msg_putchar('\n'); | |
6606 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6607 hist[i].hisnum); | |
6608 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6609 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6610 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6611 else |
6612 STRCAT(IObuff, hist[i].hisstr); | |
6613 msg_outtrans(IObuff); | |
6614 out_flush(); | |
6615 } | |
6616 if (i == idx) | |
6617 break; | |
6618 } | |
6619 } | |
6620 } | |
6621 #endif | |
6622 | |
6623 #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
|
6624 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6625 * 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
|
6626 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6627 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
|
6628 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6629 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
|
6630 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6631 static int viminfo_add_at_front = FALSE; |
6632 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6633 static int hist_type2char(int type, int use_question); |
7 | 6634 |
6635 /* | |
6636 * Translate a history type number to the associated character. | |
6637 */ | |
6638 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6639 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6640 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6641 int use_question) /* use '?' instead of '/' */ |
7 | 6642 { |
6643 if (type == HIST_CMD) | |
6644 return ':'; | |
6645 if (type == HIST_SEARCH) | |
6646 { | |
6647 if (use_question) | |
6648 return '?'; | |
6649 else | |
6650 return '/'; | |
6651 } | |
6652 if (type == HIST_EXPR) | |
6653 return '='; | |
6654 return '@'; | |
6655 } | |
6656 | |
6657 /* | |
6658 * Prepare for reading the history from the viminfo file. | |
6659 * This allocates history arrays to store the read history lines. | |
6660 */ | |
6661 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6662 prepare_viminfo_history(int asklen, int writing) |
7 | 6663 { |
6664 int i; | |
6665 int num; | |
6666 int type; | |
6667 int len; | |
6668 | |
6669 init_history(); | |
4285 | 6670 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6671 if (asklen > hislen) |
6672 asklen = hislen; | |
6673 | |
6674 for (type = 0; type < HIST_COUNT; ++type) | |
6675 { | |
4258 | 6676 /* Count the number of empty spaces in the history list. Entries read |
6677 * from viminfo previously are also considered empty. If there are | |
6678 * more spaces available than we request, then fill them up. */ | |
7 | 6679 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6680 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6681 num++; |
6682 len = asklen; | |
6683 if (num > len) | |
6684 len = num; | |
6685 if (len <= 0) | |
6686 viminfo_history[type] = NULL; | |
6687 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6688 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6689 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6690 if (viminfo_history[type] == NULL) |
6691 len = 0; | |
6692 viminfo_hislen[type] = len; | |
6693 viminfo_hisidx[type] = 0; | |
6694 } | |
6695 } | |
6696 | |
6697 /* | |
6698 * Accept a line from the viminfo, store it in the history array when it's | |
6699 * new. | |
6700 */ | |
6701 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6702 read_viminfo_history(vir_T *virp, int writing) |
7 | 6703 { |
6704 int type; | |
6705 long_u len; | |
6706 char_u *val; | |
6707 char_u *p; | |
6708 | |
6709 type = hist_char2type(virp->vir_line[0]); | |
6710 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6711 { | |
6712 val = viminfo_readstring(virp, 1, TRUE); | |
6713 if (val != NULL && *val != NUL) | |
6714 { | |
3316 | 6715 int sep = (*val == ' ' ? NUL : *val); |
6716 | |
7 | 6717 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6718 viminfo_add_at_front, sep, writing)) |
7 | 6719 { |
6720 /* Need to re-allocate to append the separator byte. */ | |
6721 len = STRLEN(val); | |
6722 p = lalloc(len + 2, TRUE); | |
6723 if (p != NULL) | |
6724 { | |
6725 if (type == HIST_SEARCH) | |
6726 { | |
6727 /* Search entry: Move the separator from the first | |
6728 * column to after the NUL. */ | |
6729 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6730 p[len] = sep; |
7 | 6731 } |
6732 else | |
6733 { | |
6734 /* Not a search entry: No separator in the viminfo | |
6735 * file, add a NUL separator. */ | |
6736 mch_memmove(p, val, (size_t)len + 1); | |
6737 p[len + 1] = NUL; | |
6738 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6739 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
|
6740 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
|
6741 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
|
6742 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
|
6743 viminfo_hisidx[type]++; |
7 | 6744 } |
6745 } | |
6746 } | |
6747 vim_free(val); | |
6748 } | |
6749 return viminfo_readline(virp); | |
6750 } | |
6751 | |
4285 | 6752 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6753 * 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
|
6754 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6755 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6756 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6757 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6758 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6759 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6760 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6761 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6762 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6763 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6764 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6765 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
|
6766 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6767 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6768 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6769 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6770 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6771 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6772 || (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
|
6773 || 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
|
6774 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6775 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6776 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6777 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6778 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6779 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
|
6780 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6781 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6782 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6783 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6784 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
|
6785 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6786 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6787 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6788 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6789 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
|
6790 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6791 /* 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
|
6792 * 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
|
6793 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
|
6794 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6795 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6796 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6797 && (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
|
6798 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6799 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6800 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6801 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6802 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6803 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6804 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6805 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6806 /* 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
|
6807 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6808 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6809 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6810 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6811 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6812 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6813 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6814 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
|
6815 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6816 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6817 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
|
6818 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6819 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6820 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
|
6821 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6822 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
|
6823 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6824 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6825 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6826 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6827 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6828 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6829 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6830 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6831 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6832 * 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
|
6833 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6834 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6835 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6836 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6837 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6838 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6839 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6840 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6841 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6842 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6843 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6844 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6845 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6846 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6847 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6848 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6849 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6850 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6851 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6852 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6853 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6854 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6855 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6856 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6857 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6858 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6859 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6860 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6861 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6862 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
|
6863 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6864 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6865 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
|
6866 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6867 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
|
6868 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6869 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6870 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6871 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6872 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6873 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
|
6874 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6875 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6876 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6877 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6878 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6879 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6880 #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
|
6881 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6882 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6883 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6884 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6885 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
|
6886 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6887 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6888 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6889 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6890 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
|
6891 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
|
6892 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6893 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6894 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6895 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6896 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6897 * 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
|
6898 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6899 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6900 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6901 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6902 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6903 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6904 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6907 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6908 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6909 /* 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
|
6910 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6911 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
|
6912 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
|
6913 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
|
6914 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6915 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6916 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 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
|
6920 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
|
6921 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6922 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6923 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 tot_hist[len++] = &history[type][i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6925 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6926 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 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
|
6928 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6929 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6930 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6933 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6934 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6935 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6936 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6937 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6938 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6939 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6940 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6942 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
|
6943 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6944 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6945 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
|
6946 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
|
6947 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6948 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6949 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6950 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
6951 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6952 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6953 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6954 /* |
4285 | 6955 * Finish reading history lines from viminfo. Not used when writing viminfo. |
6956 */ | |
7 | 6957 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6958 finish_viminfo_history(vir_T *virp) |
7 | 6959 { |
6960 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6961 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 6962 |
6963 for (type = 0; type < HIST_COUNT; ++type) | |
6964 { | |
6965 if (history[type] == NULL) | |
4283 | 6966 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6967 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6968 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6969 merge_history(type); |
7 | 6970 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6971 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6972 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
6973 VIM_CLEAR(viminfo_history[type]); |
4327 | 6974 viminfo_hisidx[type] = 0; |
7 | 6975 } |
6976 } | |
6977 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6978 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6979 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6980 * 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
|
6981 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6982 * 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
|
6983 */ |
7 | 6984 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6985 write_viminfo_history(FILE *fp, int merge) |
7 | 6986 { |
6987 int i; | |
6988 int type; | |
6989 int num_saved; | |
4283 | 6990 int round; |
7 | 6991 |
6992 init_history(); | |
6993 if (hislen == 0) | |
6994 return; | |
6995 for (type = 0; type < HIST_COUNT; ++type) | |
6996 { | |
6997 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
6998 if (num_saved == 0) | |
6999 continue; | |
7000 if (num_saved < 0) /* Use default */ | |
7001 num_saved = hislen; | |
7002 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
7003 type == HIST_CMD ? _("Command Line") : | |
7004 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7005 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7006 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7007 _("Debug Line")); |
7 | 7008 if (num_saved > hislen) |
7009 num_saved = hislen; | |
4283 | 7010 |
7011 /* | |
7012 * Merge typed and viminfo history: | |
7013 * round 1: history of typed commands. | |
7014 * round 2: history from recently read viminfo. | |
7015 */ | |
7016 for (round = 1; round <= 2; ++round) | |
7017 { | |
4307 | 7018 if (round == 1) |
7019 /* start at newest entry, somewhere in the list */ | |
7020 i = hisidx[type]; | |
7021 else if (viminfo_hisidx[type] > 0) | |
7022 /* start at newest entry, first in the list */ | |
7023 i = 0; | |
7024 else | |
7025 /* empty list */ | |
7026 i = -1; | |
4283 | 7027 if (i >= 0) |
7028 while (num_saved > 0 | |
7029 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7030 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7031 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7032 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7033 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7034 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7035 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7036 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7037 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7038 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7039 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7040 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7041 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7042 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7043 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7044 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7045 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7046 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7047 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7048 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7049 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7050 || !history[type][i].viminfo)) |
7 | 7051 { |
4283 | 7052 --num_saved; |
7053 fputc(hist_type2char(type, TRUE), fp); | |
7054 /* For the search history: put the separator in the | |
7055 * second column; use a space if there isn't one. */ | |
7056 if (type == HIST_SEARCH) | |
7057 { | |
7058 c = p[STRLEN(p) + 1]; | |
7059 putc(c == NUL ? ' ' : c, fp); | |
7060 } | |
7061 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7062 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7063 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7064 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7065 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7066 /* 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
|
7067 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7068 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7069 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7070 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7071 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7072 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
|
7073 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7074 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7075 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7076 } |
7 | 7077 } |
4283 | 7078 if (round == 1) |
7079 { | |
7080 /* Decrement index, loop around and stop when back at | |
7081 * the start. */ | |
7082 if (--i < 0) | |
7083 i = hislen - 1; | |
7084 if (i == hisidx[type]) | |
7085 break; | |
7086 } | |
7087 else | |
7088 { | |
7089 /* Increment index. Stop at the end in the while. */ | |
7090 ++i; | |
7091 } | |
7 | 7092 } |
4283 | 7093 } |
4285 | 7094 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7095 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7096 vim_free(viminfo_history[type][i].hisstr); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
7097 VIM_CLEAR(viminfo_history[type]); |
4311 | 7098 viminfo_hisidx[type] = 0; |
7 | 7099 } |
7100 } | |
7101 #endif /* FEAT_VIMINFO */ | |
7102 | |
7103 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7104 /* | |
7105 * Write a character at the current cursor+offset position. | |
7106 * It is directly written into the command buffer block. | |
7107 */ | |
7108 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7109 cmd_pchar(int c, int offset) |
7 | 7110 { |
7111 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7112 { | |
7113 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7114 return; | |
7115 } | |
7116 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7117 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7118 } | |
7119 | |
7120 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7121 cmd_gchar(int offset) |
7 | 7122 { |
7123 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7124 { | |
7125 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7126 return NUL; | |
7127 } | |
7128 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7129 } | |
7130 #endif | |
7131 | |
7132 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7133 /* | |
7134 * Open a window on the current command line and history. Allow editing in | |
7135 * the window. Returns when the window is closed. | |
7136 * Returns: | |
7137 * CR if the command is to be executed | |
7138 * Ctrl_C if it is to be abandoned | |
7139 * K_IGNORE if editing continues | |
7140 */ | |
7141 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
|
7142 open_cmdwin(void) |
7 | 7143 { |
7144 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7145 bufref_T old_curbuf; |
7 | 7146 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7147 bufref_T bufref; |
7 | 7148 win_T *wp; |
7149 int i; | |
7150 linenr_T lnum; | |
7151 int histtype; | |
7152 garray_T winsizes; | |
7153 int save_restart_edit = restart_edit; | |
7154 int save_State = State; | |
7155 int save_exmode = exmode_active; | |
510 | 7156 #ifdef FEAT_RIGHTLEFT |
7157 int save_cmdmsg_rl = cmdmsg_rl; | |
7158 #endif | |
6145 | 7159 #ifdef FEAT_FOLDING |
7160 int save_KeyTyped; | |
7161 #endif | |
7 | 7162 |
7163 /* Can't do this recursively. Can't do it when typing a password. */ | |
7164 if (cmdwin_type != 0 | |
7165 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7166 || cmdline_star > 0 | |
7167 # endif | |
7168 ) | |
7169 { | |
7170 beep_flush(); | |
7171 return K_IGNORE; | |
7172 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7173 set_bufref(&old_curbuf, curbuf); |
7 | 7174 |
7175 /* Save current window sizes. */ | |
7176 win_size_save(&winsizes); | |
7177 | |
7178 /* Don't execute autocommands while creating the window. */ | |
1410 | 7179 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7180 |
683 | 7181 /* don't use a new tab page */ |
7182 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
|
7183 cmdmod.noswapfile = 1; |
683 | 7184 |
7 | 7185 /* Create a window for the command-line buffer. */ |
7186 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7187 { | |
7188 beep_flush(); | |
1410 | 7189 unblock_autocmds(); |
7 | 7190 return K_IGNORE; |
7191 } | |
1831 | 7192 cmdwin_type = get_cmdline_type(); |
7 | 7193 |
7194 /* Create the command-line buffer empty. */ | |
1743 | 7195 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7196 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7197 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7198 curbuf->b_p_ma = TRUE; | |
1865 | 7199 #ifdef FEAT_FOLDING |
7200 curwin->w_p_fen = FALSE; | |
7201 #endif | |
7 | 7202 # ifdef FEAT_RIGHTLEFT |
510 | 7203 curwin->w_p_rl = cmdmsg_rl; |
7204 cmdmsg_rl = FALSE; | |
7 | 7205 # endif |
2583 | 7206 RESET_BINDING(curwin); |
7 | 7207 |
7208 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7209 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7210 /* 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
|
7211 ++curbuf_lock; |
7 | 7212 |
510 | 7213 /* Showing the prompt may have set need_wait_return, reset it. */ |
7214 need_wait_return = FALSE; | |
7215 | |
1831 | 7216 histtype = hist_char2type(cmdwin_type); |
7 | 7217 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7218 { | |
7219 if (p_wc == TAB) | |
7220 { | |
7221 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7222 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7223 } | |
7224 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7225 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7226 --curbuf_lock; |
7 | 7227 |
10 | 7228 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7229 * sets 'textwidth' to 78). */ | |
7230 curbuf->b_p_tw = 0; | |
7231 | |
7 | 7232 /* Fill the buffer with the history. */ |
7233 init_history(); | |
7234 if (hislen > 0) | |
7235 { | |
7236 i = hisidx[histtype]; | |
7237 if (i >= 0) | |
7238 { | |
7239 lnum = 0; | |
7240 do | |
7241 { | |
7242 if (++i == hislen) | |
7243 i = 0; | |
7244 if (history[histtype][i].hisstr != NULL) | |
7245 ml_append(lnum++, history[histtype][i].hisstr, | |
7246 (colnr_T)0, FALSE); | |
7247 } | |
7248 while (i != hisidx[histtype]); | |
7249 } | |
7250 } | |
7251 | |
7252 /* Replace the empty last line with the current command-line and put the | |
7253 * cursor there. */ | |
7254 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7255 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7256 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7257 changed_line_abv_curs(); |
7258 invalidate_botline(); | |
743 | 7259 redraw_later(SOME_VALID); |
7 | 7260 |
7261 /* 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
|
7262 save_cmdline(&save_ccline); |
7 | 7263 |
7264 /* No Ex mode here! */ | |
7265 exmode_active = 0; | |
7266 | |
7267 State = NORMAL; | |
7268 # ifdef FEAT_MOUSE | |
7269 setmouse(); | |
7270 # endif | |
7271 | |
7272 /* 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
|
7273 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7274 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7275 stuffcharReadbuff(K_NOP); | |
7 | 7276 |
7277 i = RedrawingDisabled; | |
7278 RedrawingDisabled = 0; | |
7279 | |
7280 /* | |
7281 * Call the main loop until <CR> or CTRL-C is typed. | |
7282 */ | |
7283 cmdwin_result = 0; | |
168 | 7284 main_loop(TRUE, FALSE); |
7 | 7285 |
7286 RedrawingDisabled = i; | |
7287 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7288 # ifdef FEAT_FOLDING |
6145 | 7289 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7290 # endif |
6145 | 7291 |
7 | 7292 /* 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
|
7293 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7294 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7295 # ifdef FEAT_FOLDING |
6145 | 7296 /* Restore KeyTyped in case it is modified by autocommands */ |
7297 KeyTyped = save_KeyTyped; | |
7 | 7298 # endif |
7299 | |
1214 | 7300 /* 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
|
7301 restore_cmdline(&save_ccline); |
7 | 7302 cmdwin_type = 0; |
7303 | |
7304 exmode_active = save_exmode; | |
7305 | |
1612 | 7306 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7307 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7308 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7309 { |
7310 cmdwin_result = Ctrl_C; | |
7311 EMSG(_("E199: Active window or buffer deleted")); | |
7312 } | |
7313 else | |
7314 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7315 # if defined(FEAT_EVAL) |
7 | 7316 /* autocmds may abort script processing */ |
7317 if (aborting() && cmdwin_result != K_IGNORE) | |
7318 cmdwin_result = Ctrl_C; | |
7319 # endif | |
7320 /* Set the new command line from the cmdline buffer. */ | |
7321 vim_free(ccline.cmdbuff); | |
510 | 7322 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7323 { |
510 | 7324 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7325 | |
7326 if (histtype == HIST_CMD) | |
7327 { | |
7328 /* Execute the command directly. */ | |
7329 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7330 cmdwin_result = CAR; | |
7331 } | |
7332 else | |
7333 { | |
7334 /* First need to cancel what we were doing. */ | |
7335 ccline.cmdbuff = NULL; | |
7336 stuffcharReadbuff(':'); | |
7337 stuffReadbuff((char_u *)p); | |
7338 stuffcharReadbuff(CAR); | |
7339 } | |
7 | 7340 } |
7341 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7342 { | |
7343 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7344 cmdwin_result = CAR; | |
7345 } | |
2839 | 7346 else if (cmdwin_result == Ctrl_C) |
7347 { | |
7348 /* :q or :close, don't execute any command | |
7349 * and don't modify the cmd window. */ | |
7350 ccline.cmdbuff = NULL; | |
7351 } | |
7 | 7352 else |
7353 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7354 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
|
7355 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7356 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
|
7357 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
|
7358 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
|
7359 ccline.cmdpos = 0; |
7 | 7360 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
|
7361 } |
7 | 7362 else |
7363 { | |
7364 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7365 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7366 ccline.cmdpos = curwin->w_cursor.col; | |
7367 if (ccline.cmdpos > ccline.cmdlen) | |
7368 ccline.cmdpos = ccline.cmdlen; | |
7369 if (cmdwin_result == K_IGNORE) | |
7370 { | |
7371 set_cmdspos_cursor(); | |
7372 redrawcmd(); | |
7373 } | |
7374 } | |
7375 | |
7376 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7377 block_autocmds(); |
6876 | 7378 # ifdef FEAT_CONCEAL |
7379 /* Avoid command-line window first character being concealed. */ | |
7380 curwin->w_p_cole = 0; | |
7381 # endif | |
7 | 7382 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7383 set_bufref(&bufref, curbuf); |
7 | 7384 win_goto(old_curwin); |
7385 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7386 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7387 /* 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
|
7388 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7389 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7390 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7391 |
7392 /* Restore window sizes. */ | |
7393 win_size_restore(&winsizes); | |
7394 | |
1410 | 7395 unblock_autocmds(); |
7 | 7396 } |
7397 | |
7398 ga_clear(&winsizes); | |
7399 restart_edit = save_restart_edit; | |
510 | 7400 # ifdef FEAT_RIGHTLEFT |
7401 cmdmsg_rl = save_cmdmsg_rl; | |
7402 # endif | |
7 | 7403 |
7404 State = save_State; | |
7405 # ifdef FEAT_MOUSE | |
7406 setmouse(); | |
7407 # endif | |
7408 | |
7409 return cmdwin_result; | |
7410 } | |
7411 #endif /* FEAT_CMDWIN */ | |
7412 | |
7413 /* | |
7414 * Used for commands that either take a simple command string argument, or: | |
7415 * cmd << endmarker | |
7416 * {script} | |
7417 * endmarker | |
7418 * Returns a pointer to allocated memory with {script} or NULL. | |
7419 */ | |
7420 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7421 script_get(exarg_T *eap, char_u *cmd) |
7 | 7422 { |
7423 char_u *theline; | |
7424 char *end_pattern = NULL; | |
7425 char dot[] = "."; | |
7426 garray_T ga; | |
7427 | |
7428 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7429 return NULL; | |
7430 | |
7431 ga_init2(&ga, 1, 0x400); | |
7432 | |
7433 if (cmd[2] != NUL) | |
7434 end_pattern = (char *)skipwhite(cmd + 2); | |
7435 else | |
7436 end_pattern = dot; | |
7437 | |
7438 for (;;) | |
7439 { | |
7440 theline = eap->getline( | |
7441 #ifdef FEAT_EVAL | |
75 | 7442 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7443 #endif |
7444 NUL, eap->cookie, 0); | |
7445 | |
7446 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7447 { |
7448 vim_free(theline); | |
7 | 7449 break; |
1694 | 7450 } |
7 | 7451 |
7452 ga_concat(&ga, theline); | |
7453 ga_append(&ga, '\n'); | |
7454 vim_free(theline); | |
7455 } | |
21 | 7456 ga_append(&ga, NUL); |
7 | 7457 |
7458 return (char_u *)ga.ga_data; | |
7459 } |