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