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