Mercurial > vim
annotate src/ex_getln.c @ 14528:58ca11610819 v8.1.0277
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
commit https://github.com/vim/vim/commit/c7f08b7ee1c1ff2080d425c2fcdb6907c26fc98e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 12 17:39:14 2018 +0200
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Problem: 'incsearch' highlighting wrong in a few cases.
Solution: Fix using last search pattern. Restore highlighting when changing
command. (issue #3321)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 12 Aug 2018 17:45:04 +0200 |
parents | e36d6e01708c |
children | 60e0022e6e5d |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 /* | |
17 * Variables shared between getcmdline(), redrawcmdline() and others. | |
18 * These need to be saved when using CTRL-R |, that's why they are in a | |
19 * structure. | |
20 */ | |
21 struct cmdline_info | |
22 { | |
23 char_u *cmdbuff; /* pointer to command line buffer */ | |
24 int cmdbufflen; /* length of cmdbuff */ | |
25 int cmdlen; /* number of chars in command line */ | |
26 int cmdpos; /* current cursor position */ | |
27 int cmdspos; /* cursor column on screen */ | |
3503 | 28 int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */ |
7 | 29 int cmdindent; /* number of spaces before cmdline */ |
30 char_u *cmdprompt; /* message in front of cmdline */ | |
31 int cmdattr; /* attributes for prompt */ | |
32 int overstrike; /* Typing mode on the command line. Shared by | |
33 getcmdline() and put_on_cmdline(). */ | |
1718 | 34 expand_T *xpc; /* struct being used for expansion, xp_pattern |
35 may point into cmdbuff */ | |
531 | 36 int xp_context; /* type of expansion */ |
37 # ifdef FEAT_EVAL | |
38 char_u *xp_arg; /* user-defined expansion arg */ | |
1039 | 39 int input_fn; /* when TRUE Invoked for input() function */ |
531 | 40 # endif |
7 | 41 }; |
42 | |
1718 | 43 /* The current cmdline_info. It is initialized in getcmdline() and after that |
44 * used by other functions. When invoking getcmdline() recursively it needs | |
45 * to be saved with save_cmdline() and restored with restore_cmdline(). | |
46 * TODO: make it local to getcmdline() and pass it around. */ | |
47 static struct cmdline_info ccline; | |
7 | 48 |
49 static int cmd_showtail; /* Only show path tail in lists ? */ | |
50 | |
51 #ifdef FEAT_EVAL | |
52 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
53 #endif | |
54 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
55 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
56 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
57 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
58 |
7 | 59 #ifdef FEAT_CMDHIST |
60 typedef struct hist_entry | |
61 { | |
62 int hisnum; /* identifying number */ | |
4258 | 63 int viminfo; /* when TRUE hisstr comes from viminfo */ |
7 | 64 char_u *hisstr; /* actual entry, separator char after the NUL */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
65 time_t time_set; /* when it was typed, zero if unknown */ |
7 | 66 } histentry_T; |
67 | |
68 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
69 static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */ | |
70 static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0}; | |
71 /* identifying (unique) number of newest history entry */ | |
72 static int hislen = 0; /* actual length of history tables */ | |
73 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
74 static int hist_char2type(int c); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
75 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
76 static int in_history(int, char_u *, int, int, int); |
7 | 77 # ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
78 static int calc_hist_idx(int histype, int num); |
7 | 79 # endif |
80 #endif | |
81 | |
82 #ifdef FEAT_RIGHTLEFT | |
83 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
84 #endif | |
85 | |
86 #ifdef FEAT_FKMAP | |
87 static int cmd_fkmap = 0; /* Farsi mapping during command line */ | |
88 #endif | |
89 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
90 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
91 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
92 static void set_cmdspos_cursor(void); |
7 | 93 #ifdef FEAT_MBYTE |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
94 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
95 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
96 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
97 static int realloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
98 static void draw_cmdline(int start, int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
99 static void save_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
100 static void restore_cmdline(struct cmdline_info *ccp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
101 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 102 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
103 static void redrawcmd_preedit(void); |
7 | 104 #endif |
105 #ifdef FEAT_WILDMENU | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
106 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
107 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
108 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
109 static void cursorcmd(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
110 static int ccheck_abbr(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
111 static int nextwild(expand_T *xp, int type, int options, int escape); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
112 static void escape_fname(char_u **pp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
113 static int showmatches(expand_T *xp, int wildmenu); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
114 static void set_expand_context(expand_T *xp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
115 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
116 static int expand_showtail(expand_T *xp); |
7 | 117 #ifdef FEAT_CMDL_COMPL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
118 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
119 static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]); |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
120 static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file); |
3503 | 121 # ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
122 static char_u *get_history_arg(expand_T *xp, int idx); |
3503 | 123 # endif |
7 | 124 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
125 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
126 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); |
7 | 127 # endif |
128 #endif | |
4265 | 129 #ifdef FEAT_CMDHIST |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
130 static void clear_hist_entry(histentry_T *hisptr); |
4265 | 131 #endif |
7 | 132 |
133 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
134 static int open_cmdwin(void); |
7 | 135 #endif |
136 | |
3164 | 137 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
138 static int | |
139 #ifdef __BORLANDC__ | |
140 _RTLENTRYF | |
141 #endif | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
142 sort_func_compare(const void *s1, const void *s2); |
3164 | 143 #endif |
144 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
145 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
146 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
147 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
148 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
149 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
150 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
151 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
152 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
153 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
154 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
155 |
7 | 156 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
157 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
158 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
159 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
160 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
161 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
162 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
163 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
164 compute_cmdrow(); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
165 MSG(""); |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
166 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
167 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
168 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
169 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
170 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
171 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
172 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
173 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
174 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
175 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
176 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
177 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
178 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
179 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
180 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
181 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
182 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
183 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
184 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
185 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
186 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
187 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
188 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
189 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
190 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
191 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
192 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
193 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
194 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
195 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
196 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
197 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
198 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
199 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
200 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
201 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
202 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
203 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
204 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
205 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
206 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
207 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
208 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
209 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
210 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
211 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
212 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
213 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
214 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
215 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
216 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
217 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
218 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
219 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
220 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
221 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
222 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
223 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
224 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
225 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
226 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
227 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
228 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
229 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
230 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
231 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
232 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
233 int incsearch_postponed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
234 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
235 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
236 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
237 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
238 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
239 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
240 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
241 is_state->incsearch_postponed = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
242 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
243 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
244 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
245 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
246 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
247 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
248 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
249 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
250 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
251 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
252 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
253 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
254 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
255 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
256 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
257 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
258 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
259 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
260 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
261 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
262 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
263 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
264 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
265 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
266 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
267 * Sets search_first_line and search_last_line to the address range. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
268 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
269 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
270 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
271 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
272 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
273 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
274 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
275 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
276 if (p_is && !cmd_silent) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
277 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
278 // by default search all lines |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
279 search_first_line = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
280 search_last_line = MAXLNUM; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
281 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
282 if (firstc == '/' || firstc == '?') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
283 return TRUE; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
284 if (firstc == ':') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
285 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
286 char_u *cmd = skip_range(ccline.cmdbuff, NULL); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
287 char_u *p; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
288 int delim; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
289 char_u *end; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
290 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
291 if (*cmd == 's' || *cmd == 'g' || *cmd == 'v') |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
292 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
293 // Skip over "substitute" to find the pattern separator. |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
294 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
295 ; |
14522
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
296 if (*p != NUL |
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
297 && (STRNCMP(cmd, "substitute", p - cmd) == 0 |
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
298 || STRNCMP(cmd, "global", p - cmd) == 0 |
97641c4f5687
patch 8.1.0274: 'incsearch' triggers on ":source"
Christian Brabandt <cb@256bit.org>
parents:
14520
diff
changeset
|
299 || STRNCMP(cmd, "vglobal", p - cmd) == 0)) |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
300 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
301 delim = *p++; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
302 end = skip_regexp(p, delim, p_magic, NULL); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
303 if (end > p || *end == delim) |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
304 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
305 char_u *dummy; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
306 exarg_T ea; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
307 pos_T save_cursor = curwin->w_cursor; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
308 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
309 // found a non-empty pattern |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
310 *skiplen = (int)(p - ccline.cmdbuff); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
311 *patlen = (int)(end - p); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
312 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
313 // parse the address range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
314 vim_memset(&ea, 0, sizeof(ea)); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
315 ea.line1 = 1; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
316 ea.line2 = 1; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
317 ea.cmd = ccline.cmdbuff; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
318 ea.addr_type = ADDR_LINES; |
14524
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
319 curwin->w_cursor = is_state->search_start; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
320 parse_cmd_address(&ea, &dummy); |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
321 if (ea.addr_count > 0) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
322 { |
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 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
344 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
345 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
346 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
347 incsearch_state_T *is_state, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
348 int call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
349 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
350 if (is_state->did_incsearch) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
351 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
352 is_state->did_incsearch = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
353 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
354 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
355 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
356 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
357 if (!EQUAL_POS(is_state->save_cursor, is_state->search_start)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
358 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
359 // put the '" mark at the original position |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
360 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
361 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
362 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
363 curwin->w_cursor = is_state->search_start; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
364 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
365 restore_viewstate(&is_state->old_viewstate); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
366 highlight_match = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
367 validate_cursor(); /* needed for TAB */ |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
368 if (call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
369 update_screen(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
370 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
371 redraw_all_later(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
372 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
373 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
374 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
375 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
376 * 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
|
377 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
378 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
379 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
|
380 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
381 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
382 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
|
383 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
384 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
|
385 int i; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
386 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
|
387 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
|
388 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
389 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
390 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
391 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
392 int use_last_pat; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
393 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
394 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
395 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
396 finish_incsearch_highlighting(FALSE, is_state, TRUE); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
397 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
398 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
399 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
400 // 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
|
401 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
402 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
403 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
|
404 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
405 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
406 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
|
407 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
408 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
|
409 // 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
|
410 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
|
411 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
412 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
413 // 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
|
414 curwin->w_cursor.lnum = search_first_line; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
415 curwin->w_cursor.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
|
416 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
417 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
|
418 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
419 // Use the previous pattern for ":s//". |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
420 next_char = ccline.cmdbuff[skiplen + patlen]; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
421 use_last_pat = patlen == 0 && skiplen > 0 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
422 && ccline.cmdbuff[skiplen - 1] == next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
423 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
424 // If there is no pattern, don't do anything. |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
425 if (patlen == 0 && !use_last_pat) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
426 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
427 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
428 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
|
429 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
|
430 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
431 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
432 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
433 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
|
434 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
435 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
|
436 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
437 ++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
|
438 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
439 // 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
|
440 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
|
441 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
442 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
450 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
451 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
452 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
453 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
454 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
455 ccline.cmdbuff[skiplen + patlen] = next_char; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
456 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
457 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
458 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
|
459 || 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
|
460 // 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
|
461 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
|
462 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
463 // 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
|
464 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
465 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
466 (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
|
467 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
|
468 i = 0; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
469 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
470 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
|
471 // 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
|
472 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
|
473 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
474 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
475 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
|
476 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
477 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
|
478 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
479 // 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
|
480 // 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
|
481 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
|
482 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
|
483 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
484 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
485 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
486 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
487 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
|
488 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
489 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
|
490 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
|
491 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
492 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
|
493 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
|
494 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
|
495 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
496 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
497 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
|
498 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
499 // 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
|
500 // Avoids a flash when typing "foo\|". |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
501 if (!use_last_pat) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
502 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
503 next_char = ccline.cmdbuff[skiplen + patlen]; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
504 ccline.cmdbuff[skiplen + patlen] = NUL; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
505 if (empty_pattern(ccline.cmdbuff)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
506 set_no_hlsearch(TRUE); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
507 ccline.cmdbuff[skiplen + patlen] = next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
508 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
509 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
510 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
511 // 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
|
512 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
|
513 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
|
514 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
515 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
|
516 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
|
517 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
|
518 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
|
519 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
520 // 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
|
521 if (i != 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
522 curwin->w_cursor = end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
523 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
524 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
525 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
526 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
|
527 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
528 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
529 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
530 * 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
|
531 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
532 * 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
|
533 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
534 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
535 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
|
536 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
|
537 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
538 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
|
539 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
540 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
541 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
|
542 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
543 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
544 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
|
545 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
|
546 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
|
547 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
552 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
553 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
|
554 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
555 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
|
556 skiplen = 0; |
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
557 patlen = STRLEN(pat); |
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
558 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
559 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
|
560 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
|
561 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
562 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
|
563 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
564 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
565 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
|
566 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
567 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
|
568 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
|
569 // 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
|
570 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
571 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
572 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
|
573 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
574 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
575 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
|
576 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
577 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
|
578 ++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
|
579 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
|
580 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
|
581 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
|
582 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
|
583 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
|
584 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
|
585 --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
|
586 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
|
587 if (i) |
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 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
|
590 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
|
591 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
|
592 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
|
593 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
594 // 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
|
595 // 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
|
596 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
|
597 (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
|
598 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
599 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
|
600 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
601 // 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
|
602 // 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
|
603 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
|
604 (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
|
605 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
606 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
|
607 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
608 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
609 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
|
610 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
611 (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
|
612 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
613 (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
|
614 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 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
|
617 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
|
618 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
|
619 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
621 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
622 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
|
623 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
|
624 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
625 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
626 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
627 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
|
628 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
|
629 return FAIL; |
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 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
633 * 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
|
634 * 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
|
635 * 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
|
636 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
637 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
638 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
|
639 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
640 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
|
641 |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
642 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
|
643 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
644 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
645 // 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
|
646 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
|
647 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
648 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
|
649 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
|
650 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
651 *c = gchar_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
652 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
653 // 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
|
654 // 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
|
655 // 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
|
656 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
|
657 *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
|
658 if (*c != NUL) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
659 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
660 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
|
661 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
|
662 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
663 // 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
|
664 stuffcharReadbuff(*c); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
665 *c = '\\'; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
666 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
667 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
668 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
669 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
670 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
672 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
673 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
674 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
675 /* |
7 | 676 * getcmdline() - accept a command line starting with firstc. |
677 * | |
678 * firstc == ':' get ":" command line. | |
679 * firstc == '/' or '?' get search pattern | |
680 * firstc == '=' get expression | |
681 * firstc == '@' get text for input() function | |
682 * firstc == '>' get text for debug mode | |
683 * firstc == NUL get text for :insert command | |
684 * firstc == -1 like NUL, and break on CTRL-C | |
685 * | |
686 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
687 * command line. | |
688 * | |
689 * Careful: getcmdline() can be called recursively! | |
690 * | |
691 * Return pointer to allocated string if there is a commandline, NULL | |
692 * otherwise. | |
693 */ | |
694 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
695 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
696 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
697 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
|
698 int indent) /* indent for inside conditionals */ |
7 | 699 { |
700 int c; | |
701 int i; | |
702 int j; | |
703 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
704 int do_abbr; /* when TRUE check for abbr. */ | |
705 #ifdef FEAT_CMDHIST | |
706 char_u *lookfor = NULL; /* string to match */ | |
707 int hiscnt; /* current history line in use */ | |
708 int histype; /* history type to be used */ | |
709 #endif | |
710 #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
|
711 incsearch_state_T is_state; |
7 | 712 #endif |
713 int did_wild_list = FALSE; /* did wild_list() recently */ | |
714 int wim_index = 0; /* index in wim_flags[] */ | |
715 int res; | |
716 int save_msg_scroll = msg_scroll; | |
717 int save_State = State; /* remember State when called */ | |
718 int some_key_typed = FALSE; /* one of the keys was typed */ | |
719 #ifdef FEAT_MOUSE | |
720 /* mouse drag and release events are ignored, unless they are | |
721 * preceded with a mouse down event */ | |
722 int ignore_drag_release = TRUE; | |
723 #endif | |
724 #ifdef FEAT_EVAL | |
725 int break_ctrl_c = FALSE; | |
726 #endif | |
727 expand_T xpc; | |
728 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
|
729 #if defined(FEAT_WILDMENU) || defined(FEAT_EVAL) |
195 | 730 /* Everything that may work recursively should save and restore the |
731 * current command line in save_ccline. That includes update_screen(), a | |
732 * custom status line may invoke ":normal". */ | |
733 struct cmdline_info save_ccline; | |
734 #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
|
735 int cmdline_type; |
7 | 736 |
737 #ifdef FEAT_EVAL | |
738 if (firstc == -1) | |
739 { | |
740 firstc = NUL; | |
741 break_ctrl_c = TRUE; | |
742 } | |
743 #endif | |
744 #ifdef FEAT_RIGHTLEFT | |
745 /* start without Hebrew mapping for a command line */ | |
746 if (firstc == ':' || firstc == '=' || firstc == '>') | |
747 cmd_hkmap = 0; | |
748 #endif | |
749 | |
750 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
|
751 |
7 | 752 #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
|
753 init_incsearch_state(&is_state); |
7 | 754 #endif |
755 | |
756 /* | |
757 * set some variables for redrawcmd() | |
758 */ | |
759 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 760 ccline.cmdindent = (firstc > 0 ? indent : 0); |
761 | |
762 /* alloc initial ccline.cmdbuff */ | |
763 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 764 if (ccline.cmdbuff == NULL) |
765 return NULL; /* out of memory */ | |
766 ccline.cmdlen = ccline.cmdpos = 0; | |
767 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
|
768 sb_text_start_cmdline(); |
7 | 769 |
164 | 770 /* autoindent for :insert and :append */ |
771 if (firstc <= 0) | |
772 { | |
6929 | 773 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 774 ccline.cmdbuff[indent] = NUL; |
775 ccline.cmdpos = indent; | |
776 ccline.cmdspos = indent; | |
777 ccline.cmdlen = indent; | |
778 } | |
779 | |
7 | 780 ExpandInit(&xpc); |
1718 | 781 ccline.xpc = &xpc; |
7 | 782 |
783 #ifdef FEAT_RIGHTLEFT | |
784 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
785 && (firstc == '/' || firstc == '?')) | |
786 cmdmsg_rl = TRUE; | |
787 else | |
788 cmdmsg_rl = FALSE; | |
789 #endif | |
790 | |
791 redir_off = TRUE; /* don't redirect the typed command */ | |
792 if (!cmd_silent) | |
793 { | |
794 i = msg_scrolled; | |
795 msg_scrolled = 0; /* avoid wait_return message */ | |
796 gotocmdline(TRUE); | |
797 msg_scrolled += i; | |
798 redrawcmdprompt(); /* draw prompt or indent */ | |
799 set_cmdspos(); | |
800 } | |
801 xpc.xp_context = EXPAND_NOTHING; | |
802 xpc.xp_backslash = XP_BS_NONE; | |
632 | 803 #ifndef BACKSLASH_IN_FILENAME |
804 xpc.xp_shell = FALSE; | |
805 #endif | |
7 | 806 |
531 | 807 #if defined(FEAT_EVAL) |
808 if (ccline.input_fn) | |
809 { | |
810 xpc.xp_context = ccline.xp_context; | |
811 xpc.xp_pattern = ccline.cmdbuff; | |
1322 | 812 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 813 xpc.xp_arg = ccline.xp_arg; |
1322 | 814 # endif |
531 | 815 } |
816 #endif | |
817 | |
7 | 818 /* |
819 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
820 * doing ":@0" when register 0 doesn't contain a CR. | |
821 */ | |
822 msg_scroll = FALSE; | |
823 | |
824 State = CMDLINE; | |
825 | |
826 if (firstc == '/' || firstc == '?' || firstc == '@') | |
827 { | |
828 /* Use ":lmap" mappings for search pattern and input(). */ | |
829 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
830 b_im_ptr = &curbuf->b_p_iminsert; | |
831 else | |
832 b_im_ptr = &curbuf->b_p_imsearch; | |
833 if (*b_im_ptr == B_IMODE_LMAP) | |
834 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
835 #ifdef HAVE_INPUT_METHOD |
7 | 836 im_set_active(*b_im_ptr == B_IMODE_IM); |
837 #endif | |
838 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
839 #ifdef HAVE_INPUT_METHOD |
7 | 840 else if (p_imcmdline) |
841 im_set_active(TRUE); | |
842 #endif | |
843 | |
844 #ifdef FEAT_MOUSE | |
845 setmouse(); | |
846 #endif | |
847 #ifdef CURSOR_SHAPE | |
848 ui_cursor_shape(); /* may show different cursor shape */ | |
849 #endif | |
850 | |
571 | 851 /* When inside an autocommand for writing "exiting" may be set and |
852 * terminal mode set to cooked. Need to set raw mode here then. */ | |
853 settmode(TMODE_RAW); | |
854 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
855 /* 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
|
856 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
|
857 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
|
858 |
7 | 859 #ifdef FEAT_CMDHIST |
860 init_history(); | |
861 hiscnt = hislen; /* set hiscnt to impossible history value */ | |
862 histype = hist_char2type(firstc); | |
863 #endif | |
864 | |
865 #ifdef FEAT_DIGRAPHS | |
1868 | 866 do_digraph(-1); /* init digraph typeahead */ |
7 | 867 #endif |
868 | |
5993 | 869 /* If something above caused an error, reset the flags, we do want to type |
870 * and execute commands. Display may be messed up a bit. */ | |
871 if (did_emsg) | |
872 redrawcmd(); | |
873 did_emsg = FALSE; | |
874 got_int = FALSE; | |
875 | |
7 | 876 /* |
877 * Collect the command string, handling editing keys. | |
878 */ | |
879 for (;;) | |
880 { | |
972 | 881 redir_off = TRUE; /* Don't redirect the typed command. |
882 Repeated, because a ":redir" inside | |
883 completion may switch it on. */ | |
7 | 884 #ifdef USE_ON_FLY_SCROLL |
885 dont_scroll = FALSE; /* allow scrolling here */ | |
886 #endif | |
887 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
888 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
889 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
|
890 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
|
891 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
|
892 |
7 | 893 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 894 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
895 /* 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
|
896 * anything, such as stop completion. */ |
1472 | 897 do |
898 { | |
899 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
|
900 } while (c == K_IGNORE || c == K_NOP); |
1472 | 901 |
7 | 902 if (KeyTyped) |
903 { | |
904 some_key_typed = TRUE; | |
905 #ifdef FEAT_RIGHTLEFT | |
906 if (cmd_hkmap) | |
907 c = hkmap(c); | |
908 # ifdef FEAT_FKMAP | |
909 if (cmd_fkmap) | |
910 c = cmdl_fkmap(c); | |
911 # endif | |
912 if (cmdmsg_rl && !KeyStuffed) | |
913 { | |
914 /* Invert horizontal movements and operations. Only when | |
915 * typed by the user directly, not when the result of a | |
916 * mapping. */ | |
917 switch (c) | |
918 { | |
919 case K_RIGHT: c = K_LEFT; break; | |
920 case K_S_RIGHT: c = K_S_LEFT; break; | |
921 case K_C_RIGHT: c = K_C_LEFT; break; | |
922 case K_LEFT: c = K_RIGHT; break; | |
923 case K_S_LEFT: c = K_S_RIGHT; break; | |
924 case K_C_LEFT: c = K_C_RIGHT; break; | |
925 } | |
926 } | |
927 #endif | |
928 } | |
929 | |
930 /* | |
931 * Ignore got_int when CTRL-C was typed here. | |
932 * Don't ignore it in :global, we really need to break then, e.g., for | |
933 * ":g/pat/normal /pat" (without the <CR>). | |
934 * Don't ignore it for the input() function. | |
935 */ | |
936 if ((c == Ctrl_C | |
937 #ifdef UNIX | |
938 || c == intr_char | |
939 #endif | |
940 ) | |
941 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
942 && firstc != '@' | |
943 #endif | |
944 #ifdef FEAT_EVAL | |
945 && !break_ctrl_c | |
946 #endif | |
947 && !global_busy) | |
948 got_int = FALSE; | |
949 | |
950 #ifdef FEAT_CMDHIST | |
951 /* free old command line when finished moving around in the history | |
952 * list */ | |
953 if (lookfor != NULL | |
180 | 954 && c != K_S_DOWN && c != K_S_UP |
230 | 955 && c != K_DOWN && c != K_UP |
7 | 956 && c != K_PAGEDOWN && c != K_PAGEUP |
957 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 958 && c != K_LEFT && c != K_RIGHT |
7 | 959 && (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
|
960 VIM_CLEAR(lookfor); |
7 | 961 #endif |
962 | |
963 /* | |
1718 | 964 * When there are matching completions to select <S-Tab> works like |
965 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 966 */ |
1718 | 967 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 968 c = Ctrl_P; |
969 | |
970 #ifdef FEAT_WILDMENU | |
971 /* Special translations for 'wildmenu' */ | |
972 if (did_wild_list && p_wmnu) | |
973 { | |
230 | 974 if (c == K_LEFT) |
7 | 975 c = Ctrl_P; |
230 | 976 else if (c == K_RIGHT) |
7 | 977 c = Ctrl_N; |
978 } | |
979 /* Hitting CR after "emenu Name.": complete submenu */ | |
980 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
981 && ccline.cmdpos > 1 | |
982 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
983 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
984 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
985 c = K_DOWN; | |
986 #endif | |
987 | |
988 /* free expanded names when finished walking through matches */ | |
989 if (xpc.xp_numfiles != -1 | |
990 && !(c == p_wc && KeyTyped) && c != p_wcm | |
991 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
992 && c != Ctrl_L) | |
993 { | |
994 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
995 did_wild_list = FALSE; | |
996 #ifdef FEAT_WILDMENU | |
230 | 997 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 998 #endif |
999 xpc.xp_context = EXPAND_NOTHING; | |
1000 wim_index = 0; | |
1001 #ifdef FEAT_WILDMENU | |
1002 if (p_wmnu && wild_menu_showing != 0) | |
1003 { | |
1004 int skt = KeyTyped; | |
532 | 1005 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1006 |
1007 if (ccline.input_fn) | |
1008 RedrawingDisabled = 0; | |
7 | 1009 |
1010 if (wild_menu_showing == WM_SCROLLED) | |
1011 { | |
1012 /* Entered command line, move it up */ | |
1013 cmdline_row--; | |
1014 redrawcmd(); | |
1015 } | |
1016 else if (save_p_ls != -1) | |
1017 { | |
1018 /* restore 'laststatus' and 'winminheight' */ | |
1019 p_ls = save_p_ls; | |
1020 p_wmh = save_p_wmh; | |
1021 last_status(FALSE); | |
195 | 1022 save_cmdline(&save_ccline); |
7 | 1023 update_screen(VALID); /* redraw the screen NOW */ |
195 | 1024 restore_cmdline(&save_ccline); |
7 | 1025 redrawcmd(); |
1026 save_p_ls = -1; | |
1027 } | |
1028 else | |
1029 { | |
1030 win_redraw_last_status(topframe); | |
1031 redraw_statuslines(); | |
1032 } | |
532 | 1033 KeyTyped = skt; |
1034 wild_menu_showing = 0; | |
531 | 1035 if (ccline.input_fn) |
1036 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1037 } |
1038 #endif | |
1039 } | |
1040 | |
1041 #ifdef FEAT_WILDMENU | |
1042 /* Special translations for 'wildmenu' */ | |
1043 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1044 { | |
1045 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1046 if (c == K_DOWN && ccline.cmdpos > 0 |
1047 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1048 c = p_wc; |
230 | 1049 else if (c == K_UP) |
7 | 1050 { |
1051 /* Hitting <Up>: Remove one submenu name in front of the | |
1052 * cursor */ | |
1053 int found = FALSE; | |
1054 | |
1055 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1056 i = 0; | |
1057 while (--j > 0) | |
1058 { | |
1059 /* check for start of menu name */ | |
1060 if (ccline.cmdbuff[j] == ' ' | |
1061 && ccline.cmdbuff[j - 1] != '\\') | |
1062 { | |
1063 i = j + 1; | |
1064 break; | |
1065 } | |
1066 /* check for start of submenu name */ | |
1067 if (ccline.cmdbuff[j] == '.' | |
1068 && ccline.cmdbuff[j - 1] != '\\') | |
1069 { | |
1070 if (found) | |
1071 { | |
1072 i = j + 1; | |
1073 break; | |
1074 } | |
1075 else | |
1076 found = TRUE; | |
1077 } | |
1078 } | |
1079 if (i > 0) | |
1080 cmdline_del(i); | |
1081 c = p_wc; | |
1082 xpc.xp_context = EXPAND_NOTHING; | |
1083 } | |
1084 } | |
714 | 1085 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1086 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1087 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1088 { |
1089 char_u upseg[5]; | |
1090 | |
1091 upseg[0] = PATHSEP; | |
1092 upseg[1] = '.'; | |
1093 upseg[2] = '.'; | |
1094 upseg[3] = PATHSEP; | |
1095 upseg[4] = NUL; | |
1096 | |
1318 | 1097 if (c == K_DOWN |
1098 && ccline.cmdpos > 0 | |
1099 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1100 && (ccline.cmdpos < 3 | |
1101 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1102 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1103 { | |
1104 /* go down a directory */ | |
1105 c = p_wc; | |
1106 } | |
230 | 1107 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1108 { |
1109 /* If in a direct ancestor, strip off one ../ to go down */ | |
1110 int found = FALSE; | |
1111 | |
1112 j = ccline.cmdpos; | |
1113 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1114 while (--j > i) | |
1115 { | |
39 | 1116 #ifdef FEAT_MBYTE |
1117 if (has_mbyte) | |
1118 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1119 #endif | |
7 | 1120 if (vim_ispathsep(ccline.cmdbuff[j])) |
1121 { | |
1122 found = TRUE; | |
1123 break; | |
1124 } | |
1125 } | |
1126 if (found | |
1127 && ccline.cmdbuff[j - 1] == '.' | |
1128 && ccline.cmdbuff[j - 2] == '.' | |
1129 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1130 { | |
1131 cmdline_del(j - 2); | |
1132 c = p_wc; | |
1133 } | |
1134 } | |
230 | 1135 else if (c == K_UP) |
7 | 1136 { |
1137 /* go up a directory */ | |
1138 int found = FALSE; | |
1139 | |
1140 j = ccline.cmdpos - 1; | |
1141 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1142 while (--j > i) | |
1143 { | |
1144 #ifdef FEAT_MBYTE | |
1145 if (has_mbyte) | |
1146 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1147 #endif | |
1148 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1149 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1150 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1151 ccline.cmdbuff[j + 1]) == NULL |
7 | 1152 #endif |
1153 ) | |
1154 { | |
1155 if (found) | |
1156 { | |
1157 i = j + 1; | |
1158 break; | |
1159 } | |
1160 else | |
1161 found = TRUE; | |
1162 } | |
1163 } | |
1164 | |
1165 if (!found) | |
1166 j = i; | |
1167 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1168 j += 4; | |
1169 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1170 && j == i) | |
1171 j += 3; | |
1172 else | |
1173 j = 0; | |
1174 if (j > 0) | |
1175 { | |
1176 /* TODO this is only for DOS/UNIX systems - need to put in | |
1177 * machine-specific stuff here and in upseg init */ | |
1178 cmdline_del(j); | |
1179 put_on_cmdline(upseg + 1, 3, FALSE); | |
1180 } | |
1181 else if (ccline.cmdpos > i) | |
1182 cmdline_del(i); | |
3204 | 1183 |
1184 /* Now complete in the new directory. Set KeyTyped in case the | |
1185 * Up key came from a mapping. */ | |
7 | 1186 c = p_wc; |
3204 | 1187 KeyTyped = TRUE; |
7 | 1188 } |
1189 } | |
1190 | |
1191 #endif /* FEAT_WILDMENU */ | |
1192 | |
1193 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1194 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1195 if (c == Ctrl_BSL) | |
1196 { | |
1197 ++no_mapping; | |
1198 ++allow_keys; | |
1389 | 1199 c = plain_vgetc(); |
7 | 1200 --no_mapping; |
1201 --allow_keys; | |
3859 | 1202 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1203 * is in a mapping. */ | |
1204 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
1205 || (ccline.cmdfirstc == '=' && KeyTyped))) | |
7 | 1206 { |
1207 vungetc(c); | |
1208 c = Ctrl_BSL; | |
1209 } | |
1210 #ifdef FEAT_EVAL | |
1211 else if (c == 'e') | |
1212 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1213 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1214 int len; |
7 | 1215 |
1216 /* | |
1217 * Replace the command line with the result of an expression. | |
625 | 1218 * Need to save and restore the current command line, to be |
1219 * able to enter a new one... | |
7 | 1220 */ |
1221 if (ccline.cmdpos == ccline.cmdlen) | |
1222 new_cmdpos = 99999; /* keep it at the end */ | |
1223 else | |
1224 new_cmdpos = ccline.cmdpos; | |
95 | 1225 |
1226 save_cmdline(&save_ccline); | |
7 | 1227 c = get_expr_register(); |
95 | 1228 restore_cmdline(&save_ccline); |
7 | 1229 if (c == '=') |
1230 { | |
634 | 1231 /* Need to save and restore ccline. And set "textlock" |
632 | 1232 * to avoid nasty things like going to another buffer when |
1233 * evaluating an expression. */ | |
95 | 1234 save_cmdline(&save_ccline); |
634 | 1235 ++textlock; |
7 | 1236 p = get_expr_line(); |
634 | 1237 --textlock; |
95 | 1238 restore_cmdline(&save_ccline); |
2617 | 1239 |
1240 if (p != NULL) | |
7 | 1241 { |
2617 | 1242 len = (int)STRLEN(p); |
1243 if (realloc_cmdbuff(len + 1) == OK) | |
1244 { | |
1245 ccline.cmdlen = len; | |
1246 STRCPY(ccline.cmdbuff, p); | |
1247 vim_free(p); | |
1248 | |
1249 /* Restore the cursor or use the position set with | |
1250 * set_cmdline_pos(). */ | |
1251 if (new_cmdpos > ccline.cmdlen) | |
1252 ccline.cmdpos = ccline.cmdlen; | |
1253 else | |
1254 ccline.cmdpos = new_cmdpos; | |
1255 | |
1256 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1257 redrawcmd(); | |
1258 goto cmdline_changed; | |
1259 } | |
7 | 1260 } |
1261 } | |
1262 beep_flush(); | |
2636 | 1263 got_int = FALSE; /* don't abandon the command line */ |
1264 did_emsg = FALSE; | |
1265 emsg_on_display = FALSE; | |
1266 redrawcmd(); | |
1267 goto cmdline_not_changed; | |
7 | 1268 } |
1269 #endif | |
1270 else | |
1271 { | |
1272 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1273 restart_edit = 'a'; | |
1274 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1275 in history */ | |
1276 goto returncmd; /* back to Normal mode */ | |
1277 } | |
1278 } | |
1279 | |
1280 #ifdef FEAT_CMDWIN | |
1281 if (c == cedit_key || c == K_CMDWIN) | |
1282 { | |
6211 | 1283 if (ex_normal_busy == 0 && got_int == FALSE) |
1284 { | |
1285 /* | |
1286 * Open a window to edit the command line (and history). | |
1287 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1288 c = open_cmdwin(); |
6211 | 1289 some_key_typed = TRUE; |
1290 } | |
7 | 1291 } |
1292 # ifdef FEAT_DIGRAPHS | |
1293 else | |
1294 # endif | |
1295 #endif | |
1296 #ifdef FEAT_DIGRAPHS | |
1297 c = do_digraph(c); | |
1298 #endif | |
1299 | |
1300 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1301 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1302 { | |
168 | 1303 /* In Ex mode a backslash escapes a newline. */ |
1304 if (exmode_active | |
1305 && c != ESC | |
1318 | 1306 && ccline.cmdpos == ccline.cmdlen |
168 | 1307 && ccline.cmdpos > 0 |
1308 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1309 { | |
1310 if (c == K_KENTER) | |
1311 c = '\n'; | |
1312 } | |
1313 else | |
7 | 1314 { |
168 | 1315 gotesc = FALSE; /* Might have typed ESC previously, don't |
1316 truncate the cmdline now. */ | |
1317 if (ccheck_abbr(c + ABBR_OFF)) | |
1318 goto cmdline_changed; | |
1319 if (!cmd_silent) | |
1320 { | |
1321 windgoto(msg_row, 0); | |
1322 out_flush(); | |
1323 } | |
1324 break; | |
7 | 1325 } |
1326 } | |
1327 | |
1328 /* | |
1329 * Completion for 'wildchar' or 'wildcharm' key. | |
1330 * - hitting <ESC> twice means: abandon command line. | |
1331 * - wildcard expansion is only done when the 'wildchar' key is really | |
1332 * typed, not when it comes from a macro | |
1333 */ | |
1334 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1335 { | |
1336 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1337 { | |
1338 /* if 'wildmode' contains "list" may still need to list */ | |
1339 if (xpc.xp_numfiles > 1 | |
1340 && !did_wild_list | |
1341 && (wim_flags[wim_index] & WIM_LIST)) | |
1342 { | |
1343 (void)showmatches(&xpc, FALSE); | |
1344 redrawcmd(); | |
1345 did_wild_list = TRUE; | |
1346 } | |
1347 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1348 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1349 firstc != '@'); | |
7 | 1350 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1351 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1352 firstc != '@'); | |
7 | 1353 else |
1354 res = OK; /* don't insert 'wildchar' now */ | |
1355 } | |
1356 else /* typed p_wc first time */ | |
1357 { | |
1358 wim_index = 0; | |
1359 j = ccline.cmdpos; | |
1360 /* if 'wildmode' first contains "longest", get longest | |
1361 * common part */ | |
1362 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1363 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1364 firstc != '@'); | |
7 | 1365 else |
3961 | 1366 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1367 firstc != '@'); | |
7 | 1368 |
1369 /* if interrupted while completing, behave like it failed */ | |
1370 if (got_int) | |
1371 { | |
1372 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1373 got_int = FALSE; /* don't abandon the command line */ | |
1374 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1375 #ifdef FEAT_WILDMENU | |
1376 xpc.xp_context = EXPAND_NOTHING; | |
1377 #endif | |
1378 goto cmdline_changed; | |
1379 } | |
1380 | |
1381 /* when more than one match, and 'wildmode' first contains | |
1382 * "list", or no change and 'wildmode' contains "longest,list", | |
1383 * list all matches */ | |
1384 if (res == OK && xpc.xp_numfiles > 1) | |
1385 { | |
1386 /* a "longest" that didn't do anything is skipped (but not | |
1387 * "list:longest") */ | |
1388 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1389 wim_index = 1; | |
1390 if ((wim_flags[wim_index] & WIM_LIST) | |
1391 #ifdef FEAT_WILDMENU | |
1392 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1393 #endif | |
1394 ) | |
1395 { | |
1396 if (!(wim_flags[0] & WIM_LONGEST)) | |
1397 { | |
1398 #ifdef FEAT_WILDMENU | |
1399 int p_wmnu_save = p_wmnu; | |
1400 p_wmnu = 0; | |
1401 #endif | |
3961 | 1402 /* remove match */ |
1403 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1404 #ifdef FEAT_WILDMENU |
1405 p_wmnu = p_wmnu_save; | |
1406 #endif | |
1407 } | |
1408 #ifdef FEAT_WILDMENU | |
1409 (void)showmatches(&xpc, p_wmnu | |
1410 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1411 #else | |
1412 (void)showmatches(&xpc, FALSE); | |
1413 #endif | |
1414 redrawcmd(); | |
1415 did_wild_list = TRUE; | |
1416 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1417 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1418 firstc != '@'); | |
7 | 1419 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1420 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1421 firstc != '@'); | |
7 | 1422 } |
1423 else | |
6949 | 1424 vim_beep(BO_WILD); |
7 | 1425 } |
1426 #ifdef FEAT_WILDMENU | |
1427 else if (xpc.xp_numfiles == -1) | |
1428 xpc.xp_context = EXPAND_NOTHING; | |
1429 #endif | |
1430 } | |
1431 if (wim_index < 3) | |
1432 ++wim_index; | |
1433 if (c == ESC) | |
1434 gotesc = TRUE; | |
1435 if (res == OK) | |
1436 goto cmdline_changed; | |
1437 } | |
1438 | |
1439 gotesc = FALSE; | |
1440 | |
1441 /* <S-Tab> goes to last match, in a clumsy way */ | |
1442 if (c == K_S_TAB && KeyTyped) | |
1443 { | |
3961 | 1444 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1445 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1446 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1447 goto cmdline_changed; |
1448 } | |
1449 | |
1450 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1451 c = NL; | |
1452 | |
1453 do_abbr = TRUE; /* default: check for abbreviation */ | |
1454 | |
1455 /* | |
1456 * Big switch for a typed command line character. | |
1457 */ | |
1458 switch (c) | |
1459 { | |
1460 case K_BS: | |
1461 case Ctrl_H: | |
1462 case K_DEL: | |
1463 case K_KDEL: | |
1464 case Ctrl_W: | |
1465 #ifdef FEAT_FKMAP | |
1466 if (cmd_fkmap && c == K_BS) | |
1467 c = K_DEL; | |
1468 #endif | |
1469 if (c == K_KDEL) | |
1470 c = K_DEL; | |
1471 | |
1472 /* | |
1473 * delete current character is the same as backspace on next | |
1474 * character, except at end of line | |
1475 */ | |
1476 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1477 ++ccline.cmdpos; | |
1478 #ifdef FEAT_MBYTE | |
1479 if (has_mbyte && c == K_DEL) | |
1480 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1481 ccline.cmdbuff + ccline.cmdpos); | |
1482 #endif | |
1483 if (ccline.cmdpos > 0) | |
1484 { | |
1485 char_u *p; | |
1486 | |
1487 j = ccline.cmdpos; | |
1488 p = ccline.cmdbuff + j; | |
1489 #ifdef FEAT_MBYTE | |
1490 if (has_mbyte) | |
1491 { | |
1492 p = mb_prevptr(ccline.cmdbuff, p); | |
1493 if (c == Ctrl_W) | |
1494 { | |
1495 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1496 p = mb_prevptr(ccline.cmdbuff, p); | |
1497 i = mb_get_class(p); | |
1498 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1499 p = mb_prevptr(ccline.cmdbuff, p); | |
1500 if (mb_get_class(p) != i) | |
474 | 1501 p += (*mb_ptr2len)(p); |
7 | 1502 } |
1503 } | |
1504 else | |
1505 #endif | |
1506 if (c == Ctrl_W) | |
1507 { | |
1508 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1509 --p; | |
1510 i = vim_iswordc(p[-1]); | |
1511 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1512 && vim_iswordc(p[-1]) == i) | |
1513 --p; | |
1514 } | |
1515 else | |
1516 --p; | |
1517 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1518 ccline.cmdlen -= j - ccline.cmdpos; | |
1519 i = ccline.cmdpos; | |
1520 while (i < ccline.cmdlen) | |
1521 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1522 | |
1523 /* Truncate at the end, required for multi-byte chars. */ | |
1524 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1525 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1526 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1527 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1528 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
|
1529 /* 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
|
1530 * 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
|
1531 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
|
1532 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1533 #endif |
7 | 1534 redrawcmd(); |
1535 } | |
1536 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1537 && ccline.cmdprompt == NULL && indent == 0) | |
1538 { | |
1539 /* In ex and debug mode it doesn't make sense to return. */ | |
1540 if (exmode_active | |
1541 #ifdef FEAT_EVAL | |
1542 || ccline.cmdfirstc == '>' | |
1543 #endif | |
1544 ) | |
1545 goto cmdline_not_changed; | |
1546 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1547 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1548 if (!cmd_silent) |
1549 { | |
1550 #ifdef FEAT_RIGHTLEFT | |
1551 if (cmdmsg_rl) | |
1552 msg_col = Columns; | |
1553 else | |
1554 #endif | |
1555 msg_col = 0; | |
1556 msg_putchar(' '); /* delete ':' */ | |
1557 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1558 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1559 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
|
1560 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
|
1561 #endif |
7 | 1562 redraw_cmdline = TRUE; |
1563 goto returncmd; /* back to cmd mode */ | |
1564 } | |
1565 goto cmdline_changed; | |
1566 | |
1567 case K_INS: | |
1568 case K_KINS: | |
1569 #ifdef FEAT_FKMAP | |
1570 /* if Farsi mode set, we are in reverse insert mode - | |
1571 Do not change the mode */ | |
1572 if (cmd_fkmap) | |
1573 beep_flush(); | |
1574 else | |
1575 #endif | |
1576 ccline.overstrike = !ccline.overstrike; | |
1577 #ifdef CURSOR_SHAPE | |
1578 ui_cursor_shape(); /* may show different cursor shape */ | |
1579 #endif | |
1580 goto cmdline_not_changed; | |
1581 | |
1582 case Ctrl_HAT: | |
782 | 1583 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1584 { |
1585 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1586 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1587 #ifdef HAVE_INPUT_METHOD |
7 | 1588 im_set_active(FALSE); /* Disable input method */ |
1589 #endif | |
1590 if (b_im_ptr != NULL) | |
1591 { | |
1592 if (State & LANGMAP) | |
1593 *b_im_ptr = B_IMODE_LMAP; | |
1594 else | |
1595 *b_im_ptr = B_IMODE_NONE; | |
1596 } | |
1597 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1598 #ifdef HAVE_INPUT_METHOD |
7 | 1599 else |
1600 { | |
1601 /* There are no ":lmap" mappings, toggle IM. When | |
1602 * 'imdisable' is set don't try getting the status, it's | |
1603 * always off. */ | |
1604 if ((p_imdisable && b_im_ptr != NULL) | |
1605 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1606 { | |
1607 im_set_active(FALSE); /* Disable input method */ | |
1608 if (b_im_ptr != NULL) | |
1609 *b_im_ptr = B_IMODE_NONE; | |
1610 } | |
1611 else | |
1612 { | |
1613 im_set_active(TRUE); /* Enable input method */ | |
1614 if (b_im_ptr != NULL) | |
1615 *b_im_ptr = B_IMODE_IM; | |
1616 } | |
1617 } | |
1618 #endif | |
1619 if (b_im_ptr != NULL) | |
1620 { | |
1621 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1622 set_iminsert_global(); | |
1623 else | |
1624 set_imsearch_global(); | |
1625 } | |
1626 #ifdef CURSOR_SHAPE | |
1627 ui_cursor_shape(); /* may show different cursor shape */ | |
1628 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1629 #if defined(FEAT_KEYMAP) |
7 | 1630 /* Show/unshow value of 'keymap' in status lines later. */ |
1631 status_redraw_curbuf(); | |
1632 #endif | |
1633 goto cmdline_not_changed; | |
1634 | |
1635 /* case '@': only in very old vi */ | |
1636 case Ctrl_U: | |
1637 /* delete all characters left of the cursor */ | |
1638 j = ccline.cmdpos; | |
1639 ccline.cmdlen -= j; | |
1640 i = ccline.cmdpos = 0; | |
1641 while (i < ccline.cmdlen) | |
1642 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1643 /* Truncate at the end, required for multi-byte chars. */ | |
1644 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1645 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1646 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
|
1647 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
|
1648 #endif |
7 | 1649 redrawcmd(); |
1650 goto cmdline_changed; | |
1651 | |
1652 #ifdef FEAT_CLIPBOARD | |
1653 case Ctrl_Y: | |
1654 /* Copy the modeless selection, if there is one. */ | |
1655 if (clip_star.state != SELECT_CLEARED) | |
1656 { | |
1657 if (clip_star.state == SELECT_DONE) | |
1658 clip_copy_modeless_selection(TRUE); | |
1659 goto cmdline_not_changed; | |
1660 } | |
1661 break; | |
1662 #endif | |
1663 | |
1664 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1665 case Ctrl_C: | |
571 | 1666 /* In exmode it doesn't make sense to return. Except when |
161 | 1667 * ":normal" runs out of characters. */ |
1668 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1669 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1670 goto cmdline_not_changed; |
1671 | |
1672 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1673 putting it in history */ | |
1674 goto returncmd; /* back to cmd mode */ | |
1675 | |
1676 case Ctrl_R: /* insert register */ | |
1677 #ifdef USE_ON_FLY_SCROLL | |
1678 dont_scroll = TRUE; /* disallow scrolling here */ | |
1679 #endif | |
1680 putcmdline('"', TRUE); | |
1681 ++no_mapping; | |
1389 | 1682 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1683 if (i == Ctrl_O) |
1684 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1685 if (i == Ctrl_R) | |
1389 | 1686 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
|
1687 extra_char = NUL; |
7 | 1688 --no_mapping; |
1689 #ifdef FEAT_EVAL | |
1690 /* | |
1691 * Insert the result of an expression. | |
1692 * Need to save the current command line, to be able to enter | |
1693 * a new one... | |
1694 */ | |
1695 new_cmdpos = -1; | |
1696 if (c == '=') | |
1697 { | |
1698 if (ccline.cmdfirstc == '=')/* can't do this recursively */ | |
1699 { | |
1700 beep_flush(); | |
1701 c = ESC; | |
1702 } | |
1703 else | |
1704 { | |
95 | 1705 save_cmdline(&save_ccline); |
7 | 1706 c = get_expr_register(); |
95 | 1707 restore_cmdline(&save_ccline); |
7 | 1708 } |
1709 } | |
1710 #endif | |
1711 if (c != ESC) /* use ESC to cancel inserting register */ | |
1712 { | |
1015 | 1713 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1714 |
613 | 1715 #ifdef FEAT_EVAL |
606 | 1716 /* When there was a serious error abort getting the |
1717 * command line. */ | |
1718 if (aborting()) | |
1719 { | |
1720 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1721 putting it in history */ | |
1722 goto returncmd; /* back to cmd mode */ | |
1723 } | |
613 | 1724 #endif |
7 | 1725 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1726 #ifdef FEAT_EVAL | |
1727 if (new_cmdpos >= 0) | |
1728 { | |
1729 /* set_cmdline_pos() was used */ | |
1730 if (new_cmdpos > ccline.cmdlen) | |
1731 ccline.cmdpos = ccline.cmdlen; | |
1732 else | |
1733 ccline.cmdpos = new_cmdpos; | |
1734 } | |
1735 #endif | |
1736 } | |
1737 redrawcmd(); | |
1738 goto cmdline_changed; | |
1739 | |
1740 case Ctrl_D: | |
1741 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1742 break; /* Use ^D as normal char instead */ | |
1743 | |
1744 redrawcmd(); | |
1745 continue; /* don't do incremental search now */ | |
1746 | |
1747 case K_RIGHT: | |
1748 case K_S_RIGHT: | |
1749 case K_C_RIGHT: | |
1750 do | |
1751 { | |
1752 if (ccline.cmdpos >= ccline.cmdlen) | |
1753 break; | |
1754 i = cmdline_charsize(ccline.cmdpos); | |
1755 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1756 break; | |
1757 ccline.cmdspos += i; | |
1758 #ifdef FEAT_MBYTE | |
1759 if (has_mbyte) | |
474 | 1760 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1761 + ccline.cmdpos); |
1762 else | |
1763 #endif | |
1764 ++ccline.cmdpos; | |
1765 } | |
180 | 1766 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1767 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1768 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1769 #ifdef FEAT_MBYTE | |
1770 if (has_mbyte) | |
1771 set_cmdspos_cursor(); | |
1772 #endif | |
1773 goto cmdline_not_changed; | |
1774 | |
1775 case K_LEFT: | |
1776 case K_S_LEFT: | |
1777 case K_C_LEFT: | |
1456 | 1778 if (ccline.cmdpos == 0) |
1779 goto cmdline_not_changed; | |
7 | 1780 do |
1781 { | |
1782 --ccline.cmdpos; | |
1783 #ifdef FEAT_MBYTE | |
1784 if (has_mbyte) /* move to first byte of char */ | |
1785 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1786 ccline.cmdbuff + ccline.cmdpos); | |
1787 #endif | |
1788 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1789 } | |
1456 | 1790 while (ccline.cmdpos > 0 |
1791 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1792 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1793 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1794 #ifdef FEAT_MBYTE | |
1795 if (has_mbyte) | |
1796 set_cmdspos_cursor(); | |
1797 #endif | |
1798 goto cmdline_not_changed; | |
1799 | |
1800 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
|
1801 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1802 goto cmdline_not_changed; |
7 | 1803 |
625 | 1804 #ifdef FEAT_GUI_W32 |
1805 /* On Win32 ignore <M-F4>, we get it when closing the window was | |
1806 * cancelled. */ | |
1807 case K_F4: | |
1808 if (mod_mask == MOD_MASK_ALT) | |
1809 { | |
1810 redrawcmd(); /* somehow the cmdline is cleared */ | |
1811 goto cmdline_not_changed; | |
1812 } | |
1813 break; | |
1814 #endif | |
1815 | |
7 | 1816 #ifdef FEAT_MOUSE |
1817 case K_MIDDLEDRAG: | |
1818 case K_MIDDLERELEASE: | |
1819 goto cmdline_not_changed; /* Ignore mouse */ | |
1820 | |
1821 case K_MIDDLEMOUSE: | |
1822 # ifdef FEAT_GUI | |
1823 /* When GUI is active, also paste when 'mouse' is empty */ | |
1824 if (!gui.in_use) | |
1825 # endif | |
1826 if (!mouse_has(MOUSE_COMMAND)) | |
1827 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1828 # ifdef FEAT_CLIPBOARD |
7 | 1829 if (clip_star.available) |
1015 | 1830 cmdline_paste('*', TRUE, TRUE); |
7 | 1831 else |
692 | 1832 # endif |
1015 | 1833 cmdline_paste(0, TRUE, TRUE); |
7 | 1834 redrawcmd(); |
1835 goto cmdline_changed; | |
1836 | |
692 | 1837 # ifdef FEAT_DND |
7 | 1838 case K_DROP: |
1015 | 1839 cmdline_paste('~', TRUE, FALSE); |
7 | 1840 redrawcmd(); |
1841 goto cmdline_changed; | |
692 | 1842 # endif |
7 | 1843 |
1844 case K_LEFTDRAG: | |
1845 case K_LEFTRELEASE: | |
1846 case K_RIGHTDRAG: | |
1847 case K_RIGHTRELEASE: | |
1848 /* Ignore drag and release events when the button-down wasn't | |
1849 * seen before. */ | |
1850 if (ignore_drag_release) | |
1851 goto cmdline_not_changed; | |
1852 /* FALLTHROUGH */ | |
1853 case K_LEFTMOUSE: | |
1854 case K_RIGHTMOUSE: | |
1855 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1856 ignore_drag_release = TRUE; | |
1857 else | |
1858 ignore_drag_release = FALSE; | |
1859 # ifdef FEAT_GUI | |
1860 /* When GUI is active, also move when 'mouse' is empty */ | |
1861 if (!gui.in_use) | |
1862 # endif | |
1863 if (!mouse_has(MOUSE_COMMAND)) | |
1864 goto cmdline_not_changed; /* Ignore mouse */ | |
1865 # ifdef FEAT_CLIPBOARD | |
1866 if (mouse_row < cmdline_row && clip_star.available) | |
1867 { | |
1868 int button, is_click, is_drag; | |
1869 | |
1870 /* | |
1871 * Handle modeless selection. | |
1872 */ | |
1873 button = get_mouse_button(KEY2TERMCAP1(c), | |
1874 &is_click, &is_drag); | |
1875 if (mouse_model_popup() && button == MOUSE_LEFT | |
1876 && (mod_mask & MOD_MASK_SHIFT)) | |
1877 { | |
1878 /* Translate shift-left to right button. */ | |
1879 button = MOUSE_RIGHT; | |
1880 mod_mask &= ~MOD_MASK_SHIFT; | |
1881 } | |
1882 clip_modeless(button, is_click, is_drag); | |
1883 goto cmdline_not_changed; | |
1884 } | |
1885 # endif | |
1886 | |
1887 set_cmdspos(); | |
1888 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1889 ++ccline.cmdpos) | |
1890 { | |
1891 i = cmdline_charsize(ccline.cmdpos); | |
1892 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1893 && mouse_col < ccline.cmdspos % Columns + i) | |
1894 break; | |
692 | 1895 # ifdef FEAT_MBYTE |
7 | 1896 if (has_mbyte) |
1897 { | |
1898 /* Count ">" for double-wide char that doesn't fit. */ | |
1899 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1900 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1901 + ccline.cmdpos) - 1; |
1902 } | |
692 | 1903 # endif |
7 | 1904 ccline.cmdspos += i; |
1905 } | |
1906 goto cmdline_not_changed; | |
1907 | |
1908 /* Mouse scroll wheel: ignored here */ | |
1909 case K_MOUSEDOWN: | |
1910 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1911 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1912 case K_MOUSERIGHT: |
7 | 1913 /* Alternate buttons ignored here */ |
1914 case K_X1MOUSE: | |
1915 case K_X1DRAG: | |
1916 case K_X1RELEASE: | |
1917 case K_X2MOUSE: | |
1918 case K_X2DRAG: | |
1919 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1920 case K_MOUSEMOVE: |
7 | 1921 goto cmdline_not_changed; |
1922 | |
1923 #endif /* FEAT_MOUSE */ | |
1924 | |
1925 #ifdef FEAT_GUI | |
1926 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
1927 case K_LEFTRELEASE_NM: | |
1928 goto cmdline_not_changed; | |
1929 | |
1930 case K_VER_SCROLLBAR: | |
540 | 1931 if (msg_scrolled == 0) |
7 | 1932 { |
1933 gui_do_scroll(); | |
1934 redrawcmd(); | |
1935 } | |
1936 goto cmdline_not_changed; | |
1937 | |
1938 case K_HOR_SCROLLBAR: | |
540 | 1939 if (msg_scrolled == 0) |
7 | 1940 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1941 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 1942 redrawcmd(); |
1943 } | |
1944 goto cmdline_not_changed; | |
1945 #endif | |
692 | 1946 #ifdef FEAT_GUI_TABLINE |
1947 case K_TABLINE: | |
1948 case K_TABMENU: | |
1949 /* Don't want to change any tabs here. Make sure the same tab | |
1950 * is still selected. */ | |
1951 if (gui_use_tabline()) | |
1952 gui_mch_set_curtab(tabpage_index(curtab)); | |
1953 goto cmdline_not_changed; | |
1954 #endif | |
1955 | |
7 | 1956 case K_SELECT: /* end of Select mode mapping - ignore */ |
1957 goto cmdline_not_changed; | |
1958 | |
1959 case Ctrl_B: /* begin of command line */ | |
1960 case K_HOME: | |
1961 case K_KHOME: | |
1962 case K_S_HOME: | |
1963 case K_C_HOME: | |
1964 ccline.cmdpos = 0; | |
1965 set_cmdspos(); | |
1966 goto cmdline_not_changed; | |
1967 | |
1968 case Ctrl_E: /* end of command line */ | |
1969 case K_END: | |
1970 case K_KEND: | |
1971 case K_S_END: | |
1972 case K_C_END: | |
1973 ccline.cmdpos = ccline.cmdlen; | |
1974 set_cmdspos_cursor(); | |
1975 goto cmdline_not_changed; | |
1976 | |
1977 case Ctrl_A: /* all matches */ | |
3961 | 1978 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 1979 break; |
1980 goto cmdline_changed; | |
1981 | |
772 | 1982 case Ctrl_L: |
1983 #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
|
1984 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 1985 goto cmdline_not_changed; |
1986 #endif | |
1987 | |
1988 /* completion: longest common part */ | |
3961 | 1989 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 1990 break; |
1991 goto cmdline_changed; | |
1992 | |
1993 case Ctrl_N: /* next match */ | |
1994 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
1995 if (xpc.xp_numfiles > 0) |
7 | 1996 { |
3961 | 1997 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
1998 0, firstc != '@') == FAIL) | |
7 | 1999 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2000 goto cmdline_not_changed; |
7 | 2001 } |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12664
diff
changeset
|
2002 #ifdef FEAT_CMDHIST |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2003 /* FALLTHROUGH */ |
7 | 2004 case K_UP: |
2005 case K_DOWN: | |
2006 case K_S_UP: | |
2007 case K_S_DOWN: | |
2008 case K_PAGEUP: | |
2009 case K_KPAGEUP: | |
2010 case K_PAGEDOWN: | |
2011 case K_KPAGEDOWN: | |
2012 if (hislen == 0 || firstc == NUL) /* no history */ | |
2013 goto cmdline_not_changed; | |
2014 | |
2015 i = hiscnt; | |
2016 | |
2017 /* save current command string so it can be restored later */ | |
2018 if (lookfor == NULL) | |
2019 { | |
2020 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2021 goto cmdline_not_changed; | |
2022 lookfor[ccline.cmdpos] = NUL; | |
2023 } | |
2024 | |
2025 j = (int)STRLEN(lookfor); | |
2026 for (;;) | |
2027 { | |
2028 /* one step backwards */ | |
230 | 2029 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2030 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2031 { |
2032 if (hiscnt == hislen) /* first time */ | |
2033 hiscnt = hisidx[histype]; | |
2034 else if (hiscnt == 0 && hisidx[histype] != hislen - 1) | |
2035 hiscnt = hislen - 1; | |
2036 else if (hiscnt != hisidx[histype] + 1) | |
2037 --hiscnt; | |
2038 else /* at top of list */ | |
2039 { | |
2040 hiscnt = i; | |
2041 break; | |
2042 } | |
2043 } | |
2044 else /* one step forwards */ | |
2045 { | |
2046 /* on last entry, clear the line */ | |
2047 if (hiscnt == hisidx[histype]) | |
2048 { | |
2049 hiscnt = hislen; | |
2050 break; | |
2051 } | |
2052 | |
2053 /* not on a history line, nothing to do */ | |
2054 if (hiscnt == hislen) | |
2055 break; | |
2056 if (hiscnt == hislen - 1) /* wrap around */ | |
2057 hiscnt = 0; | |
2058 else | |
2059 ++hiscnt; | |
2060 } | |
2061 if (hiscnt < 0 || history[histype][hiscnt].hisstr == NULL) | |
2062 { | |
2063 hiscnt = i; | |
2064 break; | |
2065 } | |
230 | 2066 if ((c != K_UP && c != K_DOWN) |
180 | 2067 || hiscnt == i |
7 | 2068 || STRNCMP(history[histype][hiscnt].hisstr, |
2069 lookfor, (size_t)j) == 0) | |
2070 break; | |
2071 } | |
2072 | |
2073 if (hiscnt != i) /* jumped to other entry */ | |
2074 { | |
2075 char_u *p; | |
2076 int len; | |
2077 int old_firstc; | |
2078 | |
2079 vim_free(ccline.cmdbuff); | |
1718 | 2080 xpc.xp_context = EXPAND_NOTHING; |
7 | 2081 if (hiscnt == hislen) |
2082 p = lookfor; /* back to the old one */ | |
2083 else | |
2084 p = history[histype][hiscnt].hisstr; | |
2085 | |
2086 if (histype == HIST_SEARCH | |
2087 && p != lookfor | |
2088 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2089 { | |
2090 /* Correct for the separator character used when | |
2091 * adding the history entry vs the one used now. | |
2092 * First loop: count length. | |
2093 * Second loop: copy the characters. */ | |
2094 for (i = 0; i <= 1; ++i) | |
2095 { | |
2096 len = 0; | |
2097 for (j = 0; p[j] != NUL; ++j) | |
2098 { | |
2099 /* Replace old sep with new sep, unless it is | |
2100 * escaped. */ | |
2101 if (p[j] == old_firstc | |
2102 && (j == 0 || p[j - 1] != '\\')) | |
2103 { | |
2104 if (i > 0) | |
2105 ccline.cmdbuff[len] = firstc; | |
2106 } | |
2107 else | |
2108 { | |
2109 /* Escape new sep, unless it is already | |
2110 * escaped. */ | |
2111 if (p[j] == firstc | |
2112 && (j == 0 || p[j - 1] != '\\')) | |
2113 { | |
2114 if (i > 0) | |
2115 ccline.cmdbuff[len] = '\\'; | |
2116 ++len; | |
2117 } | |
2118 if (i > 0) | |
2119 ccline.cmdbuff[len] = p[j]; | |
2120 } | |
2121 ++len; | |
2122 } | |
2123 if (i == 0) | |
2124 { | |
2125 alloc_cmdbuff(len); | |
2126 if (ccline.cmdbuff == NULL) | |
2127 goto returncmd; | |
2128 } | |
2129 } | |
2130 ccline.cmdbuff[len] = NUL; | |
2131 } | |
2132 else | |
2133 { | |
2134 alloc_cmdbuff((int)STRLEN(p)); | |
2135 if (ccline.cmdbuff == NULL) | |
2136 goto returncmd; | |
2137 STRCPY(ccline.cmdbuff, p); | |
2138 } | |
2139 | |
2140 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2141 redrawcmd(); | |
2142 goto cmdline_changed; | |
2143 } | |
2144 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2145 #endif |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2146 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2147 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2148 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2149 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2150 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
|
2151 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
|
2152 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
|
2153 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2154 break; |
7 | 2155 #endif |
2156 | |
2157 case Ctrl_V: | |
2158 case Ctrl_Q: | |
2159 #ifdef FEAT_MOUSE | |
2160 ignore_drag_release = TRUE; | |
2161 #endif | |
2162 putcmdline('^', TRUE); | |
2163 c = get_literal(); /* get next (two) character(s) */ | |
2164 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
|
2165 extra_char = NUL; |
7 | 2166 #ifdef FEAT_MBYTE |
2167 /* may need to remove ^ when composing char was typed */ | |
2168 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2169 { | |
2170 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2171 msg_putchar(' '); | |
2172 cursorcmd(); | |
2173 } | |
2174 #endif | |
2175 break; | |
2176 | |
2177 #ifdef FEAT_DIGRAPHS | |
2178 case Ctrl_K: | |
2179 #ifdef FEAT_MOUSE | |
2180 ignore_drag_release = TRUE; | |
2181 #endif | |
2182 putcmdline('?', TRUE); | |
2183 #ifdef USE_ON_FLY_SCROLL | |
2184 dont_scroll = TRUE; /* disallow scrolling here */ | |
2185 #endif | |
2186 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
|
2187 extra_char = NUL; |
7 | 2188 if (c != NUL) |
2189 break; | |
2190 | |
2191 redrawcmd(); | |
2192 goto cmdline_not_changed; | |
2193 #endif /* FEAT_DIGRAPHS */ | |
2194 | |
2195 #ifdef FEAT_RIGHTLEFT | |
2196 case Ctrl__: /* CTRL-_: switch language mode */ | |
2197 if (!p_ari) | |
2198 break; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2199 # ifdef FEAT_FKMAP |
7 | 2200 if (p_altkeymap) |
2201 { | |
2202 cmd_fkmap = !cmd_fkmap; | |
2203 if (cmd_fkmap) /* in Farsi always in Insert mode */ | |
2204 ccline.overstrike = FALSE; | |
2205 } | |
2206 else /* Hebrew is default */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2207 # endif |
7 | 2208 cmd_hkmap = !cmd_hkmap; |
2209 goto cmdline_not_changed; | |
2210 #endif | |
2211 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2212 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
|
2213 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
|
2214 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
|
2215 |
7 | 2216 default: |
2217 #ifdef UNIX | |
2218 if (c == intr_char) | |
2219 { | |
2220 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2221 putting it in history */ | |
2222 goto returncmd; /* back to Normal mode */ | |
2223 } | |
2224 #endif | |
2225 /* | |
2226 * Normal character with no special meaning. Just set mod_mask | |
2227 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2228 * the string <S-Space>. This should only happen after ^V. | |
2229 */ | |
2230 if (!IS_SPECIAL(c)) | |
2231 mod_mask = 0x0; | |
2232 break; | |
2233 } | |
2234 /* | |
2235 * End of switch on command line character. | |
2236 * We come here if we have a normal character. | |
2237 */ | |
2238 | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2239 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) && (ccheck_abbr( |
7 | 2240 #ifdef FEAT_MBYTE |
2241 /* Add ABBR_OFF for characters above 0x100, this is | |
2242 * what check_abbr() expects. */ | |
2243 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : | |
2244 #endif | |
4980
9ae0fe467776
updated for version 7.3.1235
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
2245 c) || c == Ctrl_RSB)) |
7 | 2246 goto cmdline_changed; |
2247 | |
2248 /* | |
2249 * put the character in the command line | |
2250 */ | |
2251 if (IS_SPECIAL(c) || mod_mask != 0) | |
2252 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2253 else | |
2254 { | |
2255 #ifdef FEAT_MBYTE | |
2256 if (has_mbyte) | |
2257 { | |
2258 j = (*mb_char2bytes)(c, IObuff); | |
2259 IObuff[j] = NUL; /* exclude composing chars */ | |
2260 put_on_cmdline(IObuff, j, TRUE); | |
2261 } | |
2262 else | |
2263 #endif | |
2264 { | |
2265 IObuff[0] = c; | |
2266 put_on_cmdline(IObuff, 1, TRUE); | |
2267 } | |
2268 } | |
2269 goto cmdline_changed; | |
2270 | |
2271 /* | |
2272 * This part implements incremental searches for "/" and "?" | |
2273 * Jump to cmdline_not_changed when a character has been read but the command | |
2274 * line did not change. Then we only search and redraw if something changed in | |
2275 * the past. | |
2276 * Jump to cmdline_changed when the command line did change. | |
2277 * (Sorry for the goto's, I know it is ugly). | |
2278 */ | |
2279 cmdline_not_changed: | |
2280 #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
|
2281 if (!is_state.incsearch_postponed) |
7 | 2282 continue; |
2283 #endif | |
2284 | |
2285 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
|
2286 /* 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
|
2287 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
|
2288 |
7 | 2289 #ifdef FEAT_SEARCH_EXTRA |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2290 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2291 #endif |
2292 | |
2293 #ifdef FEAT_RIGHTLEFT | |
2294 if (cmdmsg_rl | |
2295 # ifdef FEAT_ARABIC | |
534 | 2296 || (p_arshape && !p_tbidi && enc_utf8) |
7 | 2297 # endif |
2298 ) | |
2299 /* Always redraw the whole command line to fix shaping and | |
3374 | 2300 * right-left typing. Not efficient, but it works. |
2301 * Do it only when there are no characters left to read | |
2302 * to avoid useless intermediate redraws. */ | |
2303 if (vpeekc() == NUL) | |
2304 redrawcmd(); | |
7 | 2305 #endif |
2306 } | |
2307 | |
2308 returncmd: | |
2309 | |
2310 #ifdef FEAT_RIGHTLEFT | |
2311 cmdmsg_rl = FALSE; | |
2312 #endif | |
2313 | |
2314 #ifdef FEAT_FKMAP | |
2315 cmd_fkmap = 0; | |
2316 #endif | |
2317 | |
2318 ExpandCleanup(&xpc); | |
1718 | 2319 ccline.xpc = NULL; |
7 | 2320 |
2321 #ifdef FEAT_SEARCH_EXTRA | |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
2322 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2323 #endif |
2324 | |
2325 if (ccline.cmdbuff != NULL) | |
2326 { | |
2327 /* | |
2328 * Put line in history buffer (":" and "=" only when it was typed). | |
2329 */ | |
2330 #ifdef FEAT_CMDHIST | |
2331 if (ccline.cmdlen && firstc != NUL | |
2332 && (some_key_typed || histype == HIST_SEARCH)) | |
2333 { | |
2334 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2335 histype == HIST_SEARCH ? firstc : NUL); | |
2336 if (firstc == ':') | |
2337 { | |
2338 vim_free(new_last_cmdline); | |
2339 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2340 } | |
2341 } | |
2342 #endif | |
2343 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2344 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
|
2345 abandon_cmdline(); |
7 | 2346 } |
2347 | |
2348 /* | |
2349 * If the screen was shifted up, redraw the whole screen (later). | |
2350 * If the line is too long, clear it, so ruler and shown command do | |
2351 * not get printed in the middle of it. | |
2352 */ | |
2353 msg_check(); | |
2354 msg_scroll = save_msg_scroll; | |
2355 redir_off = FALSE; | |
2356 | |
2357 /* When the command line was typed, no need for a wait-return prompt. */ | |
2358 if (some_key_typed) | |
2359 need_wait_return = FALSE; | |
2360 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2361 /* 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
|
2362 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
|
2363 |
7 | 2364 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2365 #ifdef HAVE_INPUT_METHOD |
7 | 2366 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2367 im_save_status(b_im_ptr); | |
2368 im_set_active(FALSE); | |
2369 #endif | |
2370 #ifdef FEAT_MOUSE | |
2371 setmouse(); | |
2372 #endif | |
2373 #ifdef CURSOR_SHAPE | |
2374 ui_cursor_shape(); /* may show different cursor shape */ | |
2375 #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
|
2376 sb_text_end_cmdline(); |
7 | 2377 |
95 | 2378 { |
2379 char_u *p = ccline.cmdbuff; | |
2380 | |
2381 /* Make ccline empty, getcmdline() may try to use it. */ | |
2382 ccline.cmdbuff = NULL; | |
2383 return p; | |
2384 } | |
7 | 2385 } |
2386 | |
2387 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2388 /* | |
2389 * Get a command line with a prompt. | |
2390 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2391 * f_input() when evaluating an expression from CTRL-R =). | |
2392 * Returns the command line in allocated memory, or NULL. | |
2393 */ | |
2394 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2395 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2396 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2397 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2398 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2399 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2400 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2401 { |
2402 char_u *s; | |
2403 struct cmdline_info save_ccline; | |
2404 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
|
2405 int msg_silent_save = msg_silent; |
7 | 2406 |
95 | 2407 save_cmdline(&save_ccline); |
7 | 2408 ccline.cmdprompt = prompt; |
2409 ccline.cmdattr = attr; | |
531 | 2410 # ifdef FEAT_EVAL |
2411 ccline.xp_context = xp_context; | |
2412 ccline.xp_arg = xp_arg; | |
2413 ccline.input_fn = (firstc == '@'); | |
2414 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2415 msg_silent = 0; |
7 | 2416 s = getcmdline(firstc, 1L, 0); |
95 | 2417 restore_cmdline(&save_ccline); |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2418 msg_silent = msg_silent_save; |
3020 | 2419 /* Restore msg_col, the prompt from input() may have changed it. |
2420 * But only if called recursively and the commandline is therefore being | |
2421 * restored to an old one; if not, the input() prompt stays on the screen, | |
2422 * so we need its modified msg_col left intact. */ | |
2423 if (ccline.cmdbuff != NULL) | |
2424 msg_col = msg_col_save; | |
7 | 2425 |
2426 return s; | |
2427 } | |
2428 #endif | |
2429 | |
632 | 2430 /* |
634 | 2431 * Return TRUE when the text must not be changed and we can't switch to |
2432 * another window or buffer. Used when editing the command line, evaluating | |
2433 * 'balloonexpr', etc. | |
632 | 2434 */ |
2435 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2436 text_locked(void) |
632 | 2437 { |
2438 #ifdef FEAT_CMDWIN | |
2439 if (cmdwin_type != 0) | |
2440 return TRUE; | |
2441 #endif | |
634 | 2442 return textlock != 0; |
632 | 2443 } |
2444 | |
2445 /* | |
2446 * Give an error message for a command that isn't allowed while the cmdline | |
2447 * window is open or editing the cmdline in another way. | |
2448 */ | |
2449 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2450 text_locked_msg(void) |
632 | 2451 { |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2452 EMSG(_(get_text_locked_msg())); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2453 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2454 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2455 char_u * |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2456 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2457 { |
632 | 2458 #ifdef FEAT_CMDWIN |
2459 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2460 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2461 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2462 return e_secure; |
632 | 2463 } |
2464 | |
819 | 2465 /* |
1834 | 2466 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2467 * and give an error message. | |
819 | 2468 */ |
2469 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2470 curbuf_locked(void) |
819 | 2471 { |
2472 if (curbuf_lock > 0) | |
2473 { | |
2474 EMSG(_("E788: Not allowed to edit another buffer now")); | |
2475 return TRUE; | |
2476 } | |
1834 | 2477 return allbuf_locked(); |
2478 } | |
2479 | |
2480 /* | |
2481 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2482 * message. | |
2483 */ | |
2484 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2485 allbuf_locked(void) |
1834 | 2486 { |
2487 if (allbuf_lock > 0) | |
2488 { | |
2489 EMSG(_("E811: Not allowed to change buffer information now")); | |
2490 return TRUE; | |
2491 } | |
819 | 2492 return FALSE; |
2493 } | |
2494 | |
7 | 2495 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2496 cmdline_charsize(int idx) |
7 | 2497 { |
2498 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2499 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2500 return 1; | |
2501 #endif | |
2502 return ptr2cells(ccline.cmdbuff + idx); | |
2503 } | |
2504 | |
2505 /* | |
2506 * Compute the offset of the cursor on the command line for the prompt and | |
2507 * indent. | |
2508 */ | |
2509 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2510 set_cmdspos(void) |
7 | 2511 { |
531 | 2512 if (ccline.cmdfirstc != NUL) |
7 | 2513 ccline.cmdspos = 1 + ccline.cmdindent; |
2514 else | |
2515 ccline.cmdspos = 0 + ccline.cmdindent; | |
2516 } | |
2517 | |
2518 /* | |
2519 * Compute the screen position for the cursor on the command line. | |
2520 */ | |
2521 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2522 set_cmdspos_cursor(void) |
7 | 2523 { |
2524 int i, m, c; | |
2525 | |
2526 set_cmdspos(); | |
2527 if (KeyTyped) | |
534 | 2528 { |
7 | 2529 m = Columns * Rows; |
534 | 2530 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2531 m = MAXCOL; | |
2532 } | |
7 | 2533 else |
2534 m = MAXCOL; | |
2535 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2536 { | |
2537 c = cmdline_charsize(i); | |
2538 #ifdef FEAT_MBYTE | |
2539 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2540 if (has_mbyte) | |
2541 correct_cmdspos(i, c); | |
2542 #endif | |
1612 | 2543 /* If the cmdline doesn't fit, show cursor on last visible char. |
2544 * Don't move the cursor itself, so we can still append. */ | |
7 | 2545 if ((ccline.cmdspos += c) >= m) |
2546 { | |
2547 ccline.cmdspos -= c; | |
2548 break; | |
2549 } | |
2550 #ifdef FEAT_MBYTE | |
2551 if (has_mbyte) | |
474 | 2552 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2553 #endif |
2554 } | |
2555 } | |
2556 | |
2557 #ifdef FEAT_MBYTE | |
2558 /* | |
2559 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2560 * character that doesn't fit, so that a ">" must be displayed. | |
2561 */ | |
2562 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2563 correct_cmdspos(int idx, int cells) |
7 | 2564 { |
474 | 2565 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2566 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2567 && ccline.cmdspos % Columns + cells > Columns) | |
2568 ccline.cmdspos++; | |
2569 } | |
2570 #endif | |
2571 | |
2572 /* | |
2573 * Get an Ex command line for the ":" command. | |
2574 */ | |
2575 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2576 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2577 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2578 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2579 int indent) /* indent for inside conditionals */ |
7 | 2580 { |
2581 /* When executing a register, remove ':' that's in front of each line. */ | |
2582 if (exec_from_reg && vpeekc() == ':') | |
2583 (void)vgetc(); | |
2584 return getcmdline(c, 1L, indent); | |
2585 } | |
2586 | |
2587 /* | |
2588 * Get an Ex command line for Ex mode. | |
2589 * In Ex mode we only use the OS supplied line editing features and no | |
2590 * mappings or abbreviations. | |
168 | 2591 * Returns a string in allocated memory or NULL. |
7 | 2592 */ |
2593 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2594 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2595 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2596 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2597 void *cookie UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2598 int indent) /* indent for inside conditionals */ |
7 | 2599 { |
168 | 2600 garray_T line_ga; |
2601 char_u *pend; | |
2602 int startcol = 0; | |
1329 | 2603 int c1 = 0; |
168 | 2604 int escaped = FALSE; /* CTRL-V typed */ |
2605 int vcol = 0; | |
2606 char_u *p; | |
1329 | 2607 int prev_char; |
5966 | 2608 int len; |
7 | 2609 |
2610 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2611 * confuses the system function that computes tabstops. */ | |
2612 cursor_on(); | |
2613 | |
2614 /* always start in column 0; write a newline if necessary */ | |
2615 compute_cmdrow(); | |
168 | 2616 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2617 msg_putchar('\n'); |
168 | 2618 if (promptc == ':') |
7 | 2619 { |
164 | 2620 /* indent that is only displayed, not in the line itself */ |
168 | 2621 if (p_prompt) |
2622 msg_putchar(':'); | |
7 | 2623 while (indent-- > 0) |
2624 msg_putchar(' '); | |
2625 startcol = msg_col; | |
2626 } | |
2627 | |
2628 ga_init2(&line_ga, 1, 30); | |
2629 | |
164 | 2630 /* autoindent for :insert and :append is in the line itself */ |
168 | 2631 if (promptc <= 0) |
164 | 2632 { |
2633 vcol = indent; | |
2634 while (indent >= 8) | |
2635 { | |
2636 ga_append(&line_ga, TAB); | |
2637 msg_puts((char_u *)" "); | |
2638 indent -= 8; | |
2639 } | |
2640 while (indent-- > 0) | |
2641 { | |
2642 ga_append(&line_ga, ' '); | |
2643 msg_putchar(' '); | |
2644 } | |
2645 } | |
168 | 2646 ++no_mapping; |
2647 ++allow_keys; | |
164 | 2648 |
7 | 2649 /* |
2650 * Get the line, one character at a time. | |
2651 */ | |
2652 got_int = FALSE; | |
168 | 2653 while (!got_int) |
7 | 2654 { |
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
|
2655 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
|
2656 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
|
2657 |
7 | 2658 if (ga_grow(&line_ga, 40) == FAIL) |
2659 break; | |
2660 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2661 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2662 * 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
|
2663 */ |
1329 | 2664 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
|
2665 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2666 /* 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
|
2667 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
|
2668 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
|
2669 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2670 c1 = vgetc(); |
7 | 2671 |
2672 /* | |
168 | 2673 * Handle line editing. |
2674 * Previously this was left to the system, putting the terminal in | |
2675 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2676 */ |
168 | 2677 if (got_int) |
2678 { | |
2679 msg_putchar('\n'); | |
2680 break; | |
2681 } | |
2682 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2683 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
|
2684 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2685 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
|
2686 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
|
2687 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2688 |
168 | 2689 if (!escaped) |
7 | 2690 { |
168 | 2691 /* CR typed means "enter", which is NL */ |
2692 if (c1 == '\r') | |
2693 c1 = '\n'; | |
2694 | |
2695 if (c1 == BS || c1 == K_BS | |
2696 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2697 { |
168 | 2698 if (line_ga.ga_len > 0) |
2699 { | |
5966 | 2700 #ifdef FEAT_MBYTE |
2701 if (has_mbyte) | |
2702 { | |
2703 p = (char_u *)line_ga.ga_data; | |
2704 p[line_ga.ga_len] = NUL; | |
2705 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2706 line_ga.ga_len -= len; | |
2707 } | |
2708 else | |
2709 #endif | |
2710 --line_ga.ga_len; | |
168 | 2711 goto redraw; |
2712 } | |
2713 continue; | |
7 | 2714 } |
2715 | |
168 | 2716 if (c1 == Ctrl_U) |
7 | 2717 { |
168 | 2718 msg_col = startcol; |
2719 msg_clr_eos(); | |
2720 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
|
2721 goto redraw; |
168 | 2722 } |
2723 | |
2724 if (c1 == Ctrl_T) | |
2725 { | |
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
|
2726 sw = get_sw_value(curbuf); |
168 | 2727 p = (char_u *)line_ga.ga_data; |
2728 p[line_ga.ga_len] = NUL; | |
5995 | 2729 indent = get_indent_str(p, 8, FALSE); |
3740 | 2730 indent += sw - indent % sw; |
168 | 2731 add_indent: |
5995 | 2732 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2733 { |
7009 | 2734 (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
|
2735 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
|
2736 s = skipwhite(p); |
168 | 2737 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2738 *s = ' '; | |
2739 ++line_ga.ga_len; | |
7 | 2740 } |
168 | 2741 redraw: |
2742 /* redraw the line */ | |
2743 msg_col = startcol; | |
2744 vcol = 0; | |
5966 | 2745 p = (char_u *)line_ga.ga_data; |
2746 p[line_ga.ga_len] = NUL; | |
2747 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2748 { |
168 | 2749 if (*p == TAB) |
7 | 2750 { |
168 | 2751 do |
7 | 2752 { |
168 | 2753 msg_putchar(' '); |
2754 } while (++vcol % 8); | |
5966 | 2755 ++p; |
7 | 2756 } |
168 | 2757 else |
164 | 2758 { |
5966 | 2759 len = MB_PTR2LEN(p); |
2760 msg_outtrans_len(p, len); | |
2761 vcol += ptr2cells(p); | |
2762 p += len; | |
7 | 2763 } |
2764 } | |
168 | 2765 msg_clr_eos(); |
1329 | 2766 windgoto(msg_row, msg_col); |
168 | 2767 continue; |
2768 } | |
2769 | |
2770 if (c1 == Ctrl_D) | |
2771 { | |
2772 /* Delete one shiftwidth. */ | |
2773 p = (char_u *)line_ga.ga_data; | |
2774 if (prev_char == '0' || prev_char == '^') | |
7 | 2775 { |
168 | 2776 if (prev_char == '^') |
2777 ex_keep_indent = TRUE; | |
2778 indent = 0; | |
2779 p[--line_ga.ga_len] = NUL; | |
7 | 2780 } |
2781 else | |
2782 { | |
168 | 2783 p[line_ga.ga_len] = NUL; |
5995 | 2784 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
|
2785 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
|
2786 { |
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
|
2787 --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
|
2788 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
|
2789 } |
168 | 2790 } |
5995 | 2791 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2792 { |
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
|
2793 s = skipwhite(p); |
168 | 2794 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2795 --line_ga.ga_len; | |
7 | 2796 } |
168 | 2797 goto add_indent; |
2798 } | |
2799 | |
2800 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2801 { | |
2802 escaped = TRUE; | |
2803 continue; | |
7 | 2804 } |
168 | 2805 |
2806 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2807 if (IS_SPECIAL(c1)) | |
2808 continue; | |
7 | 2809 } |
168 | 2810 |
2811 if (IS_SPECIAL(c1)) | |
2812 c1 = '?'; | |
5966 | 2813 #ifdef FEAT_MBYTE |
2814 if (has_mbyte) | |
2815 len = (*mb_char2bytes)(c1, | |
2816 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2817 else | |
2818 #endif | |
2819 { | |
2820 len = 1; | |
2821 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2822 } | |
168 | 2823 if (c1 == '\n') |
2824 msg_putchar('\n'); | |
2825 else if (c1 == TAB) | |
2826 { | |
2827 /* Don't use chartabsize(), 'ts' can be different */ | |
2828 do | |
2829 { | |
2830 msg_putchar(' '); | |
2831 } while (++vcol % 8); | |
2832 } | |
7 | 2833 else |
2834 { | |
168 | 2835 msg_outtrans_len( |
5966 | 2836 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2837 vcol += char2cells(c1); |
7 | 2838 } |
5966 | 2839 line_ga.ga_len += len; |
168 | 2840 escaped = FALSE; |
2841 | |
2842 windgoto(msg_row, msg_col); | |
164 | 2843 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2844 |
2590 | 2845 /* We are done when a NL is entered, but not when it comes after an |
2846 * odd number of backslashes, that results in a NUL. */ | |
2847 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2848 { |
2590 | 2849 int bcount = 0; |
2850 | |
2851 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2852 ++bcount; | |
2853 | |
2854 if (bcount > 0) | |
2855 { | |
2856 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2857 * "\NL", etc. */ | |
2858 line_ga.ga_len -= (bcount + 1) / 2; | |
2859 pend -= (bcount + 1) / 2; | |
2860 pend[-1] = '\n'; | |
2861 } | |
2862 | |
2863 if ((bcount & 1) == 0) | |
2864 { | |
2865 --line_ga.ga_len; | |
2866 --pend; | |
2867 *pend = NUL; | |
2868 break; | |
2869 } | |
7 | 2870 } |
2871 } | |
2872 | |
168 | 2873 --no_mapping; |
2874 --allow_keys; | |
2875 | |
7 | 2876 /* make following messages go to the next line */ |
2877 msg_didout = FALSE; | |
2878 msg_col = 0; | |
2879 if (msg_row < Rows - 1) | |
2880 ++msg_row; | |
2881 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2882 | |
2883 if (got_int) | |
2884 ga_clear(&line_ga); | |
2885 | |
2886 return (char_u *)line_ga.ga_data; | |
2887 } | |
2888 | |
502 | 2889 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2890 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2891 /* |
2892 * Return TRUE if ccline.overstrike is on. | |
2893 */ | |
2894 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2895 cmdline_overstrike(void) |
7 | 2896 { |
2897 return ccline.overstrike; | |
2898 } | |
2899 | |
2900 /* | |
2901 * Return TRUE if the cursor is at the end of the cmdline. | |
2902 */ | |
2903 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2904 cmdline_at_end(void) |
7 | 2905 { |
2906 return (ccline.cmdpos >= ccline.cmdlen); | |
2907 } | |
2908 #endif | |
2909 | |
574 | 2910 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2911 /* |
2912 * Return the virtual column number at the current cursor position. | |
2913 * This is used by the IM code to obtain the start of the preedit string. | |
2914 */ | |
2915 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2916 cmdline_getvcol_cursor(void) |
7 | 2917 { |
2918 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2919 return MAXCOL; | |
2920 | |
2921 # ifdef FEAT_MBYTE | |
2922 if (has_mbyte) | |
2923 { | |
2924 colnr_T col; | |
2925 int i = 0; | |
2926 | |
2927 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 2928 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 2929 |
2930 return col; | |
2931 } | |
2932 else | |
2933 # endif | |
2934 return ccline.cmdpos; | |
2935 } | |
2936 #endif | |
2937 | |
2938 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
2939 /* | |
2940 * If part of the command line is an IM preedit string, redraw it with | |
2941 * IM feedback attributes. The cursor position is restored after drawing. | |
2942 */ | |
2943 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2944 redrawcmd_preedit(void) |
7 | 2945 { |
2946 if ((State & CMDLINE) | |
2947 && xic != NULL | |
976 | 2948 /* && im_get_status() doesn't work when using SCIM */ |
7 | 2949 && !p_imdisable |
2950 && im_is_preediting()) | |
2951 { | |
2952 int cmdpos = 0; | |
2953 int cmdspos; | |
2954 int old_row; | |
2955 int old_col; | |
2956 colnr_T col; | |
2957 | |
2958 old_row = msg_row; | |
2959 old_col = msg_col; | |
531 | 2960 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 2961 |
2962 # ifdef FEAT_MBYTE | |
2963 if (has_mbyte) | |
2964 { | |
2965 for (col = 0; col < preedit_start_col | |
2966 && cmdpos < ccline.cmdlen; ++col) | |
2967 { | |
2968 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 2969 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2970 } |
2971 } | |
2972 else | |
2973 # endif | |
2974 { | |
2975 cmdspos += preedit_start_col; | |
2976 cmdpos += preedit_start_col; | |
2977 } | |
2978 | |
2979 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
2980 msg_col = cmdspos % (int)Columns; | |
2981 if (msg_row >= Rows) | |
2982 msg_row = Rows - 1; | |
2983 | |
2984 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
2985 { | |
2986 int char_len; | |
2987 int char_attr; | |
2988 | |
2989 char_attr = im_get_feedback_attr(col); | |
2990 if (char_attr < 0) | |
2991 break; /* end of preedit string */ | |
2992 | |
2993 # ifdef FEAT_MBYTE | |
2994 if (has_mbyte) | |
474 | 2995 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2996 else |
2997 # endif | |
2998 char_len = 1; | |
2999 | |
3000 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3001 cmdpos += char_len; | |
3002 } | |
3003 | |
3004 msg_row = old_row; | |
3005 msg_col = old_col; | |
3006 } | |
3007 } | |
3008 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3009 | |
3010 /* | |
3011 * Allocate a new command line buffer. | |
3012 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3013 * Returns the new value of ccline.cmdbuff and ccline.cmdbufflen. | |
3014 */ | |
3015 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3016 alloc_cmdbuff(int len) |
7 | 3017 { |
3018 /* | |
3019 * give some extra space to avoid having to allocate all the time | |
3020 */ | |
3021 if (len < 80) | |
3022 len = 100; | |
3023 else | |
3024 len += 20; | |
3025 | |
3026 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3027 ccline.cmdbufflen = len; | |
3028 } | |
3029 | |
3030 /* | |
3031 * Re-allocate the command line to length len + something extra. | |
3032 * return FAIL for failure, OK otherwise | |
3033 */ | |
3034 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3035 realloc_cmdbuff(int len) |
7 | 3036 { |
3037 char_u *p; | |
3038 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3039 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3040 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
|
3041 |
7 | 3042 p = ccline.cmdbuff; |
3043 alloc_cmdbuff(len); /* will get some more */ | |
3044 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3045 { | |
3046 ccline.cmdbuff = p; /* keep the old one */ | |
3047 return FAIL; | |
3048 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3049 /* 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
|
3050 * 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
|
3051 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
|
3052 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3053 vim_free(p); |
1718 | 3054 |
3055 if (ccline.xpc != NULL | |
3056 && ccline.xpc->xp_pattern != NULL | |
3057 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3058 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3059 { | |
1754 | 3060 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3061 |
3062 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3063 * to point into the newly allocated memory. */ | |
3064 if (i >= 0 && i <= ccline.cmdlen) | |
3065 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3066 } | |
3067 | |
7 | 3068 return OK; |
3069 } | |
3070 | |
359 | 3071 #if defined(FEAT_ARABIC) || defined(PROTO) |
3072 static char_u *arshape_buf = NULL; | |
3073 | |
3074 # if defined(EXITFREE) || defined(PROTO) | |
3075 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3076 free_cmdline_buf(void) |
359 | 3077 { |
3078 vim_free(arshape_buf); | |
3079 } | |
3080 # endif | |
3081 #endif | |
3082 | |
7 | 3083 /* |
3084 * Draw part of the cmdline at the current cursor position. But draw stars | |
3085 * when cmdline_star is TRUE. | |
3086 */ | |
3087 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3088 draw_cmdline(int start, int len) |
7 | 3089 { |
3090 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3091 int i; | |
3092 | |
3093 if (cmdline_star > 0) | |
3094 for (i = 0; i < len; ++i) | |
3095 { | |
3096 msg_putchar('*'); | |
3097 # ifdef FEAT_MBYTE | |
3098 if (has_mbyte) | |
474 | 3099 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3100 # endif |
3101 } | |
3102 else | |
3103 #endif | |
3104 #ifdef FEAT_ARABIC | |
3105 if (p_arshape && !p_tbidi && enc_utf8 && len > 0) | |
3106 { | |
3107 static int buflen = 0; | |
3108 char_u *p; | |
3109 int j; | |
3110 int newlen = 0; | |
3111 int mb_l; | |
719 | 3112 int pc, pc1 = 0; |
7 | 3113 int prev_c = 0; |
3114 int prev_c1 = 0; | |
714 | 3115 int u8c; |
3116 int u8cc[MAX_MCO]; | |
7 | 3117 int nc = 0; |
3118 | |
3119 /* | |
3120 * Do arabic shaping into a temporary buffer. This is very | |
3121 * inefficient! | |
3122 */ | |
507 | 3123 if (len * 2 + 2 > buflen) |
7 | 3124 { |
3125 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3126 * alloc()/free() calls. */ | |
359 | 3127 vim_free(arshape_buf); |
507 | 3128 buflen = len * 2 + 2; |
359 | 3129 arshape_buf = alloc(buflen); |
3130 if (arshape_buf == NULL) | |
7 | 3131 return; /* out of memory */ |
3132 } | |
3133 | |
507 | 3134 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3135 { | |
3136 /* Prepend a space to draw the leading composing char on. */ | |
3137 arshape_buf[0] = ' '; | |
3138 newlen = 1; | |
3139 } | |
3140 | |
7 | 3141 for (j = start; j < start + len; j += mb_l) |
3142 { | |
3143 p = ccline.cmdbuff + j; | |
714 | 3144 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3145 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3146 if (ARABIC_CHAR(u8c)) |
3147 { | |
3148 /* Do Arabic shaping. */ | |
3149 if (cmdmsg_rl) | |
3150 { | |
3151 /* displaying from right to left */ | |
3152 pc = prev_c; | |
3153 pc1 = prev_c1; | |
714 | 3154 prev_c1 = u8cc[0]; |
7 | 3155 if (j + mb_l >= start + len) |
3156 nc = NUL; | |
3157 else | |
3158 nc = utf_ptr2char(p + mb_l); | |
3159 } | |
3160 else | |
3161 { | |
3162 /* displaying from left to right */ | |
3163 if (j + mb_l >= start + len) | |
3164 pc = NUL; | |
3165 else | |
714 | 3166 { |
3167 int pcc[MAX_MCO]; | |
3168 | |
3169 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3170 start + len - j - mb_l); |
714 | 3171 pc1 = pcc[0]; |
3172 } | |
7 | 3173 nc = prev_c; |
3174 } | |
3175 prev_c = u8c; | |
3176 | |
714 | 3177 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3178 |
359 | 3179 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3180 if (u8cc[0] != 0) |
7 | 3181 { |
714 | 3182 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3183 if (u8cc[1] != 0) | |
3184 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3185 arshape_buf + newlen); |
7 | 3186 } |
3187 } | |
3188 else | |
3189 { | |
3190 prev_c = u8c; | |
359 | 3191 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3192 newlen += mb_l; |
3193 } | |
3194 } | |
3195 | |
359 | 3196 msg_outtrans_len(arshape_buf, newlen); |
7 | 3197 } |
3198 else | |
3199 #endif | |
3200 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3201 } | |
3202 | |
3203 /* | |
3204 * Put a character on the command line. Shifts the following text to the | |
3205 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3206 * "c" must be printable (fit in one display cell)! | |
3207 */ | |
3208 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3209 putcmdline(int c, int shift) |
7 | 3210 { |
3211 if (cmd_silent) | |
3212 return; | |
3213 msg_no_more = TRUE; | |
3214 msg_putchar(c); | |
3215 if (shift) | |
3216 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3217 msg_no_more = FALSE; | |
3218 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3219 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3220 extra_char_shift = shift; |
7 | 3221 } |
3222 | |
3223 /* | |
3224 * Undo a putcmdline(c, FALSE). | |
3225 */ | |
3226 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3227 unputcmdline(void) |
7 | 3228 { |
3229 if (cmd_silent) | |
3230 return; | |
3231 msg_no_more = TRUE; | |
3232 if (ccline.cmdlen == ccline.cmdpos) | |
3233 msg_putchar(' '); | |
3558 | 3234 #ifdef FEAT_MBYTE |
3235 else if (has_mbyte) | |
3236 draw_cmdline(ccline.cmdpos, | |
3237 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
3238 #endif | |
7 | 3239 else |
3240 draw_cmdline(ccline.cmdpos, 1); | |
3241 msg_no_more = FALSE; | |
3242 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3243 extra_char = NUL; |
7 | 3244 } |
3245 | |
3246 /* | |
3247 * Put the given string, of the given length, onto the command line. | |
3248 * If len is -1, then STRLEN() is used to calculate the length. | |
3249 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3250 * part will be redrawn, otherwise it will not. If this function is called | |
3251 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3252 * called afterwards. | |
3253 */ | |
3254 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3255 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3256 { |
3257 int retval; | |
3258 int i; | |
3259 int m; | |
3260 int c; | |
3261 | |
3262 if (len < 0) | |
3263 len = (int)STRLEN(str); | |
3264 | |
3265 /* Check if ccline.cmdbuff needs to be longer */ | |
3266 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
|
3267 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3268 else |
3269 retval = OK; | |
3270 if (retval == OK) | |
3271 { | |
3272 if (!ccline.overstrike) | |
3273 { | |
3274 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3275 ccline.cmdbuff + ccline.cmdpos, | |
3276 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3277 ccline.cmdlen += len; | |
3278 } | |
3279 else | |
3280 { | |
3281 #ifdef FEAT_MBYTE | |
3282 if (has_mbyte) | |
3283 { | |
3284 /* Count nr of characters in the new string. */ | |
3285 m = 0; | |
474 | 3286 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3287 ++m; |
3288 /* Count nr of bytes in cmdline that are overwritten by these | |
3289 * characters. */ | |
3290 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3291 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3292 --m; |
3293 if (i < ccline.cmdlen) | |
3294 { | |
3295 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3296 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3297 ccline.cmdlen += ccline.cmdpos + len - i; | |
3298 } | |
3299 else | |
3300 ccline.cmdlen = ccline.cmdpos + len; | |
3301 } | |
3302 else | |
3303 #endif | |
3304 if (ccline.cmdpos + len > ccline.cmdlen) | |
3305 ccline.cmdlen = ccline.cmdpos + len; | |
3306 } | |
3307 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3308 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3309 | |
3310 #ifdef FEAT_MBYTE | |
3311 if (enc_utf8) | |
3312 { | |
3313 /* When the inserted text starts with a composing character, | |
3314 * backup to the character before it. There could be two of them. | |
3315 */ | |
3316 i = 0; | |
3317 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3318 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3319 { | |
3320 i = (*mb_head_off)(ccline.cmdbuff, | |
3321 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3322 ccline.cmdpos -= i; | |
3323 len += i; | |
3324 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3325 } | |
3326 # ifdef FEAT_ARABIC | |
3327 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) | |
3328 { | |
3329 /* Check the previous character for Arabic combining pair. */ | |
3330 i = (*mb_head_off)(ccline.cmdbuff, | |
3331 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3332 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3333 + ccline.cmdpos - i), c)) | |
3334 { | |
3335 ccline.cmdpos -= i; | |
3336 len += i; | |
3337 } | |
3338 else | |
3339 i = 0; | |
3340 } | |
3341 # endif | |
3342 if (i != 0) | |
3343 { | |
3344 /* Also backup the cursor position. */ | |
3345 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3346 ccline.cmdspos -= i; | |
3347 msg_col -= i; | |
3348 if (msg_col < 0) | |
3349 { | |
3350 msg_col += Columns; | |
3351 --msg_row; | |
3352 } | |
3353 } | |
3354 } | |
3355 #endif | |
3356 | |
3357 if (redraw && !cmd_silent) | |
3358 { | |
3359 msg_no_more = TRUE; | |
3360 i = cmdline_row; | |
3114 | 3361 cursorcmd(); |
7 | 3362 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3363 /* Avoid clearing the rest of the line too often. */ | |
3364 if (cmdline_row != i || ccline.overstrike) | |
3365 msg_clr_eos(); | |
3366 msg_no_more = FALSE; | |
3367 } | |
3368 #ifdef FEAT_FKMAP | |
3369 /* | |
3370 * If we are in Farsi command mode, the character input must be in | |
3371 * Insert mode. So do not advance the cmdpos. | |
3372 */ | |
3373 if (!cmd_fkmap) | |
3374 #endif | |
3375 { | |
3376 if (KeyTyped) | |
534 | 3377 { |
7 | 3378 m = Columns * Rows; |
534 | 3379 if (m < 0) /* overflow, Columns or Rows at weird value */ |
3380 m = MAXCOL; | |
3381 } | |
7 | 3382 else |
3383 m = MAXCOL; | |
3384 for (i = 0; i < len; ++i) | |
3385 { | |
3386 c = cmdline_charsize(ccline.cmdpos); | |
3387 #ifdef FEAT_MBYTE | |
3388 /* count ">" for a double-wide char that doesn't fit. */ | |
3389 if (has_mbyte) | |
3390 correct_cmdspos(ccline.cmdpos, c); | |
3391 #endif | |
1612 | 3392 /* Stop cursor at the end of the screen, but do increment the |
3393 * insert position, so that entering a very long command | |
3394 * works, even though you can't see it. */ | |
3395 if (ccline.cmdspos + c < m) | |
3396 ccline.cmdspos += c; | |
7 | 3397 #ifdef FEAT_MBYTE |
3398 if (has_mbyte) | |
3399 { | |
474 | 3400 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
7 | 3401 if (c > len - i - 1) |
3402 c = len - i - 1; | |
3403 ccline.cmdpos += c; | |
3404 i += c; | |
3405 } | |
3406 #endif | |
3407 ++ccline.cmdpos; | |
3408 } | |
3409 } | |
3410 } | |
3411 if (redraw) | |
3412 msg_check(); | |
3413 return retval; | |
3414 } | |
3415 | |
95 | 3416 static struct cmdline_info prev_ccline; |
3417 static int prev_ccline_used = FALSE; | |
3418 | |
3419 /* | |
3420 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3421 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3422 * available globally in prev_ccline. | |
3423 */ | |
3424 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3425 save_cmdline(struct cmdline_info *ccp) |
95 | 3426 { |
3427 if (!prev_ccline_used) | |
3428 { | |
3429 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
3430 prev_ccline_used = TRUE; | |
3431 } | |
3432 *ccp = prev_ccline; | |
3433 prev_ccline = ccline; | |
3434 ccline.cmdbuff = NULL; | |
3435 ccline.cmdprompt = NULL; | |
1718 | 3436 ccline.xpc = NULL; |
95 | 3437 } |
3438 | |
3439 /* | |
1214 | 3440 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3441 */ |
3442 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3443 restore_cmdline(struct cmdline_info *ccp) |
95 | 3444 { |
3445 ccline = prev_ccline; | |
3446 prev_ccline = *ccp; | |
3447 } | |
3448 | |
849 | 3449 #if defined(FEAT_EVAL) || defined(PROTO) |
3450 /* | |
3451 * Save the command line into allocated memory. Returns a pointer to be | |
3452 * passed to restore_cmdline_alloc() later. | |
3453 * Returns NULL when failed. | |
3454 */ | |
3455 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3456 save_cmdline_alloc(void) |
849 | 3457 { |
3458 struct cmdline_info *p; | |
3459 | |
3460 p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info)); | |
3461 if (p != NULL) | |
3462 save_cmdline(p); | |
3463 return (char_u *)p; | |
3464 } | |
3465 | |
3466 /* | |
3467 * Restore the command line from the return value of save_cmdline_alloc(). | |
3468 */ | |
3469 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3470 restore_cmdline_alloc(char_u *p) |
849 | 3471 { |
3472 if (p != NULL) | |
3473 { | |
3474 restore_cmdline((struct cmdline_info *)p); | |
3475 vim_free(p); | |
3476 } | |
3477 } | |
3478 #endif | |
3479 | |
15 | 3480 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3481 * 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
|
3482 * Used by CTRL-R command in command-line mode. |
15 | 3483 * insert_reg() can't be used here, because special characters from the |
3484 * register contents will be interpreted as commands. | |
3485 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3486 * Return FAIL for failure, OK otherwise. |
15 | 3487 */ |
3488 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3489 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3490 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3491 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
|
3492 int remcr) /* remove trailing CR */ |
15 | 3493 { |
3494 long i; | |
3495 char_u *arg; | |
772 | 3496 char_u *p; |
15 | 3497 int allocated; |
3498 struct cmdline_info save_ccline; | |
3499 | |
3500 /* check for valid regname; also accept special characters for CTRL-R in | |
3501 * the command line */ | |
3502 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
|
3503 && 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
|
3504 && !valid_yank_reg(regname, FALSE)) |
15 | 3505 return FAIL; |
3506 | |
3507 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3508 * CTRL-C to break the loop. */ | |
3509 line_breakcheck(); | |
3510 if (got_int) | |
3511 return FAIL; | |
3512 | |
3513 #ifdef FEAT_CLIPBOARD | |
3514 regname = may_get_selection(regname); | |
3515 #endif | |
3516 | |
634 | 3517 /* Need to save and restore ccline. And set "textlock" to avoid nasty |
632 | 3518 * things like going to another buffer when evaluating an expression. */ |
95 | 3519 save_cmdline(&save_ccline); |
634 | 3520 ++textlock; |
15 | 3521 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3522 --textlock; |
95 | 3523 restore_cmdline(&save_ccline); |
15 | 3524 |
3525 if (i) | |
3526 { | |
3527 /* Got the value of a special register in "arg". */ | |
3528 if (arg == NULL) | |
3529 return FAIL; | |
772 | 3530 |
3531 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3532 * part of the word. */ | |
3533 p = arg; | |
3534 if (p_is && regname == Ctrl_W) | |
3535 { | |
3536 char_u *w; | |
3537 int len; | |
3538 | |
3539 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3540 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3541 { |
3542 #ifdef FEAT_MBYTE | |
3543 if (has_mbyte) | |
3544 { | |
3545 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3546 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3547 break; | |
3548 w -= len; | |
3549 } | |
3550 else | |
3551 #endif | |
3552 { | |
3553 if (!vim_iswordc(w[-1])) | |
3554 break; | |
3555 --w; | |
3556 } | |
3557 } | |
2937 | 3558 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3559 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3560 p += len; | |
3561 } | |
3562 | |
3563 cmdline_paste_str(p, literally); | |
15 | 3564 if (allocated) |
3565 vim_free(arg); | |
3566 return OK; | |
3567 } | |
3568 | |
1015 | 3569 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3570 } |
3571 | |
3572 /* | |
3573 * Put a string on the command line. | |
3574 * When "literally" is TRUE, insert literally. | |
3575 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3576 * line. | |
3577 */ | |
3578 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3579 cmdline_paste_str(char_u *s, int literally) |
15 | 3580 { |
3581 int c, cv; | |
3582 | |
3583 if (literally) | |
3584 put_on_cmdline(s, -1, TRUE); | |
3585 else | |
3586 while (*s != NUL) | |
3587 { | |
3588 cv = *s; | |
3589 if (cv == Ctrl_V && s[1]) | |
3590 ++s; | |
3591 #ifdef FEAT_MBYTE | |
3592 if (has_mbyte) | |
1606 | 3593 c = mb_cptr2char_adv(&s); |
15 | 3594 else |
3595 #endif | |
3596 c = *s++; | |
3628 | 3597 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3598 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3599 #ifdef UNIX |
3600 || c == intr_char | |
3601 #endif | |
3602 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3603 stuffcharReadbuff(Ctrl_V); | |
3604 stuffcharReadbuff(c); | |
3605 } | |
3606 } | |
3607 | |
7 | 3608 #ifdef FEAT_WILDMENU |
3609 /* | |
3610 * Delete characters on the command line, from "from" to the current | |
3611 * position. | |
3612 */ | |
3613 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3614 cmdline_del(int from) |
7 | 3615 { |
3616 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3617 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3618 ccline.cmdlen -= ccline.cmdpos - from; | |
3619 ccline.cmdpos = from; | |
3620 } | |
3621 #endif | |
3622 | |
3623 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3624 * 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
|
3625 * 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
|
3626 * overwritten. |
7 | 3627 */ |
3628 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3629 redrawcmdline(void) |
7 | 3630 { |
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
|
3631 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
|
3632 } |
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
|
3633 |
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
|
3634 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
|
3635 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
|
3636 { |
7 | 3637 if (cmd_silent) |
3638 return; | |
3639 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
|
3640 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
|
3641 compute_cmdrow(); |
7 | 3642 redrawcmd(); |
3643 cursorcmd(); | |
3644 } | |
3645 | |
3646 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3647 redrawcmdprompt(void) |
7 | 3648 { |
3649 int i; | |
3650 | |
3651 if (cmd_silent) | |
3652 return; | |
531 | 3653 if (ccline.cmdfirstc != NUL) |
7 | 3654 msg_putchar(ccline.cmdfirstc); |
3655 if (ccline.cmdprompt != NULL) | |
3656 { | |
3657 msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); | |
3658 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; | |
3659 /* do the reverse of set_cmdspos() */ | |
531 | 3660 if (ccline.cmdfirstc != NUL) |
7 | 3661 --ccline.cmdindent; |
3662 } | |
3663 else | |
3664 for (i = ccline.cmdindent; i > 0; --i) | |
3665 msg_putchar(' '); | |
3666 } | |
3667 | |
3668 /* | |
3669 * Redraw what is currently on the command line. | |
3670 */ | |
3671 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3672 redrawcmd(void) |
7 | 3673 { |
3674 if (cmd_silent) | |
3675 return; | |
3676 | |
683 | 3677 /* when 'incsearch' is set there may be no command line while redrawing */ |
3678 if (ccline.cmdbuff == NULL) | |
3679 { | |
3680 windgoto(cmdline_row, 0); | |
3681 msg_clr_eos(); | |
3682 return; | |
3683 } | |
3684 | |
7 | 3685 msg_start(); |
3686 redrawcmdprompt(); | |
3687 | |
3688 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3689 msg_no_more = TRUE; | |
3690 draw_cmdline(0, ccline.cmdlen); | |
3691 msg_clr_eos(); | |
3692 msg_no_more = FALSE; | |
3693 | |
3694 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
|
3695 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
|
3696 putcmdline(extra_char, extra_char_shift); |
7 | 3697 |
3698 /* | |
3699 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3700 * in cmdline mode we can reset them now. | |
3701 */ | |
3702 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3703 | |
3704 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3705 * in cmdline mode */ | |
3706 skip_redraw = FALSE; | |
3707 } | |
3708 | |
3709 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3710 compute_cmdrow(void) |
7 | 3711 { |
540 | 3712 if (exmode_active || msg_scrolled != 0) |
7 | 3713 cmdline_row = Rows - 1; |
3714 else | |
3715 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
|
3716 + lastwin->w_status_height; |
7 | 3717 } |
3718 | |
3719 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3720 cursorcmd(void) |
7 | 3721 { |
3722 if (cmd_silent) | |
3723 return; | |
3724 | |
3725 #ifdef FEAT_RIGHTLEFT | |
3726 if (cmdmsg_rl) | |
3727 { | |
3728 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3729 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3730 if (msg_row <= 0) | |
3731 msg_row = Rows - 1; | |
3732 } | |
3733 else | |
3734 #endif | |
3735 { | |
3736 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3737 msg_col = ccline.cmdspos % (int)Columns; | |
3738 if (msg_row >= Rows) | |
3739 msg_row = Rows - 1; | |
3740 } | |
3741 | |
3742 windgoto(msg_row, msg_col); | |
3743 #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
|
3744 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
|
3745 redrawcmd_preedit(); |
7 | 3746 #endif |
3747 #ifdef MCH_CURSOR_SHAPE | |
3748 mch_update_cursor(); | |
3749 #endif | |
3750 } | |
3751 | |
3752 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3753 gotocmdline(int clr) |
7 | 3754 { |
3755 msg_start(); | |
3756 #ifdef FEAT_RIGHTLEFT | |
3757 if (cmdmsg_rl) | |
3758 msg_col = Columns - 1; | |
3759 else | |
3760 #endif | |
3761 msg_col = 0; /* always start in column 0 */ | |
3762 if (clr) /* clear the bottom line(s) */ | |
3763 msg_clr_eos(); /* will reset clear_cmdline */ | |
3764 windgoto(cmdline_row, 0); | |
3765 } | |
3766 | |
3767 /* | |
3768 * Check the word in front of the cursor for an abbreviation. | |
3769 * Called when the non-id character "c" has been entered. | |
3770 * When an abbreviation is recognized it is removed from the text with | |
3771 * backspaces and the replacement string is inserted, followed by "c". | |
3772 */ | |
3773 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3774 ccheck_abbr(int c) |
7 | 3775 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3776 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3777 |
7 | 3778 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3779 return FALSE; | |
3780 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3781 /* 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
|
3782 * 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
|
3783 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
|
3784 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3785 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
|
3786 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3787 && 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
|
3788 && 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
|
3789 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3790 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3791 /* 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
|
3792 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3793 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3794 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3795 } |
3796 | |
3164 | 3797 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3798 static int | |
3799 #ifdef __BORLANDC__ | |
3800 _RTLENTRYF | |
3801 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3802 sort_func_compare(const void *s1, const void *s2) |
3164 | 3803 { |
3804 char_u *p1 = *(char_u **)s1; | |
3805 char_u *p2 = *(char_u **)s2; | |
3806 | |
3807 if (*p1 != '<' && *p2 == '<') return -1; | |
3808 if (*p1 == '<' && *p2 != '<') return 1; | |
3809 return STRCMP(p1, p2); | |
3810 } | |
3811 #endif | |
3812 | |
7 | 3813 /* |
3814 * Return FAIL if this is not an appropriate context in which to do | |
3815 * completion of anything, return OK if it is (even if there are no matches). | |
3816 * For the caller, this means that the character is just passed through like a | |
3817 * normal character (instead of being expanded). This allows :s/^I^D etc. | |
3818 */ | |
3819 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3820 nextwild( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3821 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3822 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3823 int options, /* extra options for ExpandOne() */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3824 int escape) /* if TRUE, escape the returned matches */ |
7 | 3825 { |
3826 int i, j; | |
3827 char_u *p1; | |
3828 char_u *p2; | |
3829 int difflen; | |
3830 int v; | |
3831 | |
3832 if (xp->xp_numfiles == -1) | |
3833 { | |
3834 set_expand_context(xp); | |
3835 cmd_showtail = expand_showtail(xp); | |
3836 } | |
3837 | |
3838 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
3839 { | |
3840 beep_flush(); | |
3841 return OK; /* Something illegal on command line */ | |
3842 } | |
3843 if (xp->xp_context == EXPAND_NOTHING) | |
3844 { | |
3845 /* Caller can use the character as a normal char instead */ | |
3846 return FAIL; | |
3847 } | |
3848 | |
3849 MSG_PUTS("..."); /* show that we are busy */ | |
3850 out_flush(); | |
3851 | |
3852 i = (int)(xp->xp_pattern - ccline.cmdbuff); | |
1965 | 3853 xp->xp_pattern_len = ccline.cmdpos - i; |
7 | 3854 |
3855 if (type == WILD_NEXT || type == WILD_PREV) | |
3856 { | |
3857 /* | |
3858 * Get next/previous match for a previous expanded pattern. | |
3859 */ | |
3860 p2 = ExpandOne(xp, NULL, NULL, 0, type); | |
3861 } | |
3862 else | |
3863 { | |
3864 /* | |
3865 * Translate string into pattern and expand it. | |
3866 */ | |
1965 | 3867 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, |
3868 xp->xp_context)) == NULL) | |
7 | 3869 p2 = NULL; |
3870 else | |
3871 { | |
2652 | 3872 int use_options = options | |
3961 | 3873 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT; |
3874 if (escape) | |
3875 use_options |= WILD_ESCAPE; | |
2652 | 3876 |
3877 if (p_wic) | |
3878 use_options += WILD_ICASE; | |
1965 | 3879 p2 = ExpandOne(xp, p1, |
3880 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), | |
2652 | 3881 use_options, type); |
7 | 3882 vim_free(p1); |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2016
diff
changeset
|
3883 /* longest match: make sure it is not shorter, happens with :help */ |
7 | 3884 if (p2 != NULL && type == WILD_LONGEST) |
3885 { | |
1965 | 3886 for (j = 0; j < xp->xp_pattern_len; ++j) |
7 | 3887 if (ccline.cmdbuff[i + j] == '*' |
3888 || ccline.cmdbuff[i + j] == '?') | |
3889 break; | |
3890 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
|
3891 VIM_CLEAR(p2); |
7 | 3892 } |
3893 } | |
3894 } | |
3895 | |
3896 if (p2 != NULL && !got_int) | |
3897 { | |
1965 | 3898 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
|
3899 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) |
7 | 3900 { |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3901 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); |
7 | 3902 xp->xp_pattern = ccline.cmdbuff + i; |
3903 } | |
3904 else | |
3905 v = OK; | |
3906 if (v == OK) | |
3907 { | |
323 | 3908 mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], |
3909 &ccline.cmdbuff[ccline.cmdpos], | |
3910 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3911 mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2)); | |
7 | 3912 ccline.cmdlen += difflen; |
3913 ccline.cmdpos += difflen; | |
3914 } | |
3915 } | |
3916 vim_free(p2); | |
3917 | |
3918 redrawcmd(); | |
33 | 3919 cursorcmd(); |
7 | 3920 |
3921 /* When expanding a ":map" command and no matches are found, assume that | |
3922 * the key is supposed to be inserted literally */ | |
3923 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) | |
3924 return FAIL; | |
3925 | |
3926 if (xp->xp_numfiles <= 0 && p2 == NULL) | |
3927 beep_flush(); | |
3928 else if (xp->xp_numfiles == 1) | |
3929 /* free expanded pattern */ | |
3930 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE); | |
3931 | |
3932 return OK; | |
3933 } | |
3934 | |
3935 /* | |
3936 * Do wildcard expansion on the string 'str'. | |
3937 * Chars that should not be expanded must be preceded with a backslash. | |
1612 | 3938 * Return a pointer to allocated memory containing the new string. |
7 | 3939 * Return NULL for failure. |
3940 * | |
1412 | 3941 * "orig" is the originally expanded string, copied to allocated memory. It |
3942 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or | |
3943 * WILD_PREV "orig" should be NULL. | |
3944 * | |
838 | 3945 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" |
3946 * is WILD_EXPAND_FREE or WILD_ALL. | |
7 | 3947 * |
3948 * mode = WILD_FREE: just free previously expanded matches | |
3949 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches | |
3950 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches | |
3951 * mode = WILD_NEXT: use next match in multiple match, wrap to first | |
3952 * mode = WILD_PREV: use previous match in multiple match, wrap to first | |
3953 * mode = WILD_ALL: return all matches concatenated | |
3954 * mode = WILD_LONGEST: return longest matched part | |
3398 | 3955 * mode = WILD_ALL_KEEP: get all matches, keep matches |
7 | 3956 * |
3957 * options = WILD_LIST_NOTFOUND: list entries without a match | |
3958 * options = WILD_HOME_REPLACE: do home_replace() for buffer names | |
3959 * options = WILD_USE_NL: Use '\n' for WILD_ALL | |
3960 * options = WILD_NO_BEEP: Don't beep for multiple matches | |
3961 * options = WILD_ADD_SLASH: add a slash after directory names | |
3962 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries | |
3963 * options = WILD_SILENT: don't print warning messages | |
3964 * options = WILD_ESCAPE: put backslash before special chars | |
2652 | 3965 * options = WILD_ICASE: ignore case for files |
7 | 3966 * |
3967 * The variables xp->xp_context and xp->xp_backslash must have been set! | |
3968 */ | |
3969 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3970 ExpandOne( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3971 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3972 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3973 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
|
3974 int options, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3975 int mode) |
7 | 3976 { |
3977 char_u *ss = NULL; | |
3978 static int findex; | |
3979 static char_u *orig_save = NULL; /* kept value of orig */ | |
1432 | 3980 int orig_saved = FALSE; |
7 | 3981 int i; |
3982 long_u len; | |
3983 int non_suf_match; /* number without matching suffix */ | |
3984 | |
3985 /* | |
3986 * first handle the case of using an old match | |
3987 */ | |
3988 if (mode == WILD_NEXT || mode == WILD_PREV) | |
3989 { | |
3990 if (xp->xp_numfiles > 0) | |
3991 { | |
3992 if (mode == WILD_PREV) | |
3993 { | |
3994 if (findex == -1) | |
3995 findex = xp->xp_numfiles; | |
3996 --findex; | |
3997 } | |
3998 else /* mode == WILD_NEXT */ | |
3999 ++findex; | |
4000 | |
4001 /* | |
4002 * When wrapping around, return the original string, set findex to | |
4003 * -1. | |
4004 */ | |
4005 if (findex < 0) | |
4006 { | |
4007 if (orig_save == NULL) | |
4008 findex = xp->xp_numfiles - 1; | |
4009 else | |
4010 findex = -1; | |
4011 } | |
4012 if (findex >= xp->xp_numfiles) | |
4013 { | |
4014 if (orig_save == NULL) | |
4015 findex = 0; | |
4016 else | |
4017 findex = -1; | |
4018 } | |
4019 #ifdef FEAT_WILDMENU | |
4020 if (p_wmnu) | |
4021 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, | |
4022 findex, cmd_showtail); | |
4023 #endif | |
4024 if (findex == -1) | |
4025 return vim_strsave(orig_save); | |
4026 return vim_strsave(xp->xp_files[findex]); | |
4027 } | |
4028 else | |
4029 return NULL; | |
4030 } | |
4031 | |
1412 | 4032 /* free old names */ |
7 | 4033 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
4034 { | |
4035 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4036 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
|
4037 VIM_CLEAR(orig_save); |
7 | 4038 } |
4039 findex = 0; | |
4040 | |
4041 if (mode == WILD_FREE) /* only release file name */ | |
4042 return NULL; | |
4043 | |
4044 if (xp->xp_numfiles == -1) | |
4045 { | |
4046 vim_free(orig_save); | |
4047 orig_save = orig; | |
1432 | 4048 orig_saved = TRUE; |
7 | 4049 |
4050 /* | |
4051 * Do the expansion. | |
4052 */ | |
4053 if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, | |
4054 options) == FAIL) | |
4055 { | |
4056 #ifdef FNAME_ILLEGAL | |
4057 /* Illegal file name has been silently skipped. But when there | |
4058 * are wildcards, the real problem is that there was no match, | |
4059 * causing the pattern to be added, which has illegal characters. | |
4060 */ | |
4061 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) | |
4062 EMSG2(_(e_nomatch2), str); | |
4063 #endif | |
4064 } | |
4065 else if (xp->xp_numfiles == 0) | |
4066 { | |
4067 if (!(options & WILD_SILENT)) | |
4068 EMSG2(_(e_nomatch2), str); | |
4069 } | |
4070 else | |
4071 { | |
4072 /* Escape the matches for use on the command line. */ | |
4073 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); | |
4074 | |
4075 /* | |
4076 * Check for matching suffixes in file names. | |
4077 */ | |
3398 | 4078 if (mode != WILD_ALL && mode != WILD_ALL_KEEP |
4079 && mode != WILD_LONGEST) | |
7 | 4080 { |
4081 if (xp->xp_numfiles) | |
4082 non_suf_match = xp->xp_numfiles; | |
4083 else | |
4084 non_suf_match = 1; | |
4085 if ((xp->xp_context == EXPAND_FILES | |
4086 || xp->xp_context == EXPAND_DIRECTORIES) | |
4087 && xp->xp_numfiles > 1) | |
4088 { | |
4089 /* | |
4090 * More than one match; check suffix. | |
4091 * The files will have been sorted on matching suffix in | |
4092 * expand_wildcards, only need to check the first two. | |
4093 */ | |
4094 non_suf_match = 0; | |
4095 for (i = 0; i < 2; ++i) | |
4096 if (match_suffix(xp->xp_files[i])) | |
4097 ++non_suf_match; | |
4098 } | |
4099 if (non_suf_match != 1) | |
4100 { | |
4101 /* Can we ever get here unless it's while expanding | |
4102 * interactively? If not, we can get rid of this all | |
4103 * together. Don't really want to wait for this message | |
4104 * (and possibly have to hit return to continue!). | |
4105 */ | |
4106 if (!(options & WILD_SILENT)) | |
4107 EMSG(_(e_toomany)); | |
4108 else if (!(options & WILD_NO_BEEP)) | |
4109 beep_flush(); | |
4110 } | |
4111 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) | |
4112 ss = vim_strsave(xp->xp_files[0]); | |
4113 } | |
4114 } | |
4115 } | |
4116 | |
4117 /* Find longest common part */ | |
4118 if (mode == WILD_LONGEST && xp->xp_numfiles > 0) | |
4119 { | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4120 int mb_len = 1; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4121 int c0, ci; |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4122 |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4123 for (len = 0; xp->xp_files[0][len]; len += mb_len) |
7 | 4124 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4125 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4126 if (has_mbyte) |
7 | 4127 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4128 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
|
4129 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
|
4130 } |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4131 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4132 #endif |
7250
99476f1aaacd
commit https://github.com/vim/vim/commit/e4eda3bc7157932b0bf380fd3fdc1ba8f4438b60
Christian Brabandt <cb@256bit.org>
parents:
7235
diff
changeset
|
4133 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
|
4134 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
|
4135 { |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4136 #ifdef FEAT_MBYTE |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4137 if (has_mbyte) |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4138 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
|
4139 else |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4140 #endif |
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4141 ci = xp->xp_files[i][len]; |
4242 | 4142 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES |
7 | 4143 || xp->xp_context == EXPAND_FILES |
714 | 4144 || xp->xp_context == EXPAND_SHELLCMD |
4242 | 4145 || xp->xp_context == EXPAND_BUFFERS)) |
7 | 4146 { |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4147 if (MB_TOLOWER(c0) != MB_TOLOWER(ci)) |
7 | 4148 break; |
4149 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4150 else if (c0 != ci) |
7 | 4151 break; |
4152 } | |
4153 if (i < xp->xp_numfiles) | |
4154 { | |
4155 if (!(options & WILD_NO_BEEP)) | |
6949 | 4156 vim_beep(BO_WILD); |
7 | 4157 break; |
4158 } | |
4159 } | |
7235
e45271250496
commit https://github.com/vim/vim/commit/4f8fa1633cdfbd09a41160c8480fe67c198067e9
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
4160 |
7 | 4161 ss = alloc((unsigned)len + 1); |
4162 if (ss) | |
419 | 4163 vim_strncpy(ss, xp->xp_files[0], (size_t)len); |
7 | 4164 findex = -1; /* next p_wc gets first one */ |
4165 } | |
4166 | |
4167 /* Concatenate all matching names */ | |
4168 if (mode == WILD_ALL && xp->xp_numfiles > 0) | |
4169 { | |
4170 len = 0; | |
4171 for (i = 0; i < xp->xp_numfiles; ++i) | |
4172 len += (long_u)STRLEN(xp->xp_files[i]) + 1; | |
4173 ss = lalloc(len, TRUE); | |
4174 if (ss != NULL) | |
4175 { | |
4176 *ss = NUL; | |
4177 for (i = 0; i < xp->xp_numfiles; ++i) | |
4178 { | |
4179 STRCAT(ss, xp->xp_files[i]); | |
4180 if (i != xp->xp_numfiles - 1) | |
4181 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); | |
4182 } | |
4183 } | |
4184 } | |
4185 | |
4186 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) | |
4187 ExpandCleanup(xp); | |
4188 | |
1412 | 4189 /* Free "orig" if it wasn't stored in "orig_save". */ |
1432 | 4190 if (!orig_saved) |
1412 | 4191 vim_free(orig); |
4192 | |
7 | 4193 return ss; |
4194 } | |
4195 | |
4196 /* | |
4197 * Prepare an expand structure for use. | |
4198 */ | |
4199 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4200 ExpandInit(expand_T *xp) |
7 | 4201 { |
1718 | 4202 xp->xp_pattern = NULL; |
1965 | 4203 xp->xp_pattern_len = 0; |
7 | 4204 xp->xp_backslash = XP_BS_NONE; |
632 | 4205 #ifndef BACKSLASH_IN_FILENAME |
4206 xp->xp_shell = FALSE; | |
4207 #endif | |
7 | 4208 xp->xp_numfiles = -1; |
4209 xp->xp_files = NULL; | |
632 | 4210 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL) |
4211 xp->xp_arg = NULL; | |
4212 #endif | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
4213 xp->xp_line = NULL; |
7 | 4214 } |
4215 | |
4216 /* | |
4217 * Cleanup an expand structure after use. | |
4218 */ | |
4219 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4220 ExpandCleanup(expand_T *xp) |
7 | 4221 { |
4222 if (xp->xp_numfiles >= 0) | |
4223 { | |
4224 FreeWild(xp->xp_numfiles, xp->xp_files); | |
4225 xp->xp_numfiles = -1; | |
4226 } | |
4227 } | |
4228 | |
4229 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4230 ExpandEscape( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4231 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4232 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4233 int numfiles, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4234 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4235 int options) |
7 | 4236 { |
4237 int i; | |
4238 char_u *p; | |
4239 | |
4240 /* | |
4241 * May change home directory back to "~" | |
4242 */ | |
4243 if (options & WILD_HOME_REPLACE) | |
4244 tilde_replace(str, numfiles, files); | |
4245 | |
4246 if (options & WILD_ESCAPE) | |
4247 { | |
4248 if (xp->xp_context == EXPAND_FILES | |
2778 | 4249 || xp->xp_context == EXPAND_FILES_IN_PATH |
714 | 4250 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4251 || xp->xp_context == EXPAND_BUFFERS |
4252 || xp->xp_context == EXPAND_DIRECTORIES) | |
4253 { | |
4254 /* | |
4255 * Insert a backslash into a file name before a space, \, %, # | |
4256 * and wildmatch characters, except '~'. | |
4257 */ | |
4258 for (i = 0; i < numfiles; ++i) | |
4259 { | |
4260 /* for ":set path=" we need to escape spaces twice */ | |
4261 if (xp->xp_backslash == XP_BS_THREE) | |
4262 { | |
4263 p = vim_strsave_escaped(files[i], (char_u *)" "); | |
4264 if (p != NULL) | |
4265 { | |
4266 vim_free(files[i]); | |
4267 files[i] = p; | |
719 | 4268 #if defined(BACKSLASH_IN_FILENAME) |
7 | 4269 p = vim_strsave_escaped(files[i], (char_u *)" "); |
4270 if (p != NULL) | |
4271 { | |
4272 vim_free(files[i]); | |
4273 files[i] = p; | |
4274 } | |
4275 #endif | |
4276 } | |
4277 } | |
1589 | 4278 #ifdef BACKSLASH_IN_FILENAME |
4279 p = vim_strsave_fnameescape(files[i], FALSE); | |
4280 #else | |
1586 | 4281 p = vim_strsave_fnameescape(files[i], xp->xp_shell); |
1589 | 4282 #endif |
7 | 4283 if (p != NULL) |
4284 { | |
4285 vim_free(files[i]); | |
4286 files[i] = p; | |
4287 } | |
4288 | |
4289 /* If 'str' starts with "\~", replace "~" at start of | |
4290 * files[i] with "\~". */ | |
4291 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') | |
435 | 4292 escape_fname(&files[i]); |
7 | 4293 } |
4294 xp->xp_backslash = XP_BS_NONE; | |
435 | 4295 |
4296 /* If the first file starts with a '+' escape it. Otherwise it | |
4297 * could be seen as "+cmd". */ | |
4298 if (*files[0] == '+') | |
4299 escape_fname(&files[0]); | |
7 | 4300 } |
4301 else if (xp->xp_context == EXPAND_TAGS) | |
4302 { | |
4303 /* | |
4304 * Insert a backslash before characters in a tag name that | |
4305 * would terminate the ":tag" command. | |
4306 */ | |
4307 for (i = 0; i < numfiles; ++i) | |
4308 { | |
4309 p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); | |
4310 if (p != NULL) | |
4311 { | |
4312 vim_free(files[i]); | |
4313 files[i] = p; | |
4314 } | |
4315 } | |
4316 } | |
4317 } | |
4318 } | |
4319 | |
4320 /* | |
1586 | 4321 * Escape special characters in "fname" for when used as a file name argument |
4322 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
4323 * Returns the result in allocated memory. | |
4324 */ | |
4325 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4326 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 4327 { |
1685 | 4328 char_u *p; |
1586 | 4329 #ifdef BACKSLASH_IN_FILENAME |
4330 char_u buf[20]; | |
4331 int j = 0; | |
4332 | |
5481 | 4333 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 4334 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 4335 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 4336 buf[j++] = *p; |
4337 buf[j] = NUL; | |
1700 | 4338 p = vim_strsave_escaped(fname, buf); |
1586 | 4339 #else |
1685 | 4340 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
4341 if (shell && csh_like_shell() && p != NULL) | |
4342 { | |
4343 char_u *s; | |
4344 | |
4345 /* For csh and similar shells need to put two backslashes before '!'. | |
4346 * One is taken by Vim, one by the shell. */ | |
4347 s = vim_strsave_escaped(p, (char_u *)"!"); | |
4348 vim_free(p); | |
4349 p = s; | |
4350 } | |
1700 | 4351 #endif |
4352 | |
4353 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
4354 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
4355 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 4356 escape_fname(&p); |
4357 | |
1685 | 4358 return p; |
1586 | 4359 } |
4360 | |
4361 /* | |
435 | 4362 * Put a backslash before the file name in "pp", which is in allocated memory. |
4363 */ | |
4364 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4365 escape_fname(char_u **pp) |
435 | 4366 { |
4367 char_u *p; | |
4368 | |
4369 p = alloc((unsigned)(STRLEN(*pp) + 2)); | |
4370 if (p != NULL) | |
4371 { | |
4372 p[0] = '\\'; | |
4373 STRCPY(p + 1, *pp); | |
4374 vim_free(*pp); | |
4375 *pp = p; | |
4376 } | |
4377 } | |
4378 | |
4379 /* | |
7 | 4380 * For each file name in files[num_files]: |
4381 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
4382 */ | |
4383 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4384 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4385 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4386 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4387 char_u **files) |
7 | 4388 { |
4389 int i; | |
4390 char_u *p; | |
4391 | |
4392 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
4393 { | |
4394 for (i = 0; i < num_files; ++i) | |
4395 { | |
4396 p = home_replace_save(NULL, files[i]); | |
4397 if (p != NULL) | |
4398 { | |
4399 vim_free(files[i]); | |
4400 files[i] = p; | |
4401 } | |
4402 } | |
4403 } | |
4404 } | |
4405 | |
4406 /* | |
4407 * Show all matches for completion on the command line. | |
4408 * Returns EXPAND_NOTHING when the character that triggered expansion should | |
4409 * be inserted like a normal character. | |
4410 */ | |
4411 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4412 showmatches(expand_T *xp, int wildmenu UNUSED) |
7 | 4413 { |
4414 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m]) | |
4415 int num_files; | |
4416 char_u **files_found; | |
4417 int i, j, k; | |
4418 int maxlen; | |
4419 int lines; | |
4420 int columns; | |
4421 char_u *p; | |
4422 int lastlen; | |
4423 int attr; | |
4424 int showtail; | |
4425 | |
4426 if (xp->xp_numfiles == -1) | |
4427 { | |
4428 set_expand_context(xp); | |
4429 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos, | |
4430 &num_files, &files_found); | |
4431 showtail = expand_showtail(xp); | |
4432 if (i != EXPAND_OK) | |
4433 return i; | |
4434 | |
4435 } | |
4436 else | |
4437 { | |
4438 num_files = xp->xp_numfiles; | |
4439 files_found = xp->xp_files; | |
4440 showtail = cmd_showtail; | |
4441 } | |
4442 | |
4443 #ifdef FEAT_WILDMENU | |
4444 if (!wildmenu) | |
4445 { | |
4446 #endif | |
4447 msg_didany = FALSE; /* lines_left will be set */ | |
4448 msg_start(); /* prepare for paging */ | |
4449 msg_putchar('\n'); | |
4450 out_flush(); | |
4451 cmdline_row = msg_row; | |
4452 msg_didany = FALSE; /* lines_left will be set again */ | |
4453 msg_start(); /* prepare for paging */ | |
4454 #ifdef FEAT_WILDMENU | |
4455 } | |
4456 #endif | |
4457 | |
4458 if (got_int) | |
4459 got_int = FALSE; /* only int. the completion, not the cmd line */ | |
4460 #ifdef FEAT_WILDMENU | |
4461 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
|
4462 win_redr_status_matches(xp, num_files, files_found, -1, showtail); |
7 | 4463 #endif |
4464 else | |
4465 { | |
4466 /* find the length of the longest file name */ | |
4467 maxlen = 0; | |
4468 for (i = 0; i < num_files; ++i) | |
4469 { | |
4470 if (!showtail && (xp->xp_context == EXPAND_FILES | |
714 | 4471 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4472 || xp->xp_context == EXPAND_BUFFERS)) |
4473 { | |
4474 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE); | |
4475 j = vim_strsize(NameBuff); | |
4476 } | |
4477 else | |
4478 j = vim_strsize(L_SHOWFILE(i)); | |
4479 if (j > maxlen) | |
4480 maxlen = j; | |
4481 } | |
4482 | |
4483 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4484 lines = num_files; | |
4485 else | |
4486 { | |
4487 /* compute the number of columns and lines for the listing */ | |
4488 maxlen += 2; /* two spaces between file names */ | |
4489 columns = ((int)Columns + 2) / maxlen; | |
4490 if (columns < 1) | |
4491 columns = 1; | |
4492 lines = (num_files + columns - 1) / columns; | |
4493 } | |
4494 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4495 attr = HL_ATTR(HLF_D); /* find out highlighting for directories */ |
7 | 4496 |
4497 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4498 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4499 MSG_PUTS_ATTR(_("tagname"), HL_ATTR(HLF_T)); |
7 | 4500 msg_clr_eos(); |
4501 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
|
4502 MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T)); |
7 | 4503 } |
4504 | |
4505 /* list the files line by line */ | |
4506 for (i = 0; i < lines; ++i) | |
4507 { | |
4508 lastlen = 999; | |
4509 for (k = i; k < num_files; k += lines) | |
4510 { | |
4511 if (xp->xp_context == EXPAND_TAGS_LISTFILES) | |
4512 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4513 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); |
7 | 4514 p = files_found[k] + STRLEN(files_found[k]) + 1; |
4515 msg_advance(maxlen + 1); | |
4516 msg_puts(p); | |
4517 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
|
4518 msg_puts_long_attr(p + 2, HL_ATTR(HLF_D)); |
7 | 4519 break; |
4520 } | |
4521 for (j = maxlen - lastlen; --j >= 0; ) | |
4522 msg_putchar(' '); | |
4523 if (xp->xp_context == EXPAND_FILES | |
714 | 4524 || xp->xp_context == EXPAND_SHELLCMD |
7 | 4525 || xp->xp_context == EXPAND_BUFFERS) |
4526 { | |
2118
63bf37c1e7a2
updated for version 7.2.401
Bram Moolenaar <bram@zimbu.org>
parents:
2099
diff
changeset
|
4527 /* highlight directories */ |
2128
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4528 if (xp->xp_numfiles != -1) |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4529 { |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4530 char_u *halved_slash; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4531 char_u *exp_path; |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4532 |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4533 /* Expansion was done before and special characters |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4534 * were escaped, need to halve backslashes. Also |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4535 * $HOME has been replaced with ~/. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4536 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
|
4537 halved_slash = backslash_halve_save( |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4538 exp_path != NULL ? exp_path : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4539 j = mch_isdir(halved_slash != NULL ? halved_slash |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4540 : files_found[k]); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4541 vim_free(exp_path); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4542 vim_free(halved_slash); |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4543 } |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4544 else |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4545 /* Expansion was done here, file names are literal. */ |
a16af0072ea8
updated for version 7.2.410
Bram Moolenaar <bram@zimbu.org>
parents:
2118
diff
changeset
|
4546 j = mch_isdir(files_found[k]); |
7 | 4547 if (showtail) |
4548 p = L_SHOWFILE(k); | |
4549 else | |
4550 { | |
4551 home_replace(NULL, files_found[k], NameBuff, MAXPATHL, | |
4552 TRUE); | |
4553 p = NameBuff; | |
4554 } | |
4555 } | |
4556 else | |
4557 { | |
4558 j = FALSE; | |
4559 p = L_SHOWFILE(k); | |
4560 } | |
4561 lastlen = msg_outtrans_attr(p, j ? attr : 0); | |
4562 } | |
4563 if (msg_col > 0) /* when not wrapped around */ | |
4564 { | |
4565 msg_clr_eos(); | |
4566 msg_putchar('\n'); | |
4567 } | |
4568 out_flush(); /* show one line at a time */ | |
4569 if (got_int) | |
4570 { | |
4571 got_int = FALSE; | |
4572 break; | |
4573 } | |
4574 } | |
4575 | |
4576 /* | |
4577 * we redraw the command below the lines that we have just listed | |
4578 * This is a bit tricky, but it saves a lot of screen updating. | |
4579 */ | |
4580 cmdline_row = msg_row; /* will put it back later */ | |
4581 } | |
4582 | |
4583 if (xp->xp_numfiles == -1) | |
4584 FreeWild(num_files, files_found); | |
4585 | |
4586 return EXPAND_OK; | |
4587 } | |
4588 | |
4589 /* | |
4590 * Private gettail for showmatches() (and win_redr_status_matches()): | |
4591 * Find tail of file name path, but ignore trailing "/". | |
4592 */ | |
4593 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4594 sm_gettail(char_u *s) |
7 | 4595 { |
4596 char_u *p; | |
4597 char_u *t = s; | |
4598 int had_sep = FALSE; | |
4599 | |
4600 for (p = s; *p != NUL; ) | |
4601 { | |
4602 if (vim_ispathsep(*p) | |
4603 #ifdef BACKSLASH_IN_FILENAME | |
4604 && !rem_backslash(p) | |
4605 #endif | |
4606 ) | |
4607 had_sep = TRUE; | |
4608 else if (had_sep) | |
4609 { | |
4610 t = p; | |
4611 had_sep = FALSE; | |
4612 } | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4613 MB_PTR_ADV(p); |
7 | 4614 } |
4615 return t; | |
4616 } | |
4617 | |
4618 /* | |
4619 * Return TRUE if we only need to show the tail of completion matches. | |
4620 * When not completing file names or there is a wildcard in the path FALSE is | |
4621 * returned. | |
4622 */ | |
4623 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4624 expand_showtail(expand_T *xp) |
7 | 4625 { |
4626 char_u *s; | |
4627 char_u *end; | |
4628 | |
4629 /* When not completing file names a "/" may mean something different. */ | |
714 | 4630 if (xp->xp_context != EXPAND_FILES |
4631 && xp->xp_context != EXPAND_SHELLCMD | |
4632 && xp->xp_context != EXPAND_DIRECTORIES) | |
7 | 4633 return FALSE; |
4634 | |
4635 end = gettail(xp->xp_pattern); | |
4636 if (end == xp->xp_pattern) /* there is no path separator */ | |
4637 return FALSE; | |
4638 | |
4639 for (s = xp->xp_pattern; s < end; s++) | |
4640 { | |
4641 /* Skip escaped wildcards. Only when the backslash is not a path | |
4642 * separator, on DOS the '*' "path\*\file" must not be skipped. */ | |
4643 if (rem_backslash(s)) | |
4644 ++s; | |
4645 else if (vim_strchr((char_u *)"*?[", *s) != NULL) | |
4646 return FALSE; | |
4647 } | |
4648 return TRUE; | |
4649 } | |
4650 | |
4651 /* | |
4652 * Prepare a string for expansion. | |
4653 * When expanding file names: The string will be used with expand_wildcards(). | |
5438 | 4654 * Copy "fname[len]" into allocated memory and add a '*' at the end. |
7 | 4655 * When expanding other names: The string will be used with regcomp(). Copy |
4656 * the name into allocated memory and prepend "^". | |
4657 */ | |
4658 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4659 addstar( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4660 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4661 int len, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4662 int context) /* EXPAND_FILES etc. */ |
7 | 4663 { |
4664 char_u *retval; | |
4665 int i, j; | |
4666 int new_len; | |
4667 char_u *tail; | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4668 int ends_in_star; |
7 | 4669 |
714 | 4670 if (context != EXPAND_FILES |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
4671 && context != EXPAND_FILES_IN_PATH |
714 | 4672 && context != EXPAND_SHELLCMD |
4673 && context != EXPAND_DIRECTORIES) | |
7 | 4674 { |
4675 /* | |
4676 * Matching will be done internally (on something other than files). | |
4677 * So we convert the file-matching-type wildcards into our kind for | |
4678 * use with vim_regcomp(). First work out how long it will be: | |
4679 */ | |
4680 | |
4681 /* For help tags the translation is done in find_help_tags(). | |
4682 * For a tag pattern starting with "/" no translation is needed. */ | |
4683 if (context == EXPAND_HELP | |
4684 || context == EXPAND_COLORS | |
4685 || context == EXPAND_COMPILER | |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
4686 || context == EXPAND_OWNSYNTAX |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
4687 || context == EXPAND_FILETYPE |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4688 || 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
|
4689 || ((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
|
4690 || 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
|
4691 && fname[0] == '/')) |
7 | 4692 retval = vim_strnsave(fname, len); |
4693 else | |
4694 { | |
4695 new_len = len + 2; /* +2 for '^' at start, NUL at end */ | |
4696 for (i = 0; i < len; i++) | |
4697 { | |
4698 if (fname[i] == '*' || fname[i] == '~') | |
4699 new_len++; /* '*' needs to be replaced by ".*" | |
4700 '~' needs to be replaced by "\~" */ | |
4701 | |
4702 /* Buffer names are like file names. "." should be literal */ | |
4703 if (context == EXPAND_BUFFERS && fname[i] == '.') | |
4704 new_len++; /* "." becomes "\." */ | |
4705 | |
4706 /* Custom expansion takes care of special things, match | |
4707 * backslashes literally (perhaps also for other types?) */ | |
634 | 4708 if ((context == EXPAND_USER_DEFINED |
4709 || context == EXPAND_USER_LIST) && fname[i] == '\\') | |
7 | 4710 new_len++; /* '\' becomes "\\" */ |
4711 } | |
4712 retval = alloc(new_len); | |
4713 if (retval != NULL) | |
4714 { | |
4715 retval[0] = '^'; | |
4716 j = 1; | |
4717 for (i = 0; i < len; i++, j++) | |
4718 { | |
4719 /* Skip backslash. But why? At least keep it for custom | |
4720 * expansion. */ | |
4721 if (context != EXPAND_USER_DEFINED | |
407 | 4722 && context != EXPAND_USER_LIST |
4723 && fname[i] == '\\' | |
4724 && ++i == len) | |
7 | 4725 break; |
4726 | |
4727 switch (fname[i]) | |
4728 { | |
4729 case '*': retval[j++] = '.'; | |
4730 break; | |
4731 case '~': retval[j++] = '\\'; | |
4732 break; | |
4733 case '?': retval[j] = '.'; | |
4734 continue; | |
4735 case '.': if (context == EXPAND_BUFFERS) | |
4736 retval[j++] = '\\'; | |
4737 break; | |
407 | 4738 case '\\': if (context == EXPAND_USER_DEFINED |
4739 || context == EXPAND_USER_LIST) | |
7 | 4740 retval[j++] = '\\'; |
4741 break; | |
4742 } | |
4743 retval[j] = fname[i]; | |
4744 } | |
4745 retval[j] = NUL; | |
4746 } | |
4747 } | |
4748 } | |
4749 else | |
4750 { | |
4751 retval = alloc(len + 4); | |
4752 if (retval != NULL) | |
4753 { | |
419 | 4754 vim_strncpy(retval, fname, len); |
7 | 4755 |
4756 /* | |
831 | 4757 * Don't add a star to *, ~, ~user, $var or `cmd`. |
4758 * * would become **, which walks the whole tree. | |
7 | 4759 * ~ would be at the start of the file name, but not the tail. |
4760 * $ could be anywhere in the tail. | |
4761 * ` could be anywhere in the file name. | |
1484 | 4762 * When the name ends in '$' don't add a star, remove the '$'. |
7 | 4763 */ |
4764 tail = gettail(retval); | |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4765 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
|
4766 #ifndef BACKSLASH_IN_FILENAME |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4767 for (i = len - 2; i >= 0; --i) |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4768 { |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4769 if (retval[i] != '\\') |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4770 break; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4771 ends_in_star = !ends_in_star; |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4772 } |
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4773 #endif |
7 | 4774 if ((*retval != '~' || tail != retval) |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2128
diff
changeset
|
4775 && !ends_in_star |
7 | 4776 && vim_strchr(tail, '$') == NULL |
4777 && vim_strchr(retval, '`') == NULL) | |
4778 retval[len++] = '*'; | |
1484 | 4779 else if (len > 0 && retval[len - 1] == '$') |
4780 --len; | |
7 | 4781 retval[len] = NUL; |
4782 } | |
4783 } | |
4784 return retval; | |
4785 } | |
4786 | |
4787 /* | |
4788 * Must parse the command line so far to work out what context we are in. | |
4789 * Completion can then be done based on that context. | |
4790 * This routine sets the variables: | |
4791 * xp->xp_pattern The start of the pattern to be expanded within | |
4792 * the command line (ends at the cursor). | |
4793 * xp->xp_context The type of thing to expand. Will be one of: | |
4794 * | |
4795 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on | |
4796 * the command line, like an unknown command. Caller | |
4797 * should beep. | |
4798 * EXPAND_NOTHING Unrecognised context for completion, use char like | |
4799 * a normal char, rather than for completion. eg | |
4800 * :s/^I/ | |
4801 * EXPAND_COMMANDS Cursor is still touching the command, so complete | |
4802 * it. | |
4803 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. | |
4804 * EXPAND_FILES After command with XFILE set, or after setting | |
4805 * with P_EXPAND set. eg :e ^I, :w>>^I | |
4806 * EXPAND_DIRECTORIES In some cases this is used instead of the latter | |
4807 * when we know only directories are of interest. eg | |
4808 * :set dir=^I | |
714 | 4809 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". |
7 | 4810 * EXPAND_SETTINGS Complete variable names. eg :set d^I |
4811 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I | |
4812 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I | |
4813 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect | |
4814 * EXPAND_HELP Complete tags from the file 'helpfile'/tags | |
4815 * EXPAND_EVENTS Complete event names | |
4816 * EXPAND_SYNTAX Complete :syntax command arguments | |
4817 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names | |
4818 * EXPAND_AUGROUP Complete autocommand group names | |
4819 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I | |
4820 * EXPAND_MAPPINGS Complete mapping and abbreviation names, | |
4821 * eg :unmap a^I , :cunab x^I | |
4822 * EXPAND_FUNCTIONS Complete internal or user defined function names, | |
4823 * eg :call sub^I | |
4824 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I | |
4825 * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
4826 * names in expressions, eg :while s^I | |
4827 * EXPAND_ENV_VARS Complete environment variable names | |
3744 | 4828 * EXPAND_USER Complete user names |
7 | 4829 */ |
4830 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4831 set_expand_context(expand_T *xp) |
7 | 4832 { |
168 | 4833 /* only expansion for ':', '>' and '=' command-lines */ |
7 | 4834 if (ccline.cmdfirstc != ':' |
4835 #ifdef FEAT_EVAL | |
168 | 4836 && ccline.cmdfirstc != '>' && ccline.cmdfirstc != '=' |
531 | 4837 && !ccline.input_fn |
7 | 4838 #endif |
4839 ) | |
4840 { | |
4841 xp->xp_context = EXPAND_NOTHING; | |
4842 return; | |
4843 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4844 set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE); |
7 | 4845 } |
4846 | |
4847 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4848 set_cmd_context( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4849 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4850 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
|
4851 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
|
4852 int col, /* position of cursor */ |
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4853 int use_ccline UNUSED) /* use ccline for info */ |
7 | 4854 { |
4855 int old_char = NUL; | |
4856 char_u *nextcomm; | |
4857 | |
4858 /* | |
4859 * Avoid a UMR warning from Purify, only save the character if it has been | |
4860 * written before. | |
4861 */ | |
4862 if (col < len) | |
4863 old_char = str[col]; | |
4864 str[col] = NUL; | |
4865 nextcomm = str; | |
168 | 4866 |
4867 #ifdef FEAT_EVAL | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4868 if (use_ccline && ccline.cmdfirstc == '=') |
1322 | 4869 { |
4870 # ifdef FEAT_CMDL_COMPL | |
168 | 4871 /* pass CMD_SIZE because there is no real command */ |
4872 set_context_for_expression(xp, str, CMD_SIZE); | |
1322 | 4873 # endif |
4874 } | |
10120
fb040c9d8ce9
commit https://github.com/vim/vim/commit/33a80eeb859a78ba93432da6fa585786cfd77249
Christian Brabandt <cb@256bit.org>
parents:
10098
diff
changeset
|
4875 else if (use_ccline && ccline.input_fn) |
531 | 4876 { |
4877 xp->xp_context = ccline.xp_context; | |
4878 xp->xp_pattern = ccline.cmdbuff; | |
1322 | 4879 # if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL) |
531 | 4880 xp->xp_arg = ccline.xp_arg; |
1322 | 4881 # endif |
531 | 4882 } |
168 | 4883 else |
4884 #endif | |
4885 while (nextcomm != NULL) | |
4886 nextcomm = set_one_cmd_context(xp, nextcomm); | |
4887 | |
5056
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4888 /* 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
|
4889 * easily. */ |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4890 xp->xp_line = str; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4891 xp->xp_col = col; |
034abed357a1
updated for version 7.3.1271
Bram Moolenaar <bram@vim.org>
parents:
5033
diff
changeset
|
4892 |
7 | 4893 str[col] = old_char; |
4894 } | |
4895 | |
4896 /* | |
4897 * Expand the command line "str" from context "xp". | |
4898 * "xp" must have been set by set_cmd_context(). | |
4899 * xp->xp_pattern points into "str", to where the text that is to be expanded | |
4900 * starts. | |
4901 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the | |
4902 * cursor. | |
4903 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the | |
4904 * key that triggered expansion literally. | |
4905 * Returns EXPAND_OK otherwise. | |
4906 */ | |
4907 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4908 expand_cmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4909 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4910 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
|
4911 int col, /* position of cursor */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4912 int *matchcount, /* return: nr of matches */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4913 char_u ***matches) /* return: array of pointers to matches */ |
7 | 4914 { |
4915 char_u *file_str = NULL; | |
2652 | 4916 int options = WILD_ADD_SLASH|WILD_SILENT; |
7 | 4917 |
4918 if (xp->xp_context == EXPAND_UNSUCCESSFUL) | |
4919 { | |
4920 beep_flush(); | |
4921 return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */ | |
4922 } | |
4923 if (xp->xp_context == EXPAND_NOTHING) | |
4924 { | |
4925 /* Caller can use the character as a normal char instead */ | |
4926 return EXPAND_NOTHING; | |
4927 } | |
4928 | |
4929 /* add star to file name, or convert to regexp if not exp. files. */ | |
1965 | 4930 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern); |
4931 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); | |
7 | 4932 if (file_str == NULL) |
4933 return EXPAND_UNSUCCESSFUL; | |
4934 | |
2652 | 4935 if (p_wic) |
4936 options += WILD_ICASE; | |
4937 | |
7 | 4938 /* find all files that match the description */ |
2652 | 4939 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) |
7 | 4940 { |
4941 *matchcount = 0; | |
4942 *matches = NULL; | |
4943 } | |
4944 vim_free(file_str); | |
4945 | |
4946 return EXPAND_OK; | |
4947 } | |
4948 | |
4949 #ifdef FEAT_MULTI_LANG | |
4950 /* | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4951 * Cleanup matches for help tags: |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4952 * 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
|
4953 * tag matches it. Otherwise remove "@en" if "en" is the only language. |
7 | 4954 */ |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
4955 static void cleanup_help_tags(int num_file, char_u **file); |
7 | 4956 |
4957 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4958 cleanup_help_tags(int num_file, char_u **file) |
7 | 4959 { |
4960 int i, j; | |
4961 int len; | |
8765
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4962 char_u buf[4]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4963 char_u *p = buf; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4964 |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4965 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
|
4966 { |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4967 *p++ = '@'; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4968 *p++ = p_hlg[0]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4969 *p++ = p_hlg[1]; |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4970 } |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4971 *p = NUL; |
7 | 4972 |
4973 for (i = 0; i < num_file; ++i) | |
4974 { | |
4975 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
|
4976 if (len <= 0) |
3daf70d22168
commit https://github.com/vim/vim/commit/61264d99692803eec76a171916ab9720c75536b0
Christian Brabandt <cb@256bit.org>
parents:
8694
diff
changeset
|
4977 continue; |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4978 if (STRCMP(file[i] + len, "@en") == 0) |
7 | 4979 { |
4980 /* Sorting on priority means the same item in another language may | |
4981 * be anywhere. Search all items for a match up to the "@en". */ | |
4982 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
|
4983 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
|
4984 && STRNCMP(file[i], file[j], len + 1) == 0) |
7 | 4985 break; |
4986 if (j == num_file) | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
4987 /* item only exists with @en, remove it */ |
7 | 4988 file[i][len] = NUL; |
4989 } | |
4990 } | |
9070
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4991 |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4992 if (*buf != NUL) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4993 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
|
4994 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4995 len = (int)STRLEN(file[i]) - 3; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4996 if (len <= 0) |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4997 continue; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
4998 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
|
4999 { |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5000 /* remove the default language */ |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5001 file[i][len] = NUL; |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5002 } |
0bb25b026fc9
commit https://github.com/vim/vim/commit/9ccaae04c6f263e6db14fc403bca2404a7871114
Christian Brabandt <cb@256bit.org>
parents:
9066
diff
changeset
|
5003 } |
7 | 5004 } |
5005 #endif | |
5006 | |
5007 /* | |
5008 * Do the expansion based on xp->xp_context and "pat". | |
5009 */ | |
5010 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5011 ExpandFromContext( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5012 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5013 char_u *pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5014 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5015 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5016 int options) /* EW_ flags */ |
7 | 5017 { |
5018 #ifdef FEAT_CMDL_COMPL | |
5019 regmatch_T regmatch; | |
5020 #endif | |
5021 int ret; | |
5022 int flags; | |
5023 | |
5024 flags = EW_DIR; /* include directories */ | |
5025 if (options & WILD_LIST_NOTFOUND) | |
5026 flags |= EW_NOTFOUND; | |
5027 if (options & WILD_ADD_SLASH) | |
5028 flags |= EW_ADDSLASH; | |
5029 if (options & WILD_KEEP_ALL) | |
5030 flags |= EW_KEEPALL; | |
5031 if (options & WILD_SILENT) | |
5032 flags |= EW_SILENT; | |
6659 | 5033 if (options & WILD_ALLLINKS) |
5034 flags |= EW_ALLLINKS; | |
7 | 5035 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5036 if (xp->xp_context == EXPAND_FILES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5037 || xp->xp_context == EXPAND_DIRECTORIES |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5038 || xp->xp_context == EXPAND_FILES_IN_PATH) |
7 | 5039 { |
5040 /* | |
5041 * Expand file or directory names. | |
5042 */ | |
5043 int free_pat = FALSE; | |
5044 int i; | |
5045 | |
5046 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5047 * space */ | |
5048 if (xp->xp_backslash != XP_BS_NONE) | |
5049 { | |
5050 free_pat = TRUE; | |
5051 pat = vim_strsave(pat); | |
5052 for (i = 0; pat[i]; ++i) | |
5053 if (pat[i] == '\\') | |
5054 { | |
5055 if (xp->xp_backslash == XP_BS_THREE | |
5056 && pat[i + 1] == '\\' | |
5057 && pat[i + 2] == '\\' | |
5058 && pat[i + 3] == ' ') | |
1621 | 5059 STRMOVE(pat + i, pat + i + 3); |
7 | 5060 if (xp->xp_backslash == XP_BS_ONE |
5061 && pat[i + 1] == ' ') | |
1621 | 5062 STRMOVE(pat + i, pat + i + 1); |
7 | 5063 } |
5064 } | |
5065 | |
5066 if (xp->xp_context == EXPAND_FILES) | |
5067 flags |= EW_FILE; | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2302
diff
changeset
|
5068 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
|
5069 flags |= (EW_FILE | EW_PATH); |
7 | 5070 else |
5071 flags = (flags | EW_DIR) & ~EW_FILE; | |
2652 | 5072 if (options & WILD_ICASE) |
5073 flags |= EW_ICASE; | |
5074 | |
2016 | 5075 /* Expand wildcards, supporting %:h and the like. */ |
5076 ret = expand_wildcards_eval(&pat, num_file, file, flags); | |
7 | 5077 if (free_pat) |
5078 vim_free(pat); | |
5079 return ret; | |
5080 } | |
5081 | |
5082 *file = (char_u **)""; | |
5083 *num_file = 0; | |
5084 if (xp->xp_context == EXPAND_HELP) | |
5085 { | |
1696 | 5086 /* With an empty argument we would get all the help tags, which is |
5087 * very slow. Get matches for "help" instead. */ | |
5088 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, | |
5089 num_file, file, FALSE) == OK) | |
7 | 5090 { |
5091 #ifdef FEAT_MULTI_LANG | |
5092 cleanup_help_tags(*num_file, *file); | |
5093 #endif | |
5094 return OK; | |
5095 } | |
5096 return FAIL; | |
5097 } | |
5098 | |
5099 #ifndef FEAT_CMDL_COMPL | |
5100 return FAIL; | |
5101 #else | |
716 | 5102 if (xp->xp_context == EXPAND_SHELLCMD) |
5103 return expand_shellcmd(pat, num_file, file, flags); | |
7 | 5104 if (xp->xp_context == EXPAND_OLD_SETTING) |
5105 return ExpandOldSetting(num_file, file); | |
5106 if (xp->xp_context == EXPAND_BUFFERS) | |
5107 return ExpandBufnames(pat, num_file, file, options); | |
5108 if (xp->xp_context == EXPAND_TAGS | |
5109 || xp->xp_context == EXPAND_TAGS_LISTFILES) | |
5110 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); | |
5111 if (xp->xp_context == EXPAND_COLORS) | |
2929 | 5112 { |
5113 char *directories[] = {"colors", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5114 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
|
5115 directories); |
2929 | 5116 } |
7 | 5117 if (xp->xp_context == EXPAND_COMPILER) |
2929 | 5118 { |
3106 | 5119 char *directories[] = {"compiler", NULL}; |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5120 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5121 } |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5122 if (xp->xp_context == EXPAND_OWNSYNTAX) |
2929 | 5123 { |
5124 char *directories[] = {"syntax", NULL}; | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5125 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5126 } |
2268
aafed4a4866f
Command line completion for :ownsyntax. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2243
diff
changeset
|
5127 if (xp->xp_context == EXPAND_FILETYPE) |
2929 | 5128 { |
5129 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
|
5130 return ExpandRTDir(pat, 0, num_file, file, directories); |
2929 | 5131 } |
407 | 5132 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5133 if (xp->xp_context == EXPAND_USER_LIST) | |
856 | 5134 return ExpandUserList(xp, num_file, file); |
407 | 5135 # endif |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5136 if (xp->xp_context == EXPAND_PACKADD) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5137 return ExpandPackAddDir(pat, num_file, file); |
7 | 5138 |
5139 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); | |
5140 if (regmatch.regprog == NULL) | |
5141 return FAIL; | |
5142 | |
5143 /* set ignore-case according to p_ic, p_scs and pat */ | |
5144 regmatch.rm_ic = ignorecase(pat); | |
5145 | |
5146 if (xp->xp_context == EXPAND_SETTINGS | |
5147 || xp->xp_context == EXPAND_BOOL_SETTINGS) | |
5148 ret = ExpandSettings(xp, ®match, num_file, file); | |
5149 else if (xp->xp_context == EXPAND_MAPPINGS) | |
5150 ret = ExpandMappings(®match, num_file, file); | |
5151 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) | |
5152 else if (xp->xp_context == EXPAND_USER_DEFINED) | |
5153 ret = ExpandUserDefined(xp, ®match, num_file, file); | |
5154 # endif | |
5155 else | |
5156 { | |
5157 static struct expgen | |
5158 { | |
5159 int context; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5160 char_u *((*func)(expand_T *, int)); |
7 | 5161 int ic; |
2849 | 5162 int escaped; |
7 | 5163 } tab[] = |
5164 { | |
2849 | 5165 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, |
5166 {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
|
5167 {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
|
5168 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE}, |
3503 | 5169 #ifdef FEAT_CMDHIST |
5170 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE}, | |
5171 #endif | |
7 | 5172 #ifdef FEAT_USR_CMDS |
2849 | 5173 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, |
6424 | 5174 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE}, |
2849 | 5175 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, |
5176 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
5177 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
7 | 5178 #endif |
5179 #ifdef FEAT_EVAL | |
2849 | 5180 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, |
5181 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
5182 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
5183 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
7 | 5184 #endif |
5185 #ifdef FEAT_MENU | |
2849 | 5186 {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, |
5187 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
7 | 5188 #endif |
5189 #ifdef FEAT_SYN_HL | |
2849 | 5190 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, |
5191 #endif | |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5192 #ifdef FEAT_PROFILE |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5193 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE}, |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4327
diff
changeset
|
5194 #endif |
2849 | 5195 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, |
5196 {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
5197 {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
1845 | 5198 #ifdef FEAT_CSCOPE |
2849 | 5199 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, |
1845 | 5200 #endif |
1868 | 5201 #ifdef FEAT_SIGNS |
2849 | 5202 {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, |
1868 | 5203 #endif |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5204 #ifdef FEAT_PROFILE |
2849 | 5205 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
5206 #endif |
7 | 5207 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
5208 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
2849 | 5209 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, |
5210 {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
5211 #endif | |
5212 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
3744 | 5213 {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
|
5214 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, |
7 | 5215 }; |
5216 int i; | |
5217 | |
5218 /* | |
5219 * Find a context in the table and call the ExpandGeneric() with the | |
5220 * right function to do the expansion. | |
5221 */ | |
5222 ret = FAIL; | |
1880 | 5223 for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i) |
7 | 5224 if (xp->xp_context == tab[i].context) |
5225 { | |
5226 if (tab[i].ic) | |
5227 regmatch.rm_ic = TRUE; | |
2849 | 5228 ret = ExpandGeneric(xp, ®match, num_file, file, |
3628 | 5229 tab[i].func, tab[i].escaped); |
7 | 5230 break; |
5231 } | |
5232 } | |
5233 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5234 vim_regfree(regmatch.regprog); |
7 | 5235 |
5236 return ret; | |
5237 #endif /* FEAT_CMDL_COMPL */ | |
5238 } | |
5239 | |
5240 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
5241 /* | |
5242 * Expand a list of names. | |
5243 * | |
5244 * Generic function for command line completion. It calls a function to | |
5245 * obtain strings, one by one. The strings are matched against a regexp | |
5246 * program. Matching strings are copied into an array, which is returned. | |
5247 * | |
5248 * Returns OK when no problems encountered, FAIL for error (out of memory). | |
5249 */ | |
5250 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5251 ExpandGeneric( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5252 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5253 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5254 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5255 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5256 char_u *((*func)(expand_T *, int)), |
7 | 5257 /* 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
|
5258 int escaped) |
7 | 5259 { |
5260 int i; | |
5261 int count = 0; | |
480 | 5262 int round; |
7 | 5263 char_u *str; |
5264 | |
5265 /* do this loop twice: | |
480 | 5266 * round == 0: count the number of matching names |
5267 * round == 1: copy the matching names into allocated memory | |
7 | 5268 */ |
480 | 5269 for (round = 0; round <= 1; ++round) |
7 | 5270 { |
5271 for (i = 0; ; ++i) | |
5272 { | |
5273 str = (*func)(xp, i); | |
5274 if (str == NULL) /* end of list */ | |
5275 break; | |
5276 if (*str == NUL) /* skip empty strings */ | |
5277 continue; | |
5278 | |
5279 if (vim_regexec(regmatch, str, (colnr_T)0)) | |
5280 { | |
480 | 5281 if (round) |
7 | 5282 { |
2849 | 5283 if (escaped) |
5284 str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
5285 else | |
5286 str = vim_strsave(str); | |
7 | 5287 (*file)[count] = str; |
5288 #ifdef FEAT_MENU | |
5289 if (func == get_menu_names && str != NULL) | |
5290 { | |
5291 /* test for separator added by get_menu_names() */ | |
5292 str += STRLEN(str) - 1; | |
5293 if (*str == '\001') | |
5294 *str = '.'; | |
5295 } | |
5296 #endif | |
5297 } | |
5298 ++count; | |
5299 } | |
5300 } | |
480 | 5301 if (round == 0) |
7 | 5302 { |
5303 if (count == 0) | |
5304 return OK; | |
5305 *num_file = count; | |
5306 *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); | |
5307 if (*file == NULL) | |
5308 { | |
5309 *file = (char_u **)""; | |
5310 return FAIL; | |
5311 } | |
5312 count = 0; | |
5313 } | |
5314 } | |
480 | 5315 |
828 | 5316 /* Sort the results. Keep menu's in the specified order. */ |
5317 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) | |
3164 | 5318 { |
5319 if (xp->xp_context == EXPAND_EXPRESSION | |
5320 || xp->xp_context == EXPAND_FUNCTIONS | |
5321 || xp->xp_context == EXPAND_USER_FUNC) | |
5322 /* <SNR> functions should be sorted to the end. */ | |
5323 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *), | |
5324 sort_func_compare); | |
5325 else | |
5326 sort_strings(*file, *num_file); | |
5327 } | |
480 | 5328 |
1322 | 5329 #ifdef FEAT_CMDL_COMPL |
5330 /* Reset the variables used for special highlight names expansion, so that | |
5331 * they don't show up when getting normal highlight names by ID. */ | |
5332 reset_expand_highlight(); | |
5333 #endif | |
5334 | |
7 | 5335 return OK; |
5336 } | |
5337 | |
716 | 5338 /* |
5339 * Complete a shell command. | |
5340 * Returns FAIL or OK; | |
5341 */ | |
5342 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5343 expand_shellcmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5344 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
|
5345 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
|
5346 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
|
5347 int flagsarg) /* EW_ flags */ |
716 | 5348 { |
5349 char_u *pat; | |
5350 int i; | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5351 char_u *path = NULL; |
716 | 5352 int mustfree = FALSE; |
5353 garray_T ga; | |
5354 char_u *buf = alloc(MAXPATHL); | |
5355 size_t l; | |
5356 char_u *s, *e; | |
5357 int flags = flagsarg; | |
5358 int ret; | |
6695 | 5359 int did_curdir = FALSE; |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5360 hashtab_T found_ht; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5361 hashitem_T *hi; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5362 hash_T hash; |
716 | 5363 |
5364 if (buf == NULL) | |
5365 return FAIL; | |
5366 | |
5367 /* for ":set path=" and ":set tags=" halve backslashes for escaped | |
5368 * space */ | |
5369 pat = vim_strsave(filepat); | |
5370 for (i = 0; pat[i]; ++i) | |
5371 if (pat[i] == '\\' && pat[i + 1] == ' ') | |
1621 | 5372 STRMOVE(pat + i, pat + i + 1); |
716 | 5373 |
6695 | 5374 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; |
716 | 5375 |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5376 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
|
5377 || (pat[1] == '.' && vim_ispathsep(pat[2])))) |
716 | 5378 path = (char_u *)"."; |
5379 else | |
2630 | 5380 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5381 /* 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
|
5382 if (!mch_isFullName(pat)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5383 path = vim_getenv((char_u *)"PATH", &mustfree); |
2630 | 5384 if (path == NULL) |
5385 path = (char_u *)""; | |
5386 } | |
716 | 5387 |
5388 /* | |
5389 * Go over all directories in $PATH. Expand matches in that directory and | |
6695 | 5390 * collect them in "ga". When "." is not in $PATH also expand for the |
5391 * current directory, to find "subdir/cmd". | |
716 | 5392 */ |
5393 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
|
5394 hash_init(&found_ht); |
6695 | 5395 for (s = path; ; s = e) |
716 | 5396 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5397 #if defined(MSWIN) |
716 | 5398 e = vim_strchr(s, ';'); |
5399 #else | |
5400 e = vim_strchr(s, ':'); | |
5401 #endif | |
5402 if (e == NULL) | |
5403 e = s + STRLEN(s); | |
5404 | |
14417
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5405 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
|
5406 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5407 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
|
5408 break; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5409 // 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
|
5410 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
|
5411 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
|
5412 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5413 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
|
5414 { |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5415 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
|
5416 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
|
5417 } |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5418 else |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5419 // 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
|
5420 flags &= ~EW_DIR; |
5d9b450e7827
patch 8.1.0223: completing shell command finds sub-directories in $PATH
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
5421 |
716 | 5422 l = e - s; |
5423 if (l > MAXPATHL - 5) | |
5424 break; | |
5425 vim_strncpy(buf, s, l); | |
5426 add_pathsep(buf); | |
5427 l = STRLEN(buf); | |
5428 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l); | |
5429 | |
5430 /* Expand matches in one directory of $PATH. */ | |
5431 ret = expand_wildcards(1, &buf, num_file, file, flags); | |
5432 if (ret == OK) | |
5433 { | |
5434 if (ga_grow(&ga, *num_file) == FAIL) | |
5435 FreeWild(*num_file, *file); | |
5436 else | |
5437 { | |
5438 for (i = 0; i < *num_file; ++i) | |
5439 { | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5440 char_u *name = (*file)[i]; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5441 |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5442 if (STRLEN(name) > l) |
716 | 5443 { |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5444 // 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
|
5445 hash = hash_hash(name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5446 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
|
5447 if (HASHITEM_EMPTY(hi)) |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5448 { |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5449 // 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
|
5450 STRMOVE(name, name + l); |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5451 ((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
|
5452 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
|
5453 name = NULL; |
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5454 } |
716 | 5455 } |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5456 vim_free(name); |
716 | 5457 } |
5458 vim_free(*file); | |
5459 } | |
5460 } | |
5461 if (*e != NUL) | |
5462 ++e; | |
5463 } | |
5464 *file = ga.ga_data; | |
5465 *num_file = ga.ga_len; | |
5466 | |
5467 vim_free(buf); | |
5468 vim_free(pat); | |
5469 if (mustfree) | |
5470 vim_free(path); | |
13998
c3f9c37160e7
patch 8.1.0017: shell command completion has duplicates
Christian Brabandt <cb@256bit.org>
parents:
13933
diff
changeset
|
5471 hash_clear(&found_ht); |
716 | 5472 return OK; |
5473 } | |
5474 | |
5475 | |
7 | 5476 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) |
5477 /* | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10861
diff
changeset
|
5478 * 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
|
5479 * return the result (either a string or a List). |
7 | 5480 */ |
407 | 5481 static void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5482 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
|
5483 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
|
5484 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5485 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5486 char_u ***file) |
7 | 5487 { |
5072
cca600e60928
updated for version 7.3.1279
Bram Moolenaar <bram@vim.org>
parents:
5056
diff
changeset
|
5488 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
|
5489 typval_T args[4]; |
7 | 5490 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
|
5491 char_u *pat = NULL; |
407 | 5492 void *ret; |
13 | 5493 struct cmdline_info save_ccline; |
7 | 5494 |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5495 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) |
407 | 5496 return NULL; |
7 | 5497 *num_file = 0; |
5498 *file = NULL; | |
5499 | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5500 if (ccline.cmdbuff != NULL) |
1518 | 5501 { |
5502 keep = ccline.cmdbuff[ccline.cmdlen]; | |
5503 ccline.cmdbuff[ccline.cmdlen] = 0; | |
5504 } | |
5033
7aa4e0822dec
updated for version 7.3.1260
Bram Moolenaar <bram@vim.org>
parents:
4980
diff
changeset
|
5505 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5506 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
|
5507 |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5508 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
|
5509 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
|
5510 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
|
5511 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
|
5512 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
|
5513 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
|
5514 args[3].v_type = VAR_UNKNOWN; |
7 | 5515 |
13 | 5516 /* Save the cmdline, we don't know what the function may do. */ |
5517 save_ccline = ccline; | |
5518 ccline.cmdbuff = NULL; | |
5519 ccline.cmdprompt = NULL; | |
7 | 5520 current_SID = xp->xp_scriptID; |
13 | 5521 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14417
diff
changeset
|
5522 ret = user_expand_func(xp->xp_arg, 3, args); |
13 | 5523 |
5524 ccline = save_ccline; | |
7 | 5525 current_SID = save_current_SID; |
1518 | 5526 if (ccline.cmdbuff != NULL) |
5527 ccline.cmdbuff[ccline.cmdlen] = keep; | |
407 | 5528 |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
13998
diff
changeset
|
5529 vim_free(pat); |
407 | 5530 return ret; |
5531 } | |
5532 | |
5533 /* | |
5534 * Expand names with a function defined by the user. | |
5535 */ | |
5536 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5537 ExpandUserDefined( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5538 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5539 regmatch_T *regmatch, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5540 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5541 char_u ***file) |
407 | 5542 { |
5543 char_u *retstr; | |
5544 char_u *s; | |
5545 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
|
5546 int keep; |
407 | 5547 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
|
5548 int skip; |
407 | 5549 |
5550 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file); | |
5551 if (retstr == NULL) | |
7 | 5552 return FAIL; |
5553 | |
5554 ga_init2(&ga, (int)sizeof(char *), 3); | |
407 | 5555 for (s = retstr; *s != NUL; s = e) |
7 | 5556 { |
5557 e = vim_strchr(s, '\n'); | |
5558 if (e == NULL) | |
5559 e = s + STRLEN(s); | |
5560 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
|
5561 *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
|
5562 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5563 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
|
5564 *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
|
5565 |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5566 if (!skip) |
7 | 5567 { |
13256
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5568 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
|
5569 break; |
69e86e6e5703
patch 8.0.1502: in out-of-memory situation character is not restored
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5570 ((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
|
5571 ++ga.ga_len; |
7 | 5572 } |
5573 | |
5574 if (*e != NUL) | |
5575 ++e; | |
5576 } | |
407 | 5577 vim_free(retstr); |
5578 *file = ga.ga_data; | |
5579 *num_file = ga.ga_len; | |
5580 return OK; | |
5581 } | |
5582 | |
5583 /* | |
5584 * Expand names with a list returned by a function defined by the user. | |
5585 */ | |
5586 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5587 ExpandUserList( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5588 expand_T *xp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5589 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5590 char_u ***file) |
407 | 5591 { |
5592 list_T *retlist; | |
5593 listitem_T *li; | |
5594 garray_T ga; | |
5595 | |
5596 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file); | |
5597 if (retlist == NULL) | |
5598 return FAIL; | |
5599 | |
5600 ga_init2(&ga, (int)sizeof(char *), 3); | |
5601 /* Loop over the items in the list. */ | |
5602 for (li = retlist->lv_first; li != NULL; li = li->li_next) | |
5603 { | |
1917 | 5604 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL) |
5605 continue; /* Skip non-string items and empty strings */ | |
407 | 5606 |
5607 if (ga_grow(&ga, 1) == FAIL) | |
5608 break; | |
5609 | |
5610 ((char_u **)ga.ga_data)[ga.ga_len] = | |
1917 | 5611 vim_strsave(li->li_tv.vval.v_string); |
407 | 5612 ++ga.ga_len; |
5613 } | |
5614 list_unref(retlist); | |
5615 | |
7 | 5616 *file = ga.ga_data; |
5617 *num_file = ga.ga_len; | |
5618 return OK; | |
5619 } | |
5620 #endif | |
5621 | |
5622 /* | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5623 * 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
|
5624 * Search from 'runtimepath': |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5625 * 'runtimepath'/{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5626 * 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
|
5627 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5628 * 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
|
5629 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
2929 | 5630 * "dirnames" is an array with one or more directory names. |
7 | 5631 */ |
5632 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5633 ExpandRTDir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5634 char_u *pat, |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5635 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5636 int *num_file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5637 char_u ***file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5638 char *dirnames[]) |
7 | 5639 { |
5640 char_u *s; | |
5641 char_u *e; | |
5873 | 5642 char_u *match; |
7 | 5643 garray_T ga; |
2929 | 5644 int i; |
5645 int pat_len; | |
7 | 5646 |
5647 *num_file = 0; | |
5648 *file = NULL; | |
2931 | 5649 pat_len = (int)STRLEN(pat); |
2929 | 5650 ga_init2(&ga, (int)sizeof(char *), 10); |
5651 | |
5652 for (i = 0; dirnames[i] != NULL; ++i) | |
7 | 5653 { |
2929 | 5654 s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); |
5655 if (s == NULL) | |
5656 { | |
5657 ga_clear_strings(&ga); | |
5658 return FAIL; | |
5659 } | |
5660 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); | |
5873 | 5661 globpath(p_rtp, s, &ga, 0); |
2929 | 5662 vim_free(s); |
5873 | 5663 } |
5664 | |
8528
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5665 if (flags & DIP_START) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5666 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
|
5667 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5668 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
|
5669 if (s == NULL) |
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 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5672 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5673 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5674 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
|
5675 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5676 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5677 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5678 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5679 |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5680 if (flags & DIP_OPT) { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5681 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
|
5682 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5683 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
|
5684 if (s == NULL) |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5685 { |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5686 ga_clear_strings(&ga); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5687 return FAIL; |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5688 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5689 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
|
5690 globpath(p_pp, s, &ga, 0); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5691 vim_free(s); |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5692 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5693 } |
630300c7a26c
commit https://github.com/vim/vim/commit/52f9c19015df5ee1ee8592b6f3f15b8a57c8f5be
Christian Brabandt <cb@256bit.org>
parents:
8406
diff
changeset
|
5694 |
5873 | 5695 for (i = 0; i < ga.ga_len; ++i) |
5696 { | |
5697 match = ((char_u **)ga.ga_data)[i]; | |
5698 s = match; | |
5699 e = s + STRLEN(s); | |
5700 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) | |
7 | 5701 { |
5873 | 5702 e -= 4; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5703 for (s = e; s > match; MB_PTR_BACK(match, s)) |
5873 | 5704 if (s < match || vim_ispathsep(*s)) |
5705 break; | |
5706 ++s; | |
5707 *e = NUL; | |
5708 mch_memmove(match, s, e - s + 1); | |
7 | 5709 } |
5710 } | |
5873 | 5711 |
2929 | 5712 if (ga.ga_len == 0) |
3628 | 5713 return FAIL; |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5714 |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5715 /* Sort and remove duplicates which can happen when specifying multiple |
2929 | 5716 * directories in dirnames. */ |
2433
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5717 remove_duplicates(&ga); |
98b9a6b9e7d5
Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents:
2429
diff
changeset
|
5718 |
7 | 5719 *file = ga.ga_data; |
5720 *num_file = ga.ga_len; | |
5721 return OK; | |
5722 } | |
5723 | |
8402
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5724 /* |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5725 * Expand loadplugin names: |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5726 * 'packpath'/pack/ * /opt/{pat} |
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 static int |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5729 ExpandPackAddDir( |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5730 char_u *pat, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5731 int *num_file, |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5732 char_u ***file) |
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 char_u *s; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5735 char_u *e; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5736 char_u *match; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5737 garray_T ga; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5738 int i; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5739 int pat_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5740 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5741 *num_file = 0; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5742 *file = NULL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5743 pat_len = (int)STRLEN(pat); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5744 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
|
5745 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5746 s = alloc((unsigned)(pat_len + 26)); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5747 if (s == NULL) |
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 ga_clear_strings(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5750 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5751 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5752 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
|
5753 globpath(p_pp, s, &ga, 0); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5754 vim_free(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5755 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5756 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
|
5757 { |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5758 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
|
5759 s = gettail(match); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5760 e = s + STRLEN(s); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5761 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
|
5762 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5763 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5764 if (ga.ga_len == 0) |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5765 return FAIL; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5766 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5767 /* 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
|
5768 * directories in dirnames. */ |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5769 remove_duplicates(&ga); |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5770 |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5771 *file = ga.ga_data; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5772 *num_file = ga.ga_len; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5773 return OK; |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5774 } |
eed1ca42f9aa
commit https://github.com/vim/vim/commit/35ca0e7a1cb6e6daef8e0052a8437801226cef19
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5775 |
7 | 5776 #endif |
5777 | |
5778 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO) | |
5779 /* | |
5780 * Expand "file" for all comma-separated directories in "path". | |
5873 | 5781 * Adds the matches to "ga". Caller must init "ga". |
7 | 5782 */ |
5873 | 5783 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5784 globpath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5785 char_u *path, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5786 char_u *file, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5787 garray_T *ga, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5788 int expand_options) |
7 | 5789 { |
5790 expand_T xpc; | |
5791 char_u *buf; | |
5792 int i; | |
5793 int num_p; | |
5794 char_u **p; | |
5795 | |
5796 buf = alloc(MAXPATHL); | |
5797 if (buf == NULL) | |
5873 | 5798 return; |
7 | 5799 |
632 | 5800 ExpandInit(&xpc); |
7 | 5801 xpc.xp_context = EXPAND_FILES; |
632 | 5802 |
7 | 5803 /* Loop over all entries in {path}. */ |
5804 while (*path != NUL) | |
5805 { | |
5806 /* Copy one item of the path to buf[] and concatenate the file name. */ | |
5807 copy_option_part(&path, buf, MAXPATHL, ","); | |
5808 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL) | |
5809 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
5810 # 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
|
5811 /* 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
|
5812 * 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
|
5813 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
|
5814 STRCAT(buf, "/"); |
a847363bf06e
Fix a few problems for :find completion. Test much more. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
5815 # else |
7 | 5816 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
|
5817 # endif |
7 | 5818 STRCAT(buf, file); |
1754 | 5819 if (ExpandFromContext(&xpc, buf, &num_p, &p, |
5820 WILD_SILENT|expand_options) != FAIL && num_p > 0) | |
7 | 5821 { |
1754 | 5822 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options); |
5873 | 5823 |
5824 if (ga_grow(ga, num_p) == OK) | |
7 | 5825 { |
5826 for (i = 0; i < num_p; ++i) | |
5827 { | |
5873 | 5828 ((char_u **)ga->ga_data)[ga->ga_len] = |
5950 | 5829 vim_strnsave(p[i], (int)STRLEN(p[i])); |
5873 | 5830 ++ga->ga_len; |
7 | 5831 } |
5832 } | |
5873 | 5833 |
7 | 5834 FreeWild(num_p, p); |
5835 } | |
5836 } | |
5837 } | |
5838 | |
5839 vim_free(buf); | |
5840 } | |
5841 | |
5842 #endif | |
5843 | |
5844 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
5845 | |
5846 /********************************* | |
5847 * Command line history stuff * | |
5848 *********************************/ | |
5849 | |
5850 /* | |
5851 * Translate a history character to the associated type number. | |
5852 */ | |
5853 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5854 hist_char2type(int c) |
7 | 5855 { |
5856 if (c == ':') | |
5857 return HIST_CMD; | |
5858 if (c == '=') | |
5859 return HIST_EXPR; | |
5860 if (c == '@') | |
5861 return HIST_INPUT; | |
5862 if (c == '>') | |
5863 return HIST_DEBUG; | |
5864 return HIST_SEARCH; /* must be '?' or '/' */ | |
5865 } | |
5866 | |
5867 /* | |
5868 * Table of history names. | |
5869 * These names are used in :history and various hist...() functions. | |
5870 * It is sufficient to give the significant prefix of a history name. | |
5871 */ | |
5872 | |
5873 static char *(history_names[]) = | |
5874 { | |
5875 "cmd", | |
5876 "search", | |
5877 "expr", | |
5878 "input", | |
5879 "debug", | |
5880 NULL | |
5881 }; | |
5882 | |
3503 | 5883 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
5884 /* | |
5885 * Function given to ExpandGeneric() to obtain the possible first | |
5886 * arguments of the ":history command. | |
5887 */ | |
5888 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5889 get_history_arg(expand_T *xp UNUSED, int idx) |
3503 | 5890 { |
5891 static char_u compl[2] = { NUL, NUL }; | |
5892 char *short_names = ":=@>?/"; | |
3529 | 5893 int short_names_count = (int)STRLEN(short_names); |
3503 | 5894 int history_name_count = sizeof(history_names) / sizeof(char *) - 1; |
5895 | |
5896 if (idx < short_names_count) | |
5897 { | |
5898 compl[0] = (char_u)short_names[idx]; | |
5899 return compl; | |
5900 } | |
5901 if (idx < short_names_count + history_name_count) | |
5902 return (char_u *)history_names[idx - short_names_count]; | |
5903 if (idx == short_names_count + history_name_count) | |
5904 return (char_u *)"all"; | |
5905 return NULL; | |
5906 } | |
5907 #endif | |
5908 | |
7 | 5909 /* |
5910 * init_history() - Initialize the command line history. | |
5911 * Also used to re-allocate the history when the size changes. | |
5912 */ | |
356 | 5913 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5914 init_history(void) |
7 | 5915 { |
5916 int newlen; /* new length of history table */ | |
5917 histentry_T *temp; | |
5918 int i; | |
5919 int j; | |
5920 int type; | |
5921 | |
5922 /* | |
5923 * If size of history table changed, reallocate it | |
5924 */ | |
5925 newlen = (int)p_hi; | |
5926 if (newlen != hislen) /* history length changed */ | |
5927 { | |
5928 for (type = 0; type < HIST_COUNT; ++type) /* adjust the tables */ | |
5929 { | |
5930 if (newlen) | |
5931 { | |
5932 temp = (histentry_T *)lalloc( | |
5933 (long_u)(newlen * sizeof(histentry_T)), TRUE); | |
5934 if (temp == NULL) /* out of memory! */ | |
5935 { | |
5936 if (type == 0) /* first one: just keep the old length */ | |
5937 { | |
5938 newlen = hislen; | |
5939 break; | |
5940 } | |
5941 /* Already changed one table, now we can only have zero | |
5942 * length for all tables. */ | |
5943 newlen = 0; | |
5944 type = -1; | |
5945 continue; | |
5946 } | |
5947 } | |
5948 else | |
5949 temp = NULL; | |
5950 if (newlen == 0 || temp != NULL) | |
5951 { | |
5952 if (hisidx[type] < 0) /* there are no entries yet */ | |
5953 { | |
5954 for (i = 0; i < newlen; ++i) | |
4258 | 5955 clear_hist_entry(&temp[i]); |
7 | 5956 } |
5957 else if (newlen > hislen) /* array becomes bigger */ | |
5958 { | |
5959 for (i = 0; i <= hisidx[type]; ++i) | |
5960 temp[i] = history[type][i]; | |
5961 j = i; | |
5962 for ( ; i <= newlen - (hislen - hisidx[type]); ++i) | |
4258 | 5963 clear_hist_entry(&temp[i]); |
7 | 5964 for ( ; j < hislen; ++i, ++j) |
5965 temp[i] = history[type][j]; | |
5966 } | |
5967 else /* array becomes smaller or 0 */ | |
5968 { | |
5969 j = hisidx[type]; | |
5970 for (i = newlen - 1; ; --i) | |
5971 { | |
5972 if (i >= 0) /* copy newest entries */ | |
5973 temp[i] = history[type][j]; | |
5974 else /* remove older entries */ | |
5975 vim_free(history[type][j].hisstr); | |
5976 if (--j < 0) | |
5977 j = hislen - 1; | |
5978 if (j == hisidx[type]) | |
5979 break; | |
5980 } | |
5981 hisidx[type] = newlen - 1; | |
5982 } | |
5983 vim_free(history[type]); | |
5984 history[type] = temp; | |
5985 } | |
5986 } | |
5987 hislen = newlen; | |
5988 } | |
5989 } | |
5990 | |
4258 | 5991 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5992 clear_hist_entry(histentry_T *hisptr) |
4258 | 5993 { |
5994 hisptr->hisnum = 0; | |
5995 hisptr->viminfo = FALSE; | |
5996 hisptr->hisstr = NULL; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
5997 hisptr->time_set = 0; |
4258 | 5998 } |
5999 | |
7 | 6000 /* |
6001 * Check if command line 'str' is already in history. | |
6002 * If 'move_to_front' is TRUE, matching entry is moved to end of history. | |
6003 */ | |
6004 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6005 in_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6006 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6007 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6008 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
|
6009 int sep, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6010 int writing) /* ignore entries read from viminfo */ |
7 | 6011 { |
6012 int i; | |
6013 int last_i = -1; | |
2986 | 6014 char_u *p; |
7 | 6015 |
6016 if (hisidx[type] < 0) | |
6017 return FALSE; | |
6018 i = hisidx[type]; | |
6019 do | |
6020 { | |
6021 if (history[type][i].hisstr == NULL) | |
6022 return FALSE; | |
2986 | 6023 |
6024 /* For search history, check that the separator character matches as | |
6025 * well. */ | |
6026 p = history[type][i].hisstr; | |
6027 if (STRCMP(str, p) == 0 | |
4285 | 6028 && !(writing && history[type][i].viminfo) |
2986 | 6029 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
7 | 6030 { |
6031 if (!move_to_front) | |
6032 return TRUE; | |
6033 last_i = i; | |
6034 break; | |
6035 } | |
6036 if (--i < 0) | |
6037 i = hislen - 1; | |
6038 } while (i != hisidx[type]); | |
6039 | |
6040 if (last_i >= 0) | |
6041 { | |
6042 str = history[type][i].hisstr; | |
6043 while (i != hisidx[type]) | |
6044 { | |
6045 if (++i >= hislen) | |
6046 i = 0; | |
6047 history[type][last_i] = history[type][i]; | |
6048 last_i = i; | |
6049 } | |
4258 | 6050 history[type][i].hisnum = ++hisnum[type]; |
6051 history[type][i].viminfo = FALSE; | |
7 | 6052 history[type][i].hisstr = str; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6053 history[type][i].time_set = vim_time(); |
7 | 6054 return TRUE; |
6055 } | |
6056 return FALSE; | |
6057 } | |
6058 | |
6059 /* | |
6060 * Convert history name (from table above) to its HIST_ equivalent. | |
6061 * When "name" is empty, return "cmd" history. | |
6062 * Returns -1 for unknown history name. | |
6063 */ | |
6064 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6065 get_histtype(char_u *name) |
7 | 6066 { |
6067 int i; | |
6068 int len = (int)STRLEN(name); | |
6069 | |
6070 /* No argument: use current history. */ | |
6071 if (len == 0) | |
6072 return hist_char2type(ccline.cmdfirstc); | |
6073 | |
6074 for (i = 0; history_names[i] != NULL; ++i) | |
6075 if (STRNICMP(name, history_names[i], len) == 0) | |
6076 return i; | |
6077 | |
6078 if (vim_strchr((char_u *)":=@>?/", name[0]) != NULL && name[1] == NUL) | |
6079 return hist_char2type(name[0]); | |
6080 | |
6081 return -1; | |
6082 } | |
6083 | |
6084 static int last_maptick = -1; /* last seen maptick */ | |
6085 | |
6086 /* | |
6087 * Add the given string to the given history. If the string is already in the | |
6088 * history then it is moved to the front. "histype" may be one of he HIST_ | |
6089 * values. | |
6090 */ | |
6091 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6092 add_to_history( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6093 int histype, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6094 char_u *new_entry, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6095 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
|
6096 int sep) /* separator character used (search hist) */ |
7 | 6097 { |
6098 histentry_T *hisptr; | |
6099 int len; | |
6100 | |
6101 if (hislen == 0) /* no history */ | |
6102 return; | |
6103 | |
5467 | 6104 if (cmdmod.keeppatterns && histype == HIST_SEARCH) |
6105 return; | |
6106 | |
7 | 6107 /* |
6108 * Searches inside the same mapping overwrite each other, so that only | |
6109 * the last line is kept. Be careful not to remove a line that was moved | |
6110 * down, only lines that were added. | |
6111 */ | |
6112 if (histype == HIST_SEARCH && in_map) | |
6113 { | |
10174
b17c82587755
commit https://github.com/vim/vim/commit/46643713dc6bb04b4e84986b1763ef309e960161
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
6114 if (maptick == last_maptick && hisidx[HIST_SEARCH] >= 0) |
7 | 6115 { |
6116 /* Current line is from the same mapping, remove it */ | |
6117 hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; | |
6118 vim_free(hisptr->hisstr); | |
4258 | 6119 clear_hist_entry(hisptr); |
7 | 6120 --hisnum[histype]; |
6121 if (--hisidx[HIST_SEARCH] < 0) | |
6122 hisidx[HIST_SEARCH] = hislen - 1; | |
6123 } | |
6124 last_maptick = -1; | |
6125 } | |
4285 | 6126 if (!in_history(histype, new_entry, TRUE, sep, FALSE)) |
7 | 6127 { |
6128 if (++hisidx[histype] == hislen) | |
6129 hisidx[histype] = 0; | |
6130 hisptr = &history[histype][hisidx[histype]]; | |
6131 vim_free(hisptr->hisstr); | |
6132 | |
6133 /* Store the separator after the NUL of the string. */ | |
835 | 6134 len = (int)STRLEN(new_entry); |
7 | 6135 hisptr->hisstr = vim_strnsave(new_entry, len + 2); |
6136 if (hisptr->hisstr != NULL) | |
6137 hisptr->hisstr[len + 1] = sep; | |
6138 | |
6139 hisptr->hisnum = ++hisnum[histype]; | |
4258 | 6140 hisptr->viminfo = FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6141 hisptr->time_set = vim_time(); |
7 | 6142 if (histype == HIST_SEARCH && in_map) |
6143 last_maptick = maptick; | |
6144 } | |
6145 } | |
6146 | |
6147 #if defined(FEAT_EVAL) || defined(PROTO) | |
6148 | |
6149 /* | |
6150 * Get identifier of newest history entry. | |
6151 * "histype" may be one of the HIST_ values. | |
6152 */ | |
6153 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6154 get_history_idx(int histype) |
7 | 6155 { |
6156 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6157 || hisidx[histype] < 0) | |
6158 return -1; | |
6159 | |
6160 return history[histype][hisidx[histype]].hisnum; | |
6161 } | |
6162 | |
531 | 6163 /* |
7 | 6164 * Calculate history index from a number: |
6165 * num > 0: seen as identifying number of a history entry | |
6166 * num < 0: relative position in history wrt newest entry | |
6167 * "histype" may be one of the HIST_ values. | |
6168 */ | |
6169 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6170 calc_hist_idx(int histype, int num) |
7 | 6171 { |
6172 int i; | |
6173 histentry_T *hist; | |
6174 int wrapped = FALSE; | |
6175 | |
6176 if (hislen == 0 || histype < 0 || histype >= HIST_COUNT | |
6177 || (i = hisidx[histype]) < 0 || num == 0) | |
6178 return -1; | |
6179 | |
6180 hist = history[histype]; | |
6181 if (num > 0) | |
6182 { | |
6183 while (hist[i].hisnum > num) | |
6184 if (--i < 0) | |
6185 { | |
6186 if (wrapped) | |
6187 break; | |
6188 i += hislen; | |
6189 wrapped = TRUE; | |
6190 } | |
6191 if (hist[i].hisnum == num && hist[i].hisstr != NULL) | |
6192 return i; | |
6193 } | |
6194 else if (-num <= hislen) | |
6195 { | |
6196 i += num + 1; | |
6197 if (i < 0) | |
6198 i += hislen; | |
6199 if (hist[i].hisstr != NULL) | |
6200 return i; | |
6201 } | |
6202 return -1; | |
6203 } | |
6204 | |
6205 /* | |
6206 * Get a history entry by its index. | |
6207 * "histype" may be one of the HIST_ values. | |
6208 */ | |
6209 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6210 get_history_entry(int histype, int idx) |
7 | 6211 { |
6212 idx = calc_hist_idx(histype, idx); | |
6213 if (idx >= 0) | |
6214 return history[histype][idx].hisstr; | |
6215 else | |
6216 return (char_u *)""; | |
6217 } | |
6218 | |
6219 /* | |
6220 * Clear all entries of a history. | |
6221 * "histype" may be one of the HIST_ values. | |
6222 */ | |
6223 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6224 clr_history(int histype) |
7 | 6225 { |
6226 int i; | |
6227 histentry_T *hisptr; | |
6228 | |
6229 if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) | |
6230 { | |
6231 hisptr = history[histype]; | |
6232 for (i = hislen; i--;) | |
6233 { | |
6234 vim_free(hisptr->hisstr); | |
4258 | 6235 clear_hist_entry(hisptr); |
8406
5d926807c19c
commit https://github.com/vim/vim/commit/119d4693e06e68d4f099aa7287e375ae3d265fd0
Christian Brabandt <cb@256bit.org>
parents:
8402
diff
changeset
|
6236 hisptr++; |
7 | 6237 } |
6238 hisidx[histype] = -1; /* mark history as cleared */ | |
6239 hisnum[histype] = 0; /* reset identifier counter */ | |
6240 return OK; | |
6241 } | |
6242 return FAIL; | |
6243 } | |
6244 | |
6245 /* | |
6246 * Remove all entries matching {str} from a history. | |
6247 * "histype" may be one of the HIST_ values. | |
6248 */ | |
6249 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6250 del_history_entry(int histype, char_u *str) |
7 | 6251 { |
6252 regmatch_T regmatch; | |
6253 histentry_T *hisptr; | |
6254 int idx; | |
6255 int i; | |
6256 int last; | |
6257 int found = FALSE; | |
6258 | |
6259 regmatch.regprog = NULL; | |
6260 regmatch.rm_ic = FALSE; /* always match case */ | |
6261 if (hislen != 0 | |
6262 && histype >= 0 | |
6263 && histype < HIST_COUNT | |
6264 && *str != NUL | |
6265 && (idx = hisidx[histype]) >= 0 | |
6266 && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) | |
6267 != NULL) | |
6268 { | |
6269 i = last = idx; | |
6270 do | |
6271 { | |
6272 hisptr = &history[histype][i]; | |
6273 if (hisptr->hisstr == NULL) | |
6274 break; | |
6275 if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) | |
6276 { | |
6277 found = TRUE; | |
6278 vim_free(hisptr->hisstr); | |
4258 | 6279 clear_hist_entry(hisptr); |
7 | 6280 } |
6281 else | |
6282 { | |
6283 if (i != last) | |
6284 { | |
6285 history[histype][last] = *hisptr; | |
4258 | 6286 clear_hist_entry(hisptr); |
7 | 6287 } |
6288 if (--last < 0) | |
6289 last += hislen; | |
6290 } | |
6291 if (--i < 0) | |
6292 i += hislen; | |
6293 } while (i != idx); | |
6294 if (history[histype][idx].hisstr == NULL) | |
6295 hisidx[histype] = -1; | |
6296 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6297 vim_regfree(regmatch.regprog); |
7 | 6298 return found; |
6299 } | |
6300 | |
6301 /* | |
6302 * Remove an indexed entry from a history. | |
6303 * "histype" may be one of the HIST_ values. | |
6304 */ | |
6305 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6306 del_history_idx(int histype, int idx) |
7 | 6307 { |
6308 int i, j; | |
6309 | |
6310 i = calc_hist_idx(histype, idx); | |
6311 if (i < 0) | |
6312 return FALSE; | |
6313 idx = hisidx[histype]; | |
6314 vim_free(history[histype][i].hisstr); | |
6315 | |
6316 /* When deleting the last added search string in a mapping, reset | |
6317 * last_maptick, so that the last added search string isn't deleted again. | |
6318 */ | |
6319 if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) | |
6320 last_maptick = -1; | |
6321 | |
6322 while (i != idx) | |
6323 { | |
6324 j = (i + 1) % hislen; | |
6325 history[histype][i] = history[histype][j]; | |
6326 i = j; | |
6327 } | |
4258 | 6328 clear_hist_entry(&history[histype][i]); |
7 | 6329 if (--i < 0) |
6330 i += hislen; | |
6331 hisidx[histype] = i; | |
6332 return TRUE; | |
6333 } | |
6334 | |
6335 #endif /* FEAT_EVAL */ | |
6336 | |
6337 #if defined(FEAT_CRYPT) || defined(PROTO) | |
6338 /* | |
6339 * Very specific function to remove the value in ":set key=val" from the | |
6340 * history. | |
6341 */ | |
6342 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6343 remove_key_from_history(void) |
7 | 6344 { |
6345 char_u *p; | |
6346 int i; | |
6347 | |
6348 i = hisidx[HIST_CMD]; | |
6349 if (i < 0) | |
6350 return; | |
6351 p = history[HIST_CMD][i].hisstr; | |
6352 if (p != NULL) | |
6353 for ( ; *p; ++p) | |
6354 if (STRNCMP(p, "key", 3) == 0 && !isalpha(p[3])) | |
6355 { | |
6356 p = vim_strchr(p + 3, '='); | |
6357 if (p == NULL) | |
6358 break; | |
6359 ++p; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6360 for (i = 0; p[i] && !VIM_ISWHITE(p[i]); ++i) |
7 | 6361 if (p[i] == '\\' && p[i + 1]) |
6362 ++i; | |
1621 | 6363 STRMOVE(p, p + i); |
7 | 6364 --p; |
6365 } | |
6366 } | |
6367 #endif | |
6368 | |
6369 #endif /* FEAT_CMDHIST */ | |
6370 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6371 #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
|
6372 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6373 * 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
|
6374 * 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
|
6375 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6376 static struct cmdline_info * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6377 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6378 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6379 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6380 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6381 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6382 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6383 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
|
6384 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6385 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6386 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6387 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6388 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6389 #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
|
6390 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6391 * 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
|
6392 * 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
|
6393 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6394 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6395 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6396 get_cmdline_str(void) |
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 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
|
6399 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6400 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6401 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6402 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
|
6403 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6404 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6405 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6406 * 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
|
6407 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6408 * 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
|
6409 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6410 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6411 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6412 get_cmdline_pos(void) |
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 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
|
6415 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6416 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6417 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6418 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6419 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6420 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6421 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6422 * 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
|
6423 * 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
|
6424 * 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
|
6425 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6426 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6427 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6428 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6429 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6430 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
|
6431 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6432 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6433 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6434 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6435 /* 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
|
6436 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6437 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6438 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6439 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6440 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6441 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6442 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6443 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6444 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6445 #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
|
6446 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6447 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6448 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6449 * 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
|
6450 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6451 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6452 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6453 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6454 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6455 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
|
6456 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6457 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6458 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6459 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6460 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6461 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6462 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6463 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
6464 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6465 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6466 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6467 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6468 |
7 | 6469 #if defined(FEAT_QUICKFIX) || defined(FEAT_CMDHIST) || defined(PROTO) |
6470 /* | |
6471 * Get indices "num1,num2" that specify a range within a list (not a range of | |
6472 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
6473 * Returns OK if parsed successfully, otherwise FAIL. | |
6474 */ | |
6475 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6476 get_list_range(char_u **str, int *num1, int *num2) |
7 | 6477 { |
6478 int len; | |
6479 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
6480 varnumber_T num; |
7 | 6481 |
6482 *str = skipwhite(*str); | |
6483 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
6484 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6485 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6486 *str += len; |
6487 *num1 = (int)num; | |
6488 first = TRUE; | |
6489 } | |
6490 *str = skipwhite(*str); | |
6491 if (**str == ',') /* parse "to" part of range */ | |
6492 { | |
6493 *str = skipwhite(*str + 1); | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
6494 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); |
7 | 6495 if (len > 0) |
6496 { | |
6497 *num2 = (int)num; | |
6498 *str = skipwhite(*str + len); | |
6499 } | |
6500 else if (!first) /* no number given at all */ | |
6501 return FAIL; | |
6502 } | |
6503 else if (first) /* only one number given */ | |
6504 *num2 = *num1; | |
6505 return OK; | |
6506 } | |
6507 #endif | |
6508 | |
6509 #if defined(FEAT_CMDHIST) || defined(PROTO) | |
6510 /* | |
6511 * :history command - print a history | |
6512 */ | |
6513 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6514 ex_history(exarg_T *eap) |
7 | 6515 { |
6516 histentry_T *hist; | |
6517 int histype1 = HIST_CMD; | |
6518 int histype2 = HIST_CMD; | |
6519 int hisidx1 = 1; | |
6520 int hisidx2 = -1; | |
6521 int idx; | |
6522 int i, j, k; | |
6523 char_u *end; | |
6524 char_u *arg = eap->arg; | |
6525 | |
6526 if (hislen == 0) | |
6527 { | |
6528 MSG(_("'history' option is zero")); | |
6529 return; | |
6530 } | |
6531 | |
6532 if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) | |
6533 { | |
6534 end = arg; | |
6535 while (ASCII_ISALPHA(*end) | |
6536 || vim_strchr((char_u *)":=@>/?", *end) != NULL) | |
6537 end++; | |
6538 i = *end; | |
6539 *end = NUL; | |
6540 histype1 = get_histtype(arg); | |
6541 if (histype1 == -1) | |
6542 { | |
1853 | 6543 if (STRNICMP(arg, "all", STRLEN(arg)) == 0) |
7 | 6544 { |
6545 histype1 = 0; | |
6546 histype2 = HIST_COUNT-1; | |
6547 } | |
6548 else | |
6549 { | |
6550 *end = i; | |
6551 EMSG(_(e_trailing)); | |
6552 return; | |
6553 } | |
6554 } | |
6555 else | |
6556 histype2 = histype1; | |
6557 *end = i; | |
6558 } | |
6559 else | |
6560 end = arg; | |
6561 if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) | |
6562 { | |
6563 EMSG(_(e_trailing)); | |
6564 return; | |
6565 } | |
6566 | |
6567 for (; !got_int && histype1 <= histype2; ++histype1) | |
6568 { | |
6569 STRCPY(IObuff, "\n # "); | |
6570 STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); | |
6571 MSG_PUTS_TITLE(IObuff); | |
6572 idx = hisidx[histype1]; | |
6573 hist = history[histype1]; | |
6574 j = hisidx1; | |
6575 k = hisidx2; | |
6576 if (j < 0) | |
6577 j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; | |
6578 if (k < 0) | |
6579 k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; | |
6580 if (idx >= 0 && j <= k) | |
6581 for (i = idx + 1; !got_int; ++i) | |
6582 { | |
6583 if (i == hislen) | |
6584 i = 0; | |
6585 if (hist[i].hisstr != NULL | |
6586 && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
6587 { | |
6588 msg_putchar('\n'); | |
6589 sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', | |
6590 hist[i].hisnum); | |
6591 if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) | |
6592 trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), | |
3290 | 6593 (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); |
7 | 6594 else |
6595 STRCAT(IObuff, hist[i].hisstr); | |
6596 msg_outtrans(IObuff); | |
6597 out_flush(); | |
6598 } | |
6599 if (i == idx) | |
6600 break; | |
6601 } | |
6602 } | |
6603 } | |
6604 #endif | |
6605 | |
6606 #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
|
6607 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6608 * 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
|
6609 */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6610 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
|
6611 {NULL, NULL, NULL, NULL, NULL}; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6612 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
|
6613 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
7 | 6614 static int viminfo_add_at_front = FALSE; |
6615 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6616 static int hist_type2char(int type, int use_question); |
7 | 6617 |
6618 /* | |
6619 * Translate a history type number to the associated character. | |
6620 */ | |
6621 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6622 hist_type2char( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6623 int type, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6624 int use_question) /* use '?' instead of '/' */ |
7 | 6625 { |
6626 if (type == HIST_CMD) | |
6627 return ':'; | |
6628 if (type == HIST_SEARCH) | |
6629 { | |
6630 if (use_question) | |
6631 return '?'; | |
6632 else | |
6633 return '/'; | |
6634 } | |
6635 if (type == HIST_EXPR) | |
6636 return '='; | |
6637 return '@'; | |
6638 } | |
6639 | |
6640 /* | |
6641 * Prepare for reading the history from the viminfo file. | |
6642 * This allocates history arrays to store the read history lines. | |
6643 */ | |
6644 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6645 prepare_viminfo_history(int asklen, int writing) |
7 | 6646 { |
6647 int i; | |
6648 int num; | |
6649 int type; | |
6650 int len; | |
6651 | |
6652 init_history(); | |
4285 | 6653 viminfo_add_at_front = (asklen != 0 && !writing); |
7 | 6654 if (asklen > hislen) |
6655 asklen = hislen; | |
6656 | |
6657 for (type = 0; type < HIST_COUNT; ++type) | |
6658 { | |
4258 | 6659 /* Count the number of empty spaces in the history list. Entries read |
6660 * from viminfo previously are also considered empty. If there are | |
6661 * more spaces available than we request, then fill them up. */ | |
7 | 6662 for (i = 0, num = 0; i < hislen; i++) |
4258 | 6663 if (history[type][i].hisstr == NULL || history[type][i].viminfo) |
7 | 6664 num++; |
6665 len = asklen; | |
6666 if (num > len) | |
6667 len = num; | |
6668 if (len <= 0) | |
6669 viminfo_history[type] = NULL; | |
6670 else | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6671 viminfo_history[type] = (histentry_T *)lalloc( |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6672 (long_u)(len * sizeof(histentry_T)), FALSE); |
7 | 6673 if (viminfo_history[type] == NULL) |
6674 len = 0; | |
6675 viminfo_hislen[type] = len; | |
6676 viminfo_hisidx[type] = 0; | |
6677 } | |
6678 } | |
6679 | |
6680 /* | |
6681 * Accept a line from the viminfo, store it in the history array when it's | |
6682 * new. | |
6683 */ | |
6684 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6685 read_viminfo_history(vir_T *virp, int writing) |
7 | 6686 { |
6687 int type; | |
6688 long_u len; | |
6689 char_u *val; | |
6690 char_u *p; | |
6691 | |
6692 type = hist_char2type(virp->vir_line[0]); | |
6693 if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
6694 { | |
6695 val = viminfo_readstring(virp, 1, TRUE); | |
6696 if (val != NULL && *val != NUL) | |
6697 { | |
3316 | 6698 int sep = (*val == ' ' ? NUL : *val); |
6699 | |
7 | 6700 if (!in_history(type, val + (type == HIST_SEARCH), |
4285 | 6701 viminfo_add_at_front, sep, writing)) |
7 | 6702 { |
6703 /* Need to re-allocate to append the separator byte. */ | |
6704 len = STRLEN(val); | |
6705 p = lalloc(len + 2, TRUE); | |
6706 if (p != NULL) | |
6707 { | |
6708 if (type == HIST_SEARCH) | |
6709 { | |
6710 /* Search entry: Move the separator from the first | |
6711 * column to after the NUL. */ | |
6712 mch_memmove(p, val + 1, (size_t)len); | |
3316 | 6713 p[len] = sep; |
7 | 6714 } |
6715 else | |
6716 { | |
6717 /* Not a search entry: No separator in the viminfo | |
6718 * file, add a NUL separator. */ | |
6719 mch_memmove(p, val, (size_t)len + 1); | |
6720 p[len + 1] = NUL; | |
6721 } | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6722 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
|
6723 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
|
6724 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
|
6725 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
|
6726 viminfo_hisidx[type]++; |
7 | 6727 } |
6728 } | |
6729 } | |
6730 vim_free(val); | |
6731 } | |
6732 return viminfo_readline(virp); | |
6733 } | |
6734 | |
4285 | 6735 /* |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6736 * 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
|
6737 * array when it's new. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6738 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6739 void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6740 handle_viminfo_history( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6741 garray_T *values, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6742 int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6743 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6744 int type; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6745 long_u len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6746 char_u *val; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6747 char_u *p; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6748 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
|
6749 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6750 /* Check the format: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6751 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6752 if (values->ga_len < 4 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6753 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6754 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6755 || (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
|
6756 || 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
|
6757 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6758 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6759 type = vp[0].bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6760 if (type >= HIST_COUNT) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6761 return; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6762 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
|
6763 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6764 val = vp[3].bv_string; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6765 if (val != NULL && *val != NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6766 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6767 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
|
6768 ? vp[2].bv_nr : NUL; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6769 int idx; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6770 int overwrite = FALSE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6771 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6772 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
|
6773 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6774 /* 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
|
6775 * 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
|
6776 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
|
6777 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6778 p = viminfo_history[type][idx].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6779 if (STRCMP(val, p) == 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6780 && (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
|
6781 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6782 overwrite = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6783 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6784 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6785 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6786 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6787 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6788 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6789 /* 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
|
6790 len = vp[3].bv_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6791 p = lalloc(len + 2, TRUE); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6792 } |
9301
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6793 else |
c3805fb080a6
commit https://github.com/vim/vim/commit/72e697d189616265ecefe0df4509d476df3bae40
Christian Brabandt <cb@256bit.org>
parents:
9287
diff
changeset
|
6794 len = 0; /* for picky compilers */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6795 if (p != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6796 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
6797 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
|
6798 if (!overwrite) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6799 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6800 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
|
6801 /* Put the separator after the NUL. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6802 p[len + 1] = sep; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6803 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
|
6804 viminfo_history[type][idx].hisnum = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6805 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
|
6806 viminfo_hisidx[type]++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6807 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6808 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6809 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6810 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6811 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6812 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6813 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6814 /* |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6815 * 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
|
6816 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6817 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6818 concat_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6819 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6820 int idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6821 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6822 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6823 idx = hisidx[type] + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6824 if (idx >= hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6825 idx -= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6826 else if (idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6827 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6828 if (viminfo_add_at_front) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6829 hisidx[type] = idx; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6830 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6831 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6832 if (hisidx[type] == -1) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6833 hisidx[type] = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6834 do |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6835 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6836 if (history[type][idx].hisstr != NULL |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6837 || history[type][idx].viminfo) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6838 break; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6839 if (++idx == hislen) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6840 idx = 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6841 } while (idx != hisidx[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6842 if (idx != hisidx[type] && --idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6843 idx = hislen - 1; |
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 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
|
6846 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6847 vim_free(history[type][idx].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6848 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
|
6849 history[type][idx].viminfo = TRUE; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6850 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
|
6851 if (--idx < 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6852 idx = hislen - 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6853 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6854 idx += 1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6855 idx %= hislen; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6856 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
|
6857 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6858 history[type][idx++].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6859 idx %= hislen; |
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 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6863 #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
|
6864 static int |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6865 #ifdef __BORLANDC__ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6866 _RTLENTRYF |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6867 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6868 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
|
6869 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6870 histentry_T *p1 = *(histentry_T **)s1; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6871 histentry_T *p2 = *(histentry_T **)s2; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6872 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6873 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
|
6874 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
|
6875 return 0; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6876 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6877 #endif |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6878 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6879 /* |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6880 * 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
|
6881 * timestamp; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6882 */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6883 static void |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6884 merge_history(int type) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6885 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6886 int max_len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6887 histentry_T **tot_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6888 histentry_T *new_hist; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6889 int i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6890 int len; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6891 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6892 /* 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
|
6893 max_len = hislen + viminfo_hisidx[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6894 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
|
6895 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
|
6896 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
|
6897 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6898 vim_free(tot_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6899 vim_free(new_hist); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6900 return; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6901 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6902 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
|
6903 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
|
6904 len = i; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6905 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6906 if (history[type][i].hisstr != NULL) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6907 tot_hist[len++] = &history[type][i]; |
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 /* Sort the list on timestamp. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6910 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
|
6911 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6912 /* Keep the newest ones. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6913 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6914 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6915 if (i < len) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6916 { |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6917 new_hist[i] = *tot_hist[i]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6918 tot_hist[i]->hisstr = NULL; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6919 if (new_hist[i].hisnum == 0) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6920 new_hist[i].hisnum = ++hisnum[type]; |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6921 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6922 else |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6923 clear_hist_entry(&new_hist[i]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6924 } |
9287
af25a1a875db
commit https://github.com/vim/vim/commit/a890f5e34887bff7616bdb4b9ee0bf98c8d2a8f0
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6925 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
|
6926 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6927 /* Free what is not kept. */ |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6928 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
|
6929 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
|
6930 for (i = 0; i < hislen; i++) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6931 vim_free(history[type][i].hisstr); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6932 vim_free(history[type]); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6933 history[type] = new_hist; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
6934 vim_free(tot_hist); |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6935 } |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6936 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6937 /* |
4285 | 6938 * Finish reading history lines from viminfo. Not used when writing viminfo. |
6939 */ | |
7 | 6940 void |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6941 finish_viminfo_history(vir_T *virp) |
7 | 6942 { |
6943 int type; | |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6944 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
7 | 6945 |
6946 for (type = 0; type < HIST_COUNT; ++type) | |
6947 { | |
6948 if (history[type] == NULL) | |
4283 | 6949 continue; |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6950 |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6951 if (merge) |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6952 merge_history(type); |
7 | 6953 else |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6954 concat_history(type); |
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
6955 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
6956 VIM_CLEAR(viminfo_history[type]); |
4327 | 6957 viminfo_hisidx[type] = 0; |
7 | 6958 } |
6959 } | |
6960 | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6961 /* |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6962 * Write history to viminfo file in "fp". |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6963 * 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
|
6964 * file, data is in viminfo_history[]. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
6965 * 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
|
6966 */ |
7 | 6967 void |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6968 write_viminfo_history(FILE *fp, int merge) |
7 | 6969 { |
6970 int i; | |
6971 int type; | |
6972 int num_saved; | |
4283 | 6973 int round; |
7 | 6974 |
6975 init_history(); | |
6976 if (hislen == 0) | |
6977 return; | |
6978 for (type = 0; type < HIST_COUNT; ++type) | |
6979 { | |
6980 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); | |
6981 if (num_saved == 0) | |
6982 continue; | |
6983 if (num_saved < 0) /* Use default */ | |
6984 num_saved = hislen; | |
6985 fprintf(fp, _("\n# %s History (newest to oldest):\n"), | |
6986 type == HIST_CMD ? _("Command Line") : | |
6987 type == HIST_SEARCH ? _("Search String") : | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6988 type == HIST_EXPR ? _("Expression") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6989 type == HIST_INPUT ? _("Input Line") : |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
6990 _("Debug Line")); |
7 | 6991 if (num_saved > hislen) |
6992 num_saved = hislen; | |
4283 | 6993 |
6994 /* | |
6995 * Merge typed and viminfo history: | |
6996 * round 1: history of typed commands. | |
6997 * round 2: history from recently read viminfo. | |
6998 */ | |
6999 for (round = 1; round <= 2; ++round) | |
7000 { | |
4307 | 7001 if (round == 1) |
7002 /* start at newest entry, somewhere in the list */ | |
7003 i = hisidx[type]; | |
7004 else if (viminfo_hisidx[type] > 0) | |
7005 /* start at newest entry, first in the list */ | |
7006 i = 0; | |
7007 else | |
7008 /* empty list */ | |
7009 i = -1; | |
4283 | 7010 if (i >= 0) |
7011 while (num_saved > 0 | |
7012 && !(round == 2 && i >= viminfo_hisidx[type])) | |
7 | 7013 { |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7014 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7015 time_t timestamp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7016 int c = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7017 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7018 if (round == 1) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7019 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7020 p = history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7021 timestamp = history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7022 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7023 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7024 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7025 p = viminfo_history[type] == NULL ? NULL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7026 : viminfo_history[type][i].hisstr; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7027 timestamp = viminfo_history[type] == NULL ? 0 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7028 : viminfo_history[type][i].time_set; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7029 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7030 |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7031 if (p != NULL && (round == 2 |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7032 || !merge |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
7033 || !history[type][i].viminfo)) |
7 | 7034 { |
4283 | 7035 --num_saved; |
7036 fputc(hist_type2char(type, TRUE), fp); | |
7037 /* For the search history: put the separator in the | |
7038 * second column; use a space if there isn't one. */ | |
7039 if (type == HIST_SEARCH) | |
7040 { | |
7041 c = p[STRLEN(p) + 1]; | |
7042 putc(c == NUL ? ' ' : c, fp); | |
7043 } | |
7044 viminfo_writestring(fp, p); | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7045 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7046 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7047 char cbuf[NUMBUFLEN]; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7048 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7049 /* 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
|
7050 * |{bartype},{histtype},{timestamp},{separator},"text" */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7051 if (c == NUL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7052 cbuf[0] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7053 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7054 sprintf(cbuf, "%d", c); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7055 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
|
7056 type, (long)timestamp, cbuf); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7057 barline_writestring(fp, p, LSIZE - 20); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7058 putc('\n', fp); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7059 } |
7 | 7060 } |
4283 | 7061 if (round == 1) |
7062 { | |
7063 /* Decrement index, loop around and stop when back at | |
7064 * the start. */ | |
7065 if (--i < 0) | |
7066 i = hislen - 1; | |
7067 if (i == hisidx[type]) | |
7068 break; | |
7069 } | |
7070 else | |
7071 { | |
7072 /* Increment index. Stop at the end in the while. */ | |
7073 ++i; | |
7074 } | |
7 | 7075 } |
4283 | 7076 } |
4285 | 7077 for (i = 0; i < viminfo_hisidx[type]; ++i) |
4327 | 7078 if (viminfo_history[type] != NULL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9070
diff
changeset
|
7079 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
|
7080 VIM_CLEAR(viminfo_history[type]); |
4311 | 7081 viminfo_hisidx[type] = 0; |
7 | 7082 } |
7083 } | |
7084 #endif /* FEAT_VIMINFO */ | |
7085 | |
7086 #if defined(FEAT_FKMAP) || defined(PROTO) | |
7087 /* | |
7088 * Write a character at the current cursor+offset position. | |
7089 * It is directly written into the command buffer block. | |
7090 */ | |
7091 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7092 cmd_pchar(int c, int offset) |
7 | 7093 { |
7094 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7095 { | |
7096 EMSG(_("E198: cmd_pchar beyond the command length")); | |
7097 return; | |
7098 } | |
7099 ccline.cmdbuff[ccline.cmdpos + offset] = (char_u)c; | |
7100 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
7101 } | |
7102 | |
7103 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7104 cmd_gchar(int offset) |
7 | 7105 { |
7106 if (ccline.cmdpos + offset >= ccline.cmdlen || ccline.cmdpos + offset < 0) | |
7107 { | |
7108 /* EMSG(_("cmd_gchar beyond the command length")); */ | |
7109 return NUL; | |
7110 } | |
7111 return (int)ccline.cmdbuff[ccline.cmdpos + offset]; | |
7112 } | |
7113 #endif | |
7114 | |
7115 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
7116 /* | |
7117 * Open a window on the current command line and history. Allow editing in | |
7118 * the window. Returns when the window is closed. | |
7119 * Returns: | |
7120 * CR if the command is to be executed | |
7121 * Ctrl_C if it is to be abandoned | |
7122 * K_IGNORE if editing continues | |
7123 */ | |
7124 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
|
7125 open_cmdwin(void) |
7 | 7126 { |
7127 struct cmdline_info save_ccline; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7128 bufref_T old_curbuf; |
7 | 7129 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7130 bufref_T bufref; |
7 | 7131 win_T *wp; |
7132 int i; | |
7133 linenr_T lnum; | |
7134 int histtype; | |
7135 garray_T winsizes; | |
7136 int save_restart_edit = restart_edit; | |
7137 int save_State = State; | |
7138 int save_exmode = exmode_active; | |
510 | 7139 #ifdef FEAT_RIGHTLEFT |
7140 int save_cmdmsg_rl = cmdmsg_rl; | |
7141 #endif | |
6145 | 7142 #ifdef FEAT_FOLDING |
7143 int save_KeyTyped; | |
7144 #endif | |
7 | 7145 |
7146 /* Can't do this recursively. Can't do it when typing a password. */ | |
7147 if (cmdwin_type != 0 | |
7148 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
7149 || cmdline_star > 0 | |
7150 # endif | |
7151 ) | |
7152 { | |
7153 beep_flush(); | |
7154 return K_IGNORE; | |
7155 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7156 set_bufref(&old_curbuf, curbuf); |
7 | 7157 |
7158 /* Save current window sizes. */ | |
7159 win_size_save(&winsizes); | |
7160 | |
7161 /* Don't execute autocommands while creating the window. */ | |
1410 | 7162 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7163 |
683 | 7164 /* don't use a new tab page */ |
7165 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
|
7166 cmdmod.noswapfile = 1; |
683 | 7167 |
7 | 7168 /* Create a window for the command-line buffer. */ |
7169 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
7170 { | |
7171 beep_flush(); | |
1410 | 7172 unblock_autocmds(); |
7 | 7173 return K_IGNORE; |
7174 } | |
1831 | 7175 cmdwin_type = get_cmdline_type(); |
7 | 7176 |
7177 /* Create the command-line buffer empty. */ | |
1743 | 7178 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 7179 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 7180 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
7181 curbuf->b_p_ma = TRUE; | |
1865 | 7182 #ifdef FEAT_FOLDING |
7183 curwin->w_p_fen = FALSE; | |
7184 #endif | |
7 | 7185 # ifdef FEAT_RIGHTLEFT |
510 | 7186 curwin->w_p_rl = cmdmsg_rl; |
7187 cmdmsg_rl = FALSE; | |
7 | 7188 # endif |
2583 | 7189 RESET_BINDING(curwin); |
7 | 7190 |
7191 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 7192 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7193 /* 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
|
7194 ++curbuf_lock; |
7 | 7195 |
510 | 7196 /* Showing the prompt may have set need_wait_return, reset it. */ |
7197 need_wait_return = FALSE; | |
7198 | |
1831 | 7199 histtype = hist_char2type(cmdwin_type); |
7 | 7200 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
7201 { | |
7202 if (p_wc == TAB) | |
7203 { | |
7204 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
7205 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
7206 } | |
7207 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
7208 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
7209 --curbuf_lock; |
7 | 7210 |
10 | 7211 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
7212 * sets 'textwidth' to 78). */ | |
7213 curbuf->b_p_tw = 0; | |
7214 | |
7 | 7215 /* Fill the buffer with the history. */ |
7216 init_history(); | |
7217 if (hislen > 0) | |
7218 { | |
7219 i = hisidx[histtype]; | |
7220 if (i >= 0) | |
7221 { | |
7222 lnum = 0; | |
7223 do | |
7224 { | |
7225 if (++i == hislen) | |
7226 i = 0; | |
7227 if (history[histtype][i].hisstr != NULL) | |
7228 ml_append(lnum++, history[histtype][i].hisstr, | |
7229 (colnr_T)0, FALSE); | |
7230 } | |
7231 while (i != hisidx[histtype]); | |
7232 } | |
7233 } | |
7234 | |
7235 /* Replace the empty last line with the current command-line and put the | |
7236 * cursor there. */ | |
7237 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
7238 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7239 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 7240 changed_line_abv_curs(); |
7241 invalidate_botline(); | |
743 | 7242 redraw_later(SOME_VALID); |
7 | 7243 |
7244 /* 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
|
7245 save_cmdline(&save_ccline); |
7 | 7246 |
7247 /* No Ex mode here! */ | |
7248 exmode_active = 0; | |
7249 | |
7250 State = NORMAL; | |
7251 # ifdef FEAT_MOUSE | |
7252 setmouse(); | |
7253 # endif | |
7254 | |
7255 /* 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
|
7256 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 7257 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
7258 stuffcharReadbuff(K_NOP); | |
7 | 7259 |
7260 i = RedrawingDisabled; | |
7261 RedrawingDisabled = 0; | |
7262 | |
7263 /* | |
7264 * Call the main loop until <CR> or CTRL-C is typed. | |
7265 */ | |
7266 cmdwin_result = 0; | |
168 | 7267 main_loop(TRUE, FALSE); |
7 | 7268 |
7269 RedrawingDisabled = i; | |
7270 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7271 # ifdef FEAT_FOLDING |
6145 | 7272 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7273 # endif |
6145 | 7274 |
7 | 7275 /* 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
|
7276 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 7277 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7278 # ifdef FEAT_FOLDING |
6145 | 7279 /* Restore KeyTyped in case it is modified by autocommands */ |
7280 KeyTyped = save_KeyTyped; | |
7 | 7281 # endif |
7282 | |
1214 | 7283 /* 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
|
7284 restore_cmdline(&save_ccline); |
7 | 7285 cmdwin_type = 0; |
7286 | |
7287 exmode_active = save_exmode; | |
7288 | |
1612 | 7289 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 7290 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7291 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 7292 { |
7293 cmdwin_result = Ctrl_C; | |
7294 EMSG(_("E199: Active window or buffer deleted")); | |
7295 } | |
7296 else | |
7297 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
7298 # if defined(FEAT_EVAL) |
7 | 7299 /* autocmds may abort script processing */ |
7300 if (aborting() && cmdwin_result != K_IGNORE) | |
7301 cmdwin_result = Ctrl_C; | |
7302 # endif | |
7303 /* Set the new command line from the cmdline buffer. */ | |
7304 vim_free(ccline.cmdbuff); | |
510 | 7305 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 7306 { |
510 | 7307 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
7308 | |
7309 if (histtype == HIST_CMD) | |
7310 { | |
7311 /* Execute the command directly. */ | |
7312 ccline.cmdbuff = vim_strsave((char_u *)p); | |
7313 cmdwin_result = CAR; | |
7314 } | |
7315 else | |
7316 { | |
7317 /* First need to cancel what we were doing. */ | |
7318 ccline.cmdbuff = NULL; | |
7319 stuffcharReadbuff(':'); | |
7320 stuffReadbuff((char_u *)p); | |
7321 stuffcharReadbuff(CAR); | |
7322 } | |
7 | 7323 } |
7324 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
7325 { | |
7326 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
7327 cmdwin_result = CAR; | |
7328 } | |
2839 | 7329 else if (cmdwin_result == Ctrl_C) |
7330 { | |
7331 /* :q or :close, don't execute any command | |
7332 * and don't modify the cmd window. */ | |
7333 ccline.cmdbuff = NULL; | |
7334 } | |
7 | 7335 else |
7336 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
7337 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
|
7338 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
7339 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
|
7340 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
|
7341 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
|
7342 ccline.cmdpos = 0; |
7 | 7343 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
|
7344 } |
7 | 7345 else |
7346 { | |
7347 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
7348 ccline.cmdbufflen = ccline.cmdlen + 1; | |
7349 ccline.cmdpos = curwin->w_cursor.col; | |
7350 if (ccline.cmdpos > ccline.cmdlen) | |
7351 ccline.cmdpos = ccline.cmdlen; | |
7352 if (cmdwin_result == K_IGNORE) | |
7353 { | |
7354 set_cmdspos_cursor(); | |
7355 redrawcmd(); | |
7356 } | |
7357 } | |
7358 | |
7359 /* Don't execute autocommands while deleting the window. */ | |
1410 | 7360 block_autocmds(); |
6876 | 7361 # ifdef FEAT_CONCEAL |
7362 /* Avoid command-line window first character being concealed. */ | |
7363 curwin->w_p_cole = 0; | |
7364 # endif | |
7 | 7365 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7366 set_bufref(&bufref, curbuf); |
7 | 7367 win_goto(old_curwin); |
7368 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7369 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
7370 /* 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
|
7371 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7372 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
7373 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 7374 |
7375 /* Restore window sizes. */ | |
7376 win_size_restore(&winsizes); | |
7377 | |
1410 | 7378 unblock_autocmds(); |
7 | 7379 } |
7380 | |
7381 ga_clear(&winsizes); | |
7382 restart_edit = save_restart_edit; | |
510 | 7383 # ifdef FEAT_RIGHTLEFT |
7384 cmdmsg_rl = save_cmdmsg_rl; | |
7385 # endif | |
7 | 7386 |
7387 State = save_State; | |
7388 # ifdef FEAT_MOUSE | |
7389 setmouse(); | |
7390 # endif | |
7391 | |
7392 return cmdwin_result; | |
7393 } | |
7394 #endif /* FEAT_CMDWIN */ | |
7395 | |
7396 /* | |
7397 * Used for commands that either take a simple command string argument, or: | |
7398 * cmd << endmarker | |
7399 * {script} | |
7400 * endmarker | |
7401 * Returns a pointer to allocated memory with {script} or NULL. | |
7402 */ | |
7403 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7404 script_get(exarg_T *eap, char_u *cmd) |
7 | 7405 { |
7406 char_u *theline; | |
7407 char *end_pattern = NULL; | |
7408 char dot[] = "."; | |
7409 garray_T ga; | |
7410 | |
7411 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
7412 return NULL; | |
7413 | |
7414 ga_init2(&ga, 1, 0x400); | |
7415 | |
7416 if (cmd[2] != NUL) | |
7417 end_pattern = (char *)skipwhite(cmd + 2); | |
7418 else | |
7419 end_pattern = dot; | |
7420 | |
7421 for (;;) | |
7422 { | |
7423 theline = eap->getline( | |
7424 #ifdef FEAT_EVAL | |
75 | 7425 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 7426 #endif |
7427 NUL, eap->cookie, 0); | |
7428 | |
7429 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 7430 { |
7431 vim_free(theline); | |
7 | 7432 break; |
1694 | 7433 } |
7 | 7434 |
7435 ga_concat(&ga, theline); | |
7436 ga_append(&ga, '\n'); | |
7437 vim_free(theline); | |
7438 } | |
21 | 7439 ga_append(&ga, NUL); |
7 | 7440 |
7441 return (char_u *)ga.ga_data; | |
7442 } |