Mercurial > vim
annotate src/getchar.c @ 17600:ca42eb789472 v8.1.1797
patch 8.1.1797: the vgetorpeek() function is too long
commit https://github.com/vim/vim/commit/edd680f3649c47d7ed5818e356e7c47f874f5cf8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 3 14:23:48 2019 +0200
patch 8.1.1797: the vgetorpeek() function is too long
Problem: The vgetorpeek() function is too long.
Solution: Split off the part that handles mappings, with fix.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 03 Aug 2019 14:30:05 +0200 |
parents | 3b18d5341c03 |
children | 653ab352b019 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9980
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 * getchar.c | |
12 * | |
13 * functions related with getting a character from the user/mapping/redo/... | |
14 * | |
15 * manipulations with redo buffer and stuff buffer | |
16 * mappings and abbreviations | |
17 */ | |
18 | |
19 #include "vim.h" | |
20 | |
21 /* | |
22 * These buffers are used for storing: | |
23 * - stuffed characters: A command that is translated into another command. | |
24 * - redo characters: will redo the last change. | |
1992 | 25 * - recorded characters: for the "q" command. |
7 | 26 * |
27 * The bytes are stored like in the typeahead buffer: | |
28 * - K_SPECIAL introduces a special key (two more bytes follow). A literal | |
29 * K_SPECIAL is stored as K_SPECIAL KS_SPECIAL KE_FILLER. | |
30 * - CSI introduces a GUI termcap code (also when gui.in_use is FALSE, | |
31 * otherwise switching the GUI on would make mappings invalid). | |
32 * A literal CSI is stored as CSI KS_EXTRA KE_CSI. | |
33 * These translations are also done on multi-byte characters! | |
34 * | |
35 * Escaping CSI bytes is done by the system-specific input functions, called | |
36 * by ui_inchar(). | |
37 * Escaping K_SPECIAL is done by inchar(). | |
38 * Un-escaping is done by vgetc(). | |
39 */ | |
40 | |
41 #define MINIMAL_SIZE 20 /* minimal size for b_str */ | |
42 | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
43 static buffheader_T redobuff = {{NULL, {NUL}}, NULL, 0, 0}; |
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
44 static buffheader_T old_redobuff = {{NULL, {NUL}}, NULL, 0, 0}; |
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
45 static buffheader_T recordbuff = {{NULL, {NUL}}, NULL, 0, 0}; |
7 | 46 |
47 static int typeahead_char = 0; /* typeahead char that's not flushed */ | |
48 | |
49 /* | |
50 * when block_redo is TRUE redo buffer will not be changed | |
51 * used by edit() to repeat insertions and 'V' command for redoing | |
52 */ | |
53 static int block_redo = FALSE; | |
54 | |
1051 | 55 static int KeyNoremap = 0; /* remapping flags */ |
7 | 56 |
57 /* | |
9228
ea504064c996
commit https://github.com/vim/vim/commit/fd89d7ea81b18d32363456b16258174dc9e095dc
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
58 * Variables used by vgetorpeek() and flush_buffers(). |
7 | 59 * |
60 * typebuf.tb_buf[] contains all characters that are not consumed yet. | |
61 * typebuf.tb_buf[typebuf.tb_off] is the first valid character. | |
62 * typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1] is the last valid char. | |
63 * typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] must be NUL. | |
64 * The head of the buffer may contain the result of mappings, abbreviations | |
65 * and @a commands. The length of this part is typebuf.tb_maplen. | |
66 * typebuf.tb_silent is the part where <silent> applies. | |
67 * After the head are characters that come from the terminal. | |
68 * typebuf.tb_no_abbr_cnt is the number of characters in typebuf.tb_buf that | |
69 * should not be considered for abbreviations. | |
70 * Some parts of typebuf.tb_buf may not be mapped. These parts are remembered | |
71 * in typebuf.tb_noremap[], which is the same length as typebuf.tb_buf and | |
72 * contains RM_NONE for the characters that are not to be remapped. | |
73 * typebuf.tb_noremap[typebuf.tb_off] is the first valid flag. | |
74 * (typebuf has been put in globals.h, because check_termcode() needs it). | |
75 */ | |
76 #define RM_YES 0 /* tb_noremap: remap */ | |
77 #define RM_NONE 1 /* tb_noremap: don't remap */ | |
78 #define RM_SCRIPT 2 /* tb_noremap: remap local script mappings */ | |
10 | 79 #define RM_ABBR 4 /* tb_noremap: don't remap, do abbrev. */ |
7 | 80 |
81 /* typebuf.tb_buf has three parts: room in front (for result of mappings), the | |
82 * middle for typeahead and room for new characters (which needs to be 3 * | |
83 * MAXMAPLEN) for the Amiga). | |
84 */ | |
85 #define TYPELEN_INIT (5 * (MAXMAPLEN + 3)) | |
86 static char_u typebuf_init[TYPELEN_INIT]; /* initial typebuf.tb_buf */ | |
87 static char_u noremapbuf_init[TYPELEN_INIT]; /* initial typebuf.tb_noremap */ | |
88 | |
89 static int last_recorded_len = 0; /* number of last recorded chars */ | |
90 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
91 static int read_readbuf(buffheader_T *buf, int advance); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
92 static void init_typebuf(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
93 static void may_sync_undo(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
94 static void closescript(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
95 static int vgetorpeek(int); |
12281
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
96 static int inchar(char_u *buf, int maxlen, long wait_time); |
7 | 97 |
98 /* | |
99 * Free and clear a buffer. | |
100 */ | |
101 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
102 free_buff(buffheader_T *buf) |
7 | 103 { |
5649 | 104 buffblock_T *p, *np; |
7 | 105 |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
106 for (p = buf->bh_first.b_next; p != NULL; p = np) |
7 | 107 { |
108 np = p->b_next; | |
109 vim_free(p); | |
110 } | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
111 buf->bh_first.b_next = NULL; |
7 | 112 } |
113 | |
114 /* | |
115 * Return the contents of a buffer as a single string. | |
116 * K_SPECIAL and CSI in the returned string are escaped. | |
117 */ | |
118 static char_u * | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
119 get_buffcont( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
120 buffheader_T *buffer, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
121 int dozero) /* count == zero is not an error */ |
7 | 122 { |
123 long_u count = 0; | |
124 char_u *p = NULL; | |
125 char_u *p2; | |
126 char_u *str; | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
127 buffblock_T *bp; |
7 | 128 |
129 /* compute the total length of the string */ | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
130 for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next) |
7 | 131 count += (long_u)STRLEN(bp->b_str); |
132 | |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
133 if ((count || dozero) && (p = alloc(count + 1)) != NULL) |
7 | 134 { |
135 p2 = p; | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
136 for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next) |
7 | 137 for (str = bp->b_str; *str; ) |
138 *p2++ = *str++; | |
139 *p2 = NUL; | |
140 } | |
141 return (p); | |
142 } | |
143 | |
144 /* | |
145 * Return the contents of the record buffer as a single string | |
146 * and clear the record buffer. | |
147 * K_SPECIAL and CSI in the returned string are escaped. | |
148 */ | |
149 char_u * | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
150 get_recorded(void) |
7 | 151 { |
152 char_u *p; | |
153 size_t len; | |
154 | |
155 p = get_buffcont(&recordbuff, TRUE); | |
156 free_buff(&recordbuff); | |
157 | |
158 /* | |
159 * Remove the characters that were added the last time, these must be the | |
160 * (possibly mapped) characters that stopped the recording. | |
161 */ | |
162 len = STRLEN(p); | |
163 if ((int)len >= last_recorded_len) | |
164 { | |
165 len -= last_recorded_len; | |
166 p[len] = NUL; | |
167 } | |
168 | |
169 /* | |
170 * When stopping recording from Insert mode with CTRL-O q, also remove the | |
171 * CTRL-O. | |
172 */ | |
173 if (len > 0 && restart_edit != 0 && p[len - 1] == Ctrl_O) | |
174 p[len - 1] = NUL; | |
175 | |
176 return (p); | |
177 } | |
178 | |
179 /* | |
180 * Return the contents of the redo buffer as a single string. | |
181 * K_SPECIAL and CSI in the returned string are escaped. | |
182 */ | |
183 char_u * | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
184 get_inserted(void) |
7 | 185 { |
1618 | 186 return get_buffcont(&redobuff, FALSE); |
7 | 187 } |
188 | |
189 /* | |
1130 | 190 * Add string "s" after the current block of buffer "buf". |
7 | 191 * K_SPECIAL and CSI should have been escaped already. |
192 */ | |
193 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
194 add_buff( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
195 buffheader_T *buf, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
196 char_u *s, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
197 long slen) /* length of "s" or -1 */ |
7 | 198 { |
5649 | 199 buffblock_T *p; |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
200 long_u len; |
7 | 201 |
202 if (slen < 0) | |
203 slen = (long)STRLEN(s); | |
204 if (slen == 0) /* don't add empty strings */ | |
205 return; | |
206 | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
207 if (buf->bh_first.b_next == NULL) /* first add to list */ |
7 | 208 { |
209 buf->bh_space = 0; | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
210 buf->bh_curr = &(buf->bh_first); |
7 | 211 } |
212 else if (buf->bh_curr == NULL) /* buffer has already been read */ | |
213 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
214 iemsg(_("E222: Add to read buffer")); |
7 | 215 return; |
216 } | |
217 else if (buf->bh_index != 0) | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
218 mch_memmove(buf->bh_first.b_next->b_str, |
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
219 buf->bh_first.b_next->b_str + buf->bh_index, |
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
220 STRLEN(buf->bh_first.b_next->b_str + buf->bh_index) + 1); |
7 | 221 buf->bh_index = 0; |
222 | |
223 if (buf->bh_space >= (int)slen) | |
224 { | |
225 len = (long_u)STRLEN(buf->bh_curr->b_str); | |
416 | 226 vim_strncpy(buf->bh_curr->b_str + len, s, (size_t)slen); |
7 | 227 buf->bh_space -= slen; |
228 } | |
229 else | |
230 { | |
231 if (slen < MINIMAL_SIZE) | |
232 len = MINIMAL_SIZE; | |
233 else | |
234 len = slen; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
235 p = alloc(sizeof(buffblock_T) + len); |
7 | 236 if (p == NULL) |
237 return; /* no space, just forget it */ | |
835 | 238 buf->bh_space = (int)(len - slen); |
416 | 239 vim_strncpy(p->b_str, s, (size_t)slen); |
7 | 240 |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
241 p->b_next = buf->bh_curr->b_next; |
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
242 buf->bh_curr->b_next = p; |
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
243 buf->bh_curr = p; |
7 | 244 } |
245 return; | |
246 } | |
247 | |
248 /* | |
249 * Add number "n" to buffer "buf". | |
250 */ | |
251 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
252 add_num_buff(buffheader_T *buf, long n) |
7 | 253 { |
254 char_u number[32]; | |
255 | |
256 sprintf((char *)number, "%ld", n); | |
257 add_buff(buf, number, -1L); | |
258 } | |
259 | |
260 /* | |
261 * Add character 'c' to buffer "buf". | |
262 * Translates special keys, NUL, CSI, K_SPECIAL and multibyte characters. | |
263 */ | |
264 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
265 add_char_buff(buffheader_T *buf, int c) |
7 | 266 { |
267 char_u bytes[MB_MAXBYTES + 1]; | |
268 int len; | |
269 int i; | |
270 char_u temp[4]; | |
271 | |
272 if (IS_SPECIAL(c)) | |
273 len = 1; | |
274 else | |
275 len = (*mb_char2bytes)(c, bytes); | |
276 for (i = 0; i < len; ++i) | |
277 { | |
278 if (!IS_SPECIAL(c)) | |
279 c = bytes[i]; | |
280 | |
281 if (IS_SPECIAL(c) || c == K_SPECIAL || c == NUL) | |
282 { | |
283 /* translate special key code into three byte sequence */ | |
284 temp[0] = K_SPECIAL; | |
285 temp[1] = K_SECOND(c); | |
286 temp[2] = K_THIRD(c); | |
287 temp[3] = NUL; | |
288 } | |
289 #ifdef FEAT_GUI | |
290 else if (c == CSI) | |
291 { | |
292 /* Translate a CSI to a CSI - KS_EXTRA - KE_CSI sequence */ | |
293 temp[0] = CSI; | |
294 temp[1] = KS_EXTRA; | |
295 temp[2] = (int)KE_CSI; | |
296 temp[3] = NUL; | |
297 } | |
298 #endif | |
299 else | |
300 { | |
301 temp[0] = c; | |
302 temp[1] = NUL; | |
303 } | |
304 add_buff(buf, temp, -1L); | |
305 } | |
306 } | |
307 | |
5649 | 308 /* First read ahead buffer. Used for translated commands. */ |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
309 static buffheader_T readbuf1 = {{NULL, {NUL}}, NULL, 0, 0}; |
5649 | 310 |
311 /* Second read ahead buffer. Used for redo. */ | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
312 static buffheader_T readbuf2 = {{NULL, {NUL}}, NULL, 0, 0}; |
5649 | 313 |
7 | 314 /* |
5649 | 315 * Get one byte from the read buffers. Use readbuf1 one first, use readbuf2 |
316 * if that one is empty. | |
7 | 317 * If advance == TRUE go to the next char. |
318 * No translation is done K_SPECIAL and CSI are escaped. | |
319 */ | |
320 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
321 read_readbuffers(int advance) |
7 | 322 { |
5649 | 323 int c; |
324 | |
325 c = read_readbuf(&readbuf1, advance); | |
326 if (c == NUL) | |
327 c = read_readbuf(&readbuf2, advance); | |
328 return c; | |
329 } | |
330 | |
331 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
332 read_readbuf(buffheader_T *buf, int advance) |
5649 | 333 { |
334 char_u c; | |
335 buffblock_T *curr; | |
336 | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
337 if (buf->bh_first.b_next == NULL) /* buffer is empty */ |
7 | 338 return NUL; |
339 | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
340 curr = buf->bh_first.b_next; |
5649 | 341 c = curr->b_str[buf->bh_index]; |
7 | 342 |
343 if (advance) | |
344 { | |
5649 | 345 if (curr->b_str[++buf->bh_index] == NUL) |
7 | 346 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
347 buf->bh_first.b_next = curr->b_next; |
7 | 348 vim_free(curr); |
5649 | 349 buf->bh_index = 0; |
7 | 350 } |
351 } | |
352 return c; | |
353 } | |
354 | |
355 /* | |
5670 | 356 * Prepare the read buffers for reading (if they contain something). |
7 | 357 */ |
358 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
359 start_stuff(void) |
7 | 360 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
361 if (readbuf1.bh_first.b_next != NULL) |
7 | 362 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
363 readbuf1.bh_curr = &(readbuf1.bh_first); |
5649 | 364 readbuf1.bh_space = 0; |
365 } | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
366 if (readbuf2.bh_first.b_next != NULL) |
5649 | 367 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
368 readbuf2.bh_curr = &(readbuf2.bh_first); |
5649 | 369 readbuf2.bh_space = 0; |
7 | 370 } |
371 } | |
372 | |
373 /* | |
374 * Return TRUE if the stuff buffer is empty. | |
375 */ | |
376 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
377 stuff_empty(void) |
7 | 378 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
379 return (readbuf1.bh_first.b_next == NULL |
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
380 && readbuf2.bh_first.b_next == NULL); |
5649 | 381 } |
382 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
383 #if defined(FEAT_EVAL) || defined(PROTO) |
5649 | 384 /* |
385 * Return TRUE if readbuf1 is empty. There may still be redo characters in | |
386 * redbuf2. | |
387 */ | |
388 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
389 readbuf1_empty(void) |
5649 | 390 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
391 return (readbuf1.bh_first.b_next == NULL); |
7 | 392 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
393 #endif |
7 | 394 |
395 /* | |
396 * Set a typeahead character that won't be flushed. | |
397 */ | |
398 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
399 typeahead_noflush(int c) |
7 | 400 { |
401 typeahead_char = c; | |
402 } | |
403 | |
404 /* | |
405 * Remove the contents of the stuff buffer and the mapped characters in the | |
3263 | 406 * typeahead buffer (used in case of an error). If "flush_typeahead" is true, |
7 | 407 * flush all typeahead characters (used when interrupted by a CTRL-C). |
408 */ | |
409 void | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
410 flush_buffers(flush_buffers_T flush_typeahead) |
7 | 411 { |
412 init_typebuf(); | |
413 | |
414 start_stuff(); | |
5649 | 415 while (read_readbuffers(TRUE) != NUL) |
7 | 416 ; |
417 | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
418 if (flush_typeahead == FLUSH_MINIMAL) |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
419 { |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
420 // remove mapped characters at the start only |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
421 typebuf.tb_off += typebuf.tb_maplen; |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
422 typebuf.tb_len -= typebuf.tb_maplen; |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
423 } |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
424 else |
7 | 425 { |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
426 // remove typeahead |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
427 if (flush_typeahead == FLUSH_INPUT) |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
428 // We have to get all characters, because we may delete the first |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
429 // part of an escape sequence. In an xterm we get one char at a |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
430 // time and we have to get them all. |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
431 while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L) != 0) |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
432 ; |
7 | 433 typebuf.tb_off = MAXMAPLEN; |
434 typebuf.tb_len = 0; | |
11577
2bc04093ed28
patch 8.0.0671: hang when typing CTRL-C in confirm() in timer
Christian Brabandt <cb@256bit.org>
parents:
11490
diff
changeset
|
435 #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
2bc04093ed28
patch 8.0.0671: hang when typing CTRL-C in confirm() in timer
Christian Brabandt <cb@256bit.org>
parents:
11490
diff
changeset
|
436 /* Reset the flag that text received from a client or from feedkeys() |
2bc04093ed28
patch 8.0.0671: hang when typing CTRL-C in confirm() in timer
Christian Brabandt <cb@256bit.org>
parents:
11490
diff
changeset
|
437 * was inserted in the typeahead buffer. */ |
2bc04093ed28
patch 8.0.0671: hang when typing CTRL-C in confirm() in timer
Christian Brabandt <cb@256bit.org>
parents:
11490
diff
changeset
|
438 typebuf_was_filled = FALSE; |
2bc04093ed28
patch 8.0.0671: hang when typing CTRL-C in confirm() in timer
Christian Brabandt <cb@256bit.org>
parents:
11490
diff
changeset
|
439 #endif |
7 | 440 } |
441 typebuf.tb_maplen = 0; | |
442 typebuf.tb_silent = 0; | |
443 cmd_silent = FALSE; | |
444 typebuf.tb_no_abbr_cnt = 0; | |
445 } | |
446 | |
447 /* | |
448 * The previous contents of the redo buffer is kept in old_redobuffer. | |
449 * This is used for the CTRL-O <.> command in insert mode. | |
450 */ | |
451 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
452 ResetRedobuff(void) |
7 | 453 { |
454 if (!block_redo) | |
455 { | |
456 free_buff(&old_redobuff); | |
457 old_redobuff = redobuff; | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
458 redobuff.bh_first.b_next = NULL; |
7 | 459 } |
460 } | |
461 | |
3324 | 462 /* |
463 * Discard the contents of the redo buffer and restore the previous redo | |
464 * buffer. | |
465 */ | |
466 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
467 CancelRedo(void) |
3324 | 468 { |
469 if (!block_redo) | |
470 { | |
471 free_buff(&redobuff); | |
472 redobuff = old_redobuff; | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
473 old_redobuff.bh_first.b_next = NULL; |
3324 | 474 start_stuff(); |
5649 | 475 while (read_readbuffers(TRUE) != NUL) |
3324 | 476 ; |
477 } | |
478 } | |
479 | |
7 | 480 /* |
481 * Save redobuff and old_redobuff to save_redobuff and save_old_redobuff. | |
482 * Used before executing autocommands and user functions. | |
483 */ | |
484 void | |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
485 saveRedobuff(save_redo_T *save_redo) |
7 | 486 { |
487 char_u *s; | |
488 | |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
489 save_redo->sr_redobuff = redobuff; |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
490 redobuff.bh_first.b_next = NULL; |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
491 save_redo->sr_old_redobuff = old_redobuff; |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
492 old_redobuff.bh_first.b_next = NULL; |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
493 |
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
494 /* Make a copy, so that ":normal ." in a function works. */ |
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
495 s = get_buffcont(&save_redo->sr_redobuff, FALSE); |
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
496 if (s != NULL) |
7 | 497 { |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
498 add_buff(&redobuff, s, -1L); |
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
499 vim_free(s); |
7 | 500 } |
501 } | |
502 | |
503 /* | |
504 * Restore redobuff and old_redobuff from save_redobuff and save_old_redobuff. | |
505 * Used after executing autocommands and user functions. | |
506 */ | |
507 void | |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
508 restoreRedobuff(save_redo_T *save_redo) |
7 | 509 { |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
510 free_buff(&redobuff); |
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
511 redobuff = save_redo->sr_redobuff; |
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
512 free_buff(&old_redobuff); |
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
513 old_redobuff = save_redo->sr_old_redobuff; |
7 | 514 } |
515 | |
516 /* | |
517 * Append "s" to the redo buffer. | |
518 * K_SPECIAL and CSI should already have been escaped. | |
519 */ | |
520 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
521 AppendToRedobuff(char_u *s) |
7 | 522 { |
523 if (!block_redo) | |
524 add_buff(&redobuff, s, -1L); | |
525 } | |
526 | |
527 /* | |
528 * Append to Redo buffer literally, escaping special characters with CTRL-V. | |
529 * K_SPECIAL and CSI are escaped as well. | |
530 */ | |
531 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
532 AppendToRedobuffLit( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
533 char_u *str, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
534 int len) /* length of "str" or -1 for up to the NUL */ |
7 | 535 { |
620 | 536 char_u *s = str; |
7 | 537 int c; |
538 char_u *start; | |
539 | |
540 if (block_redo) | |
541 return; | |
542 | |
620 | 543 while (len < 0 ? *s != NUL : s - str < len) |
7 | 544 { |
545 /* Put a string of normal characters in the redo buffer (that's | |
546 * faster). */ | |
547 start = s; | |
548 while (*s >= ' ' | |
549 #ifndef EBCDIC | |
550 && *s < DEL /* EBCDIC: all chars above space are normal */ | |
551 #endif | |
620 | 552 && (len < 0 || s - str < len)) |
7 | 553 ++s; |
554 | |
555 /* Don't put '0' or '^' as last character, just in case a CTRL-D is | |
556 * typed next. */ | |
557 if (*s == NUL && (s[-1] == '0' || s[-1] == '^')) | |
558 --s; | |
559 if (s > start) | |
560 add_buff(&redobuff, start, (long)(s - start)); | |
561 | |
620 | 562 if (*s == NUL || (len >= 0 && s - str >= len)) |
563 break; | |
564 | |
565 /* Handle a special or multibyte character. */ | |
566 if (has_mbyte) | |
567 /* Handle composing chars separately. */ | |
568 c = mb_cptr2char_adv(&s); | |
569 else | |
570 c = *s++; | |
571 if (c < ' ' || c == DEL || (*s == NUL && (c == '0' || c == '^'))) | |
572 add_char_buff(&redobuff, Ctrl_V); | |
573 | |
574 /* CTRL-V '0' must be inserted as CTRL-V 048 (EBCDIC: xf0) */ | |
575 if (*s == NUL && c == '0') | |
7 | 576 #ifdef EBCDIC |
620 | 577 add_buff(&redobuff, (char_u *)"xf0", 3L); |
7 | 578 #else |
620 | 579 add_buff(&redobuff, (char_u *)"048", 3L); |
7 | 580 #endif |
620 | 581 else |
582 add_char_buff(&redobuff, c); | |
7 | 583 } |
584 } | |
585 | |
586 /* | |
587 * Append a character to the redo buffer. | |
588 * Translates special keys, NUL, CSI, K_SPECIAL and multibyte characters. | |
589 */ | |
590 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
591 AppendCharToRedobuff(int c) |
7 | 592 { |
593 if (!block_redo) | |
594 add_char_buff(&redobuff, c); | |
595 } | |
596 | |
597 /* | |
598 * Append a number to the redo buffer. | |
599 */ | |
600 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
601 AppendNumberToRedobuff(long n) |
7 | 602 { |
603 if (!block_redo) | |
604 add_num_buff(&redobuff, n); | |
605 } | |
606 | |
607 /* | |
608 * Append string "s" to the stuff buffer. | |
609 * CSI and K_SPECIAL must already have been escaped. | |
610 */ | |
611 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
612 stuffReadbuff(char_u *s) |
7 | 613 { |
5649 | 614 add_buff(&readbuf1, s, -1L); |
7 | 615 } |
616 | |
6098 | 617 /* |
618 * Append string "s" to the redo stuff buffer. | |
619 * CSI and K_SPECIAL must already have been escaped. | |
620 */ | |
621 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
622 stuffRedoReadbuff(char_u *s) |
6098 | 623 { |
624 add_buff(&readbuf2, s, -1L); | |
625 } | |
626 | |
7 | 627 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
628 stuffReadbuffLen(char_u *s, long len) |
7 | 629 { |
5649 | 630 add_buff(&readbuf1, s, len); |
7 | 631 } |
632 | |
633 #if defined(FEAT_EVAL) || defined(PROTO) | |
634 /* | |
635 * Stuff "s" into the stuff buffer, leaving special key codes unmodified and | |
636 * escaping other K_SPECIAL and CSI bytes. | |
2784 | 637 * Change CR, LF and ESC into a space. |
7 | 638 */ |
639 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
640 stuffReadbuffSpec(char_u *s) |
7 | 641 { |
2784 | 642 int c; |
643 | |
7 | 644 while (*s != NUL) |
645 { | |
646 if (*s == K_SPECIAL && s[1] != NUL && s[2] != NUL) | |
647 { | |
648 /* Insert special key literally. */ | |
649 stuffReadbuffLen(s, 3L); | |
650 s += 3; | |
651 } | |
652 else | |
2784 | 653 { |
654 c = mb_ptr2char_adv(&s); | |
655 if (c == CAR || c == NL || c == ESC) | |
656 c = ' '; | |
657 stuffcharReadbuff(c); | |
658 } | |
7 | 659 } |
660 } | |
661 #endif | |
662 | |
663 /* | |
664 * Append a character to the stuff buffer. | |
665 * Translates special keys, NUL, CSI, K_SPECIAL and multibyte characters. | |
666 */ | |
667 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
668 stuffcharReadbuff(int c) |
7 | 669 { |
5649 | 670 add_char_buff(&readbuf1, c); |
7 | 671 } |
672 | |
673 /* | |
674 * Append a number to the stuff buffer. | |
675 */ | |
676 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
677 stuffnumReadbuff(long n) |
7 | 678 { |
5649 | 679 add_num_buff(&readbuf1, n); |
7 | 680 } |
681 | |
682 /* | |
683 * Read a character from the redo buffer. Translates K_SPECIAL, CSI and | |
684 * multibyte characters. | |
685 * The redo buffer is left as it is. | |
3324 | 686 * If init is TRUE, prepare for redo, return FAIL if nothing to redo, OK |
687 * otherwise. | |
688 * If old is TRUE, use old_redobuff instead of redobuff. | |
7 | 689 */ |
690 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
691 read_redo(int init, int old_redo) |
7 | 692 { |
5649 | 693 static buffblock_T *bp; |
694 static char_u *p; | |
695 int c; | |
696 int n; | |
697 char_u buf[MB_MAXBYTES + 1]; | |
698 int i; | |
7 | 699 |
700 if (init) | |
701 { | |
702 if (old_redo) | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
703 bp = old_redobuff.bh_first.b_next; |
7 | 704 else |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
705 bp = redobuff.bh_first.b_next; |
7 | 706 if (bp == NULL) |
707 return FAIL; | |
708 p = bp->b_str; | |
709 return OK; | |
710 } | |
711 if ((c = *p) != NUL) | |
712 { | |
713 /* Reverse the conversion done by add_char_buff() */ | |
714 /* For a multi-byte character get all the bytes and return the | |
715 * converted character. */ | |
716 if (has_mbyte && (c != K_SPECIAL || p[1] == KS_SPECIAL)) | |
717 n = MB_BYTE2LEN_CHECK(c); | |
718 else | |
719 n = 1; | |
720 for (i = 0; ; ++i) | |
721 { | |
722 if (c == K_SPECIAL) /* special key or escaped K_SPECIAL */ | |
723 { | |
724 c = TO_SPECIAL(p[1], p[2]); | |
725 p += 2; | |
726 } | |
727 #ifdef FEAT_GUI | |
728 if (c == CSI) /* escaped CSI */ | |
729 p += 2; | |
730 #endif | |
731 if (*++p == NUL && bp->b_next != NULL) | |
732 { | |
733 bp = bp->b_next; | |
734 p = bp->b_str; | |
735 } | |
736 buf[i] = c; | |
737 if (i == n - 1) /* last byte of a character */ | |
738 { | |
739 if (n != 1) | |
740 c = (*mb_ptr2char)(buf); | |
741 break; | |
742 } | |
743 c = *p; | |
744 if (c == NUL) /* cannot happen? */ | |
745 break; | |
746 } | |
747 } | |
748 | |
749 return c; | |
750 } | |
751 | |
752 /* | |
753 * Copy the rest of the redo buffer into the stuff buffer (in a slow way). | |
754 * If old_redo is TRUE, use old_redobuff instead of redobuff. | |
755 * The escaped K_SPECIAL and CSI are copied without translation. | |
756 */ | |
757 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
758 copy_redo(int old_redo) |
7 | 759 { |
760 int c; | |
761 | |
762 while ((c = read_redo(FALSE, old_redo)) != NUL) | |
5649 | 763 add_char_buff(&readbuf2, c); |
7 | 764 } |
765 | |
766 /* | |
5649 | 767 * Stuff the redo buffer into readbuf2. |
7 | 768 * Insert the redo count into the command. |
769 * If "old_redo" is TRUE, the last but one command is repeated | |
770 * instead of the last command (inserting text). This is used for | |
771 * CTRL-O <.> in insert mode | |
772 * | |
773 * return FAIL for failure, OK otherwise | |
774 */ | |
775 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
776 start_redo(long count, int old_redo) |
7 | 777 { |
778 int c; | |
779 | |
780 /* init the pointers; return if nothing to redo */ | |
781 if (read_redo(TRUE, old_redo) == FAIL) | |
782 return FAIL; | |
783 | |
784 c = read_redo(FALSE, old_redo); | |
785 | |
786 /* copy the buffer name, if present */ | |
787 if (c == '"') | |
788 { | |
5649 | 789 add_buff(&readbuf2, (char_u *)"\"", 1L); |
7 | 790 c = read_redo(FALSE, old_redo); |
791 | |
792 /* if a numbered buffer is used, increment the number */ | |
793 if (c >= '1' && c < '9') | |
794 ++c; | |
5649 | 795 add_char_buff(&readbuf2, c); |
14009
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
796 |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
797 /* the expression register should be re-evaluated */ |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
798 if (c == '=') |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
799 { |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
800 add_char_buff(&readbuf2, CAR); |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
801 cmd_silent = TRUE; |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
802 } |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
803 |
7 | 804 c = read_redo(FALSE, old_redo); |
805 } | |
806 | |
807 if (c == 'v') /* redo Visual */ | |
808 { | |
809 VIsual = curwin->w_cursor; | |
810 VIsual_active = TRUE; | |
811 VIsual_select = FALSE; | |
812 VIsual_reselect = TRUE; | |
813 redo_VIsual_busy = TRUE; | |
814 c = read_redo(FALSE, old_redo); | |
815 } | |
816 | |
817 /* try to enter the count (in place of a previous count) */ | |
818 if (count) | |
819 { | |
820 while (VIM_ISDIGIT(c)) /* skip "old" count */ | |
821 c = read_redo(FALSE, old_redo); | |
5649 | 822 add_num_buff(&readbuf2, count); |
7 | 823 } |
824 | |
825 /* copy from the redo buffer into the stuff buffer */ | |
5649 | 826 add_char_buff(&readbuf2, c); |
7 | 827 copy_redo(old_redo); |
828 return OK; | |
829 } | |
830 | |
831 /* | |
832 * Repeat the last insert (R, o, O, a, A, i or I command) by stuffing | |
5649 | 833 * the redo buffer into readbuf2. |
7 | 834 * return FAIL for failure, OK otherwise |
835 */ | |
836 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
837 start_redo_ins(void) |
7 | 838 { |
839 int c; | |
840 | |
841 if (read_redo(TRUE, FALSE) == FAIL) | |
842 return FAIL; | |
843 start_stuff(); | |
844 | |
845 /* skip the count and the command character */ | |
846 while ((c = read_redo(FALSE, FALSE)) != NUL) | |
847 { | |
848 if (vim_strchr((char_u *)"AaIiRrOo", c) != NULL) | |
849 { | |
850 if (c == 'O' || c == 'o') | |
5649 | 851 add_buff(&readbuf2, NL_STR, -1L); |
7 | 852 break; |
853 } | |
854 } | |
855 | |
856 /* copy the typed text from the redo buffer into the stuff buffer */ | |
857 copy_redo(FALSE); | |
858 block_redo = TRUE; | |
859 return OK; | |
860 } | |
861 | |
862 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
863 stop_redo_ins(void) |
7 | 864 { |
865 block_redo = FALSE; | |
866 } | |
867 | |
868 /* | |
869 * Initialize typebuf.tb_buf to point to typebuf_init. | |
870 * alloc() cannot be used here: In out-of-memory situations it would | |
871 * be impossible to type anything. | |
872 */ | |
873 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
874 init_typebuf(void) |
7 | 875 { |
876 if (typebuf.tb_buf == NULL) | |
877 { | |
878 typebuf.tb_buf = typebuf_init; | |
879 typebuf.tb_noremap = noremapbuf_init; | |
880 typebuf.tb_buflen = TYPELEN_INIT; | |
881 typebuf.tb_len = 0; | |
11331
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
882 typebuf.tb_off = MAXMAPLEN + 4; |
7 | 883 typebuf.tb_change_cnt = 1; |
884 } | |
885 } | |
886 | |
887 /* | |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
888 * Returns TRUE when keys cannot be remapped. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
889 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
890 int |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
891 noremap_keys(void) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
892 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
893 return KeyNoremap & (RM_NONE|RM_SCRIPT); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
894 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
895 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
896 /* |
7408
1886f2863437
commit https://github.com/vim/vim/commit/e7fedb6ebe72d9a475aa65109b77d5ed4667067a
Christian Brabandt <cb@256bit.org>
parents:
7117
diff
changeset
|
897 * Insert a string in position 'offset' in the typeahead buffer (for "@r" |
1886f2863437
commit https://github.com/vim/vim/commit/e7fedb6ebe72d9a475aa65109b77d5ed4667067a
Christian Brabandt <cb@256bit.org>
parents:
7117
diff
changeset
|
898 * and ":normal" command, vgetorpeek() and check_termcode()). |
7 | 899 * |
900 * If noremap is REMAP_YES, new string can be mapped again. | |
901 * If noremap is REMAP_NONE, new string cannot be mapped again. | |
10 | 902 * If noremap is REMAP_SKIP, fist char of new string cannot be mapped again, |
903 * but abbreviations are allowed. | |
7 | 904 * If noremap is REMAP_SCRIPT, new string cannot be mapped again, except for |
905 * script-local mappings. | |
906 * If noremap is > 0, that many characters of the new string cannot be mapped. | |
907 * | |
908 * If nottyped is TRUE, the string does not return KeyTyped (don't use when | |
909 * offset is non-zero!). | |
910 * | |
911 * If silent is TRUE, cmd_silent is set when the characters are obtained. | |
912 * | |
913 * return FAIL for failure, OK otherwise | |
914 */ | |
915 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
916 ins_typebuf( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
917 char_u *str, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
918 int noremap, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
919 int offset, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
920 int nottyped, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
921 int silent) |
7 | 922 { |
923 char_u *s1, *s2; | |
924 int newlen; | |
925 int addlen; | |
926 int i; | |
927 int newoff; | |
928 int val; | |
929 int nrm; | |
930 | |
931 init_typebuf(); | |
932 if (++typebuf.tb_change_cnt == 0) | |
933 typebuf.tb_change_cnt = 1; | |
934 | |
935 addlen = (int)STRLEN(str); | |
1130 | 936 |
7 | 937 if (offset == 0 && addlen <= typebuf.tb_off) |
938 { | |
10549
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
939 /* |
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
940 * Easy case: there is room in front of typebuf.tb_buf[typebuf.tb_off] |
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
941 */ |
7 | 942 typebuf.tb_off -= addlen; |
943 mch_memmove(typebuf.tb_buf + typebuf.tb_off, str, (size_t)addlen); | |
944 } | |
11331
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
945 else if (typebuf.tb_len == 0 && typebuf.tb_buflen |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
946 >= addlen + 3 * (MAXMAPLEN + 4)) |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
947 { |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
948 /* |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
949 * Buffer is empty and string fits in the existing buffer. |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
950 * Leave some space before and after, if possible. |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
951 */ |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
952 typebuf.tb_off = (typebuf.tb_buflen - addlen - 3 * (MAXMAPLEN + 4)) / 2; |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
953 mch_memmove(typebuf.tb_buf + typebuf.tb_off, str, (size_t)addlen); |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
954 } |
7 | 955 else |
956 { | |
10549
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
957 /* |
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
958 * Need to allocate a new buffer. |
11331
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
959 * In typebuf.tb_buf there must always be room for 3 * (MAXMAPLEN + 4) |
10549
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
960 * characters. We add some extra room to avoid having to allocate too |
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
961 * often. |
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
962 */ |
7 | 963 newoff = MAXMAPLEN + 4; |
964 newlen = typebuf.tb_len + addlen + newoff + 4 * (MAXMAPLEN + 4); | |
965 if (newlen < 0) /* string is getting too long */ | |
966 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
967 emsg(_(e_toocompl)); /* also calls flush_buffers */ |
7 | 968 setcursor(); |
969 return FAIL; | |
970 } | |
971 s1 = alloc(newlen); | |
972 if (s1 == NULL) /* out of memory */ | |
973 return FAIL; | |
974 s2 = alloc(newlen); | |
975 if (s2 == NULL) /* out of memory */ | |
976 { | |
977 vim_free(s1); | |
978 return FAIL; | |
979 } | |
980 typebuf.tb_buflen = newlen; | |
981 | |
982 /* copy the old chars, before the insertion point */ | |
983 mch_memmove(s1 + newoff, typebuf.tb_buf + typebuf.tb_off, | |
984 (size_t)offset); | |
985 /* copy the new chars */ | |
986 mch_memmove(s1 + newoff + offset, str, (size_t)addlen); | |
987 /* copy the old chars, after the insertion point, including the NUL at | |
988 * the end */ | |
989 mch_memmove(s1 + newoff + offset + addlen, | |
990 typebuf.tb_buf + typebuf.tb_off + offset, | |
991 (size_t)(typebuf.tb_len - offset + 1)); | |
992 if (typebuf.tb_buf != typebuf_init) | |
993 vim_free(typebuf.tb_buf); | |
994 typebuf.tb_buf = s1; | |
995 | |
996 mch_memmove(s2 + newoff, typebuf.tb_noremap + typebuf.tb_off, | |
997 (size_t)offset); | |
998 mch_memmove(s2 + newoff + offset + addlen, | |
999 typebuf.tb_noremap + typebuf.tb_off + offset, | |
1000 (size_t)(typebuf.tb_len - offset)); | |
1001 if (typebuf.tb_noremap != noremapbuf_init) | |
1002 vim_free(typebuf.tb_noremap); | |
1003 typebuf.tb_noremap = s2; | |
1004 | |
1005 typebuf.tb_off = newoff; | |
1006 } | |
1007 typebuf.tb_len += addlen; | |
1008 | |
1009 /* If noremap == REMAP_SCRIPT: do remap script-local mappings. */ | |
1010 if (noremap == REMAP_SCRIPT) | |
1011 val = RM_SCRIPT; | |
10 | 1012 else if (noremap == REMAP_SKIP) |
1013 val = RM_ABBR; | |
7 | 1014 else |
1015 val = RM_NONE; | |
1016 | |
1017 /* | |
1018 * Adjust typebuf.tb_noremap[] for the new characters: | |
1019 * If noremap == REMAP_NONE or REMAP_SCRIPT: new characters are | |
1020 * (sometimes) not remappable | |
1021 * If noremap == REMAP_YES: all the new characters are mappable | |
1022 * If noremap > 0: "noremap" characters are not remappable, the rest | |
1023 * mappable | |
1024 */ | |
10 | 1025 if (noremap == REMAP_SKIP) |
1026 nrm = 1; | |
1027 else if (noremap < 0) | |
7 | 1028 nrm = addlen; |
1029 else | |
1030 nrm = noremap; | |
1031 for (i = 0; i < addlen; ++i) | |
1032 typebuf.tb_noremap[typebuf.tb_off + i + offset] = | |
1033 (--nrm >= 0) ? val : RM_YES; | |
1034 | |
1035 /* tb_maplen and tb_silent only remember the length of mapped and/or | |
1036 * silent mappings at the start of the buffer, assuming that a mapped | |
1037 * sequence doesn't result in typed characters. */ | |
1038 if (nottyped || typebuf.tb_maplen > offset) | |
1039 typebuf.tb_maplen += addlen; | |
1040 if (silent || typebuf.tb_silent > offset) | |
1041 { | |
1042 typebuf.tb_silent += addlen; | |
1043 cmd_silent = TRUE; | |
1044 } | |
1045 if (typebuf.tb_no_abbr_cnt && offset == 0) /* and not used for abbrev.s */ | |
1046 typebuf.tb_no_abbr_cnt += addlen; | |
1047 | |
1048 return OK; | |
1049 } | |
1050 | |
1051 /* | |
852 | 1052 * Put character "c" back into the typeahead buffer. |
1053 * Can be used for a character obtained by vgetc() that needs to be put back. | |
1051 | 1054 * Uses cmd_silent, KeyTyped and KeyNoremap to restore the flags belonging to |
1055 * the char. | |
852 | 1056 */ |
1057 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1058 ins_char_typebuf(int c) |
852 | 1059 { |
3549 | 1060 char_u buf[MB_MAXBYTES + 1]; |
852 | 1061 if (IS_SPECIAL(c)) |
1062 { | |
1063 buf[0] = K_SPECIAL; | |
1064 buf[1] = K_SECOND(c); | |
1065 buf[2] = K_THIRD(c); | |
1066 buf[3] = NUL; | |
1067 } | |
1068 else | |
1069 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
1051 | 1070 (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent); |
852 | 1071 } |
1072 | |
1073 /* | |
7 | 1074 * Return TRUE if the typeahead buffer was changed (while waiting for a |
841 | 1075 * character to arrive). Happens when a message was received from a client or |
842 | 1076 * from feedkeys(). |
7 | 1077 * But check in a more generic way to avoid trouble: When "typebuf.tb_buf" |
1078 * changed it was reallocated and the old pointer can no longer be used. | |
1079 * Or "typebuf.tb_off" may have been changed and we would overwrite characters | |
1080 * that was just added. | |
1081 */ | |
1082 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1083 typebuf_changed( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1084 int tb_change_cnt) /* old value of typebuf.tb_change_cnt */ |
7 | 1085 { |
1086 return (tb_change_cnt != 0 && (typebuf.tb_change_cnt != tb_change_cnt | |
841 | 1087 #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
1088 || typebuf_was_filled | |
7 | 1089 #endif |
1090 )); | |
1091 } | |
1092 | |
1093 /* | |
1094 * Return TRUE if there are no characters in the typeahead buffer that have | |
1095 * not been typed (result from a mapping or come from ":normal"). | |
1096 */ | |
1097 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1098 typebuf_typed(void) |
7 | 1099 { |
1100 return typebuf.tb_maplen == 0; | |
1101 } | |
1102 | |
1103 /* | |
1104 * Return the number of characters that are mapped (or not typed). | |
1105 */ | |
1106 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1107 typebuf_maplen(void) |
7 | 1108 { |
1109 return typebuf.tb_maplen; | |
1110 } | |
1111 | |
1112 /* | |
1113 * remove "len" characters from typebuf.tb_buf[typebuf.tb_off + offset] | |
1114 */ | |
1115 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1116 del_typebuf(int len, int offset) |
7 | 1117 { |
1118 int i; | |
1119 | |
1120 if (len == 0) | |
1121 return; /* nothing to do */ | |
1122 | |
1123 typebuf.tb_len -= len; | |
1124 | |
1125 /* | |
1126 * Easy case: Just increase typebuf.tb_off. | |
1127 */ | |
1128 if (offset == 0 && typebuf.tb_buflen - (typebuf.tb_off + len) | |
1129 >= 3 * MAXMAPLEN + 3) | |
1130 typebuf.tb_off += len; | |
1131 /* | |
1132 * Have to move the characters in typebuf.tb_buf[] and typebuf.tb_noremap[] | |
1133 */ | |
1134 else | |
1135 { | |
1136 i = typebuf.tb_off + offset; | |
1137 /* | |
1138 * Leave some extra room at the end to avoid reallocation. | |
1139 */ | |
1140 if (typebuf.tb_off > MAXMAPLEN) | |
1141 { | |
1142 mch_memmove(typebuf.tb_buf + MAXMAPLEN, | |
1143 typebuf.tb_buf + typebuf.tb_off, (size_t)offset); | |
1144 mch_memmove(typebuf.tb_noremap + MAXMAPLEN, | |
1145 typebuf.tb_noremap + typebuf.tb_off, (size_t)offset); | |
1146 typebuf.tb_off = MAXMAPLEN; | |
1147 } | |
1148 /* adjust typebuf.tb_buf (include the NUL at the end) */ | |
1149 mch_memmove(typebuf.tb_buf + typebuf.tb_off + offset, | |
1150 typebuf.tb_buf + i + len, | |
1151 (size_t)(typebuf.tb_len - offset + 1)); | |
1152 /* adjust typebuf.tb_noremap[] */ | |
1153 mch_memmove(typebuf.tb_noremap + typebuf.tb_off + offset, | |
1154 typebuf.tb_noremap + i + len, | |
1155 (size_t)(typebuf.tb_len - offset)); | |
1156 } | |
1157 | |
1158 if (typebuf.tb_maplen > offset) /* adjust tb_maplen */ | |
1159 { | |
1160 if (typebuf.tb_maplen < offset + len) | |
1161 typebuf.tb_maplen = offset; | |
1162 else | |
1163 typebuf.tb_maplen -= len; | |
1164 } | |
1165 if (typebuf.tb_silent > offset) /* adjust tb_silent */ | |
1166 { | |
1167 if (typebuf.tb_silent < offset + len) | |
1168 typebuf.tb_silent = offset; | |
1169 else | |
1170 typebuf.tb_silent -= len; | |
1171 } | |
1172 if (typebuf.tb_no_abbr_cnt > offset) /* adjust tb_no_abbr_cnt */ | |
1173 { | |
1174 if (typebuf.tb_no_abbr_cnt < offset + len) | |
1175 typebuf.tb_no_abbr_cnt = offset; | |
1176 else | |
1177 typebuf.tb_no_abbr_cnt -= len; | |
1178 } | |
1179 | |
841 | 1180 #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
842 | 1181 /* Reset the flag that text received from a client or from feedkeys() |
841 | 1182 * was inserted in the typeahead buffer. */ |
1183 typebuf_was_filled = FALSE; | |
7 | 1184 #endif |
1185 if (++typebuf.tb_change_cnt == 0) | |
1186 typebuf.tb_change_cnt = 1; | |
1187 } | |
1188 | |
1189 /* | |
1190 * Write typed characters to script file. | |
1191 * If recording is on put the character in the recordbuffer. | |
1192 */ | |
1193 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1194 gotchars(char_u *chars, int len) |
7 | 1195 { |
14247
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1196 char_u *s = chars; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1197 int i; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1198 static char_u buf[4]; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1199 static int buflen = 0; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1200 int todo = len; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1201 |
1130 | 1202 while (todo--) |
7 | 1203 { |
14247
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1204 buf[buflen++] = *s++; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1205 |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1206 // When receiving a special key sequence, store it until we have all |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1207 // the bytes and we can decide what to do with it. |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1208 if (buflen == 1 && buf[0] == K_SPECIAL) |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1209 continue; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1210 if (buflen == 2) |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1211 continue; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1212 if (buflen == 3 && buf[1] == KS_EXTRA |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1213 && (buf[2] == KE_FOCUSGAINED || buf[2] == KE_FOCUSLOST)) |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1214 { |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1215 // Drop K_FOCUSGAINED and K_FOCUSLOST, they are not useful in a |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1216 // recording. |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1217 buflen = 0; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1218 continue; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1219 } |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1220 |
7 | 1221 /* Handle one byte at a time; no translation to be done. */ |
14247
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1222 for (i = 0; i < buflen; ++i) |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1223 updatescript(buf[i]); |
7 | 1224 |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1225 if (reg_recording != 0) |
7 | 1226 { |
14247
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1227 buf[buflen] = NUL; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1228 add_buff(&recordbuff, buf, (long)buflen); |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1229 /* remember how many chars were last recorded */ |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1230 last_recorded_len += buflen; |
7 | 1231 } |
14247
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1232 buflen = 0; |
7 | 1233 } |
1234 may_sync_undo(); | |
1235 | |
1236 #ifdef FEAT_EVAL | |
1237 /* output "debug mode" message next time in debug mode */ | |
1238 debug_did_msg = FALSE; | |
1239 #endif | |
1240 | |
1241 /* Since characters have been typed, consider the following to be in | |
1242 * another mapping. Search string will be kept in history. */ | |
1243 ++maptick; | |
1244 } | |
1245 | |
1246 /* | |
1247 * Sync undo. Called when typed characters are obtained from the typeahead | |
1248 * buffer, or when a menu is used. | |
1249 * Do not sync: | |
1250 * - In Insert mode, unless cursor key has been used. | |
1251 * - While reading a script file. | |
1252 * - When no_u_sync is non-zero. | |
1253 */ | |
1254 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1255 may_sync_undo(void) |
7 | 1256 { |
1257 if ((!(State & (INSERT + CMDLINE)) || arrow_used) | |
825 | 1258 && scriptin[curscript] == NULL) |
1259 u_sync(FALSE); | |
7 | 1260 } |
1261 | |
1262 /* | |
1263 * Make "typebuf" empty and allocate new buffers. | |
1264 * Returns FAIL when out of memory. | |
1265 */ | |
1266 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1267 alloc_typebuf(void) |
7 | 1268 { |
1269 typebuf.tb_buf = alloc(TYPELEN_INIT); | |
1270 typebuf.tb_noremap = alloc(TYPELEN_INIT); | |
1271 if (typebuf.tb_buf == NULL || typebuf.tb_noremap == NULL) | |
1272 { | |
1273 free_typebuf(); | |
1274 return FAIL; | |
1275 } | |
1276 typebuf.tb_buflen = TYPELEN_INIT; | |
11331
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
1277 typebuf.tb_off = MAXMAPLEN + 4; /* can insert without realloc */ |
7 | 1278 typebuf.tb_len = 0; |
1279 typebuf.tb_maplen = 0; | |
1280 typebuf.tb_silent = 0; | |
1281 typebuf.tb_no_abbr_cnt = 0; | |
1282 if (++typebuf.tb_change_cnt == 0) | |
1283 typebuf.tb_change_cnt = 1; | |
1284 return OK; | |
1285 } | |
1286 | |
1287 /* | |
1288 * Free the buffers of "typebuf". | |
1289 */ | |
1290 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1291 free_typebuf(void) |
7 | 1292 { |
1462 | 1293 if (typebuf.tb_buf == typebuf_init) |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1294 internal_error("Free typebuf 1"); |
1462 | 1295 else |
1296 vim_free(typebuf.tb_buf); | |
1992 | 1297 if (typebuf.tb_noremap == noremapbuf_init) |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1298 internal_error("Free typebuf 2"); |
1462 | 1299 else |
1300 vim_free(typebuf.tb_noremap); | |
7 | 1301 } |
1302 | |
1303 /* | |
1304 * When doing ":so! file", the current typeahead needs to be saved, and | |
1305 * restored when "file" has been read completely. | |
1306 */ | |
1307 static typebuf_T saved_typebuf[NSCRIPT]; | |
1308 | |
1309 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1310 save_typebuf(void) |
7 | 1311 { |
1312 init_typebuf(); | |
1313 saved_typebuf[curscript] = typebuf; | |
1314 /* If out of memory: restore typebuf and close file. */ | |
1315 if (alloc_typebuf() == FAIL) | |
1316 { | |
1317 closescript(); | |
1318 return FAIL; | |
1319 } | |
1320 return OK; | |
1321 } | |
1322 | |
1928 | 1323 static int old_char = -1; /* character put back by vungetc() */ |
1324 static int old_mod_mask; /* mod_mask for ungotten character */ | |
4227 | 1325 #ifdef FEAT_MOUSE |
1326 static int old_mouse_row; /* mouse_row related to old_char */ | |
1327 static int old_mouse_col; /* mouse_col related to old_char */ | |
1328 #endif | |
1928 | 1329 |
7 | 1330 /* |
1331 * Save all three kinds of typeahead, so that the user must type at a prompt. | |
1332 */ | |
1333 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1334 save_typeahead(tasave_T *tp) |
7 | 1335 { |
1336 tp->save_typebuf = typebuf; | |
1337 tp->typebuf_valid = (alloc_typebuf() == OK); | |
1338 if (!tp->typebuf_valid) | |
1339 typebuf = tp->save_typebuf; | |
1340 | |
1928 | 1341 tp->old_char = old_char; |
1342 tp->old_mod_mask = old_mod_mask; | |
1343 old_char = -1; | |
1344 | |
5649 | 1345 tp->save_readbuf1 = readbuf1; |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
1346 readbuf1.bh_first.b_next = NULL; |
5649 | 1347 tp->save_readbuf2 = readbuf2; |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
1348 readbuf2.bh_first.b_next = NULL; |
7 | 1349 # ifdef USE_INPUT_BUF |
1350 tp->save_inputbuf = get_input_buf(); | |
1351 # endif | |
1352 } | |
1353 | |
1354 /* | |
1355 * Restore the typeahead to what it was before calling save_typeahead(). | |
1356 * The allocated memory is freed, can only be called once! | |
1357 */ | |
1358 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1359 restore_typeahead(tasave_T *tp) |
7 | 1360 { |
1361 if (tp->typebuf_valid) | |
1362 { | |
1363 free_typebuf(); | |
1364 typebuf = tp->save_typebuf; | |
1365 } | |
1366 | |
1928 | 1367 old_char = tp->old_char; |
1368 old_mod_mask = tp->old_mod_mask; | |
1369 | |
5649 | 1370 free_buff(&readbuf1); |
1371 readbuf1 = tp->save_readbuf1; | |
1372 free_buff(&readbuf2); | |
1373 readbuf2 = tp->save_readbuf2; | |
7 | 1374 # ifdef USE_INPUT_BUF |
1375 set_input_buf(tp->save_inputbuf); | |
1376 # endif | |
1377 } | |
1378 | |
1379 /* | |
1380 * Open a new script file for the ":source!" command. | |
1381 */ | |
1382 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1383 openscript( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1384 char_u *name, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1385 int directly) /* when TRUE execute directly */ |
7 | 1386 { |
1387 if (curscript + 1 == NSCRIPT) | |
1388 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
1389 emsg(_(e_nesting)); |
7 | 1390 return; |
1391 } | |
16726
fbab59a5ee6b
patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents:
16712
diff
changeset
|
1392 |
fbab59a5ee6b
patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents:
16712
diff
changeset
|
1393 // Disallow sourcing a file in the sandbox, the commands would be executed |
fbab59a5ee6b
patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents:
16712
diff
changeset
|
1394 // later, possibly outside of the sandbox. |
fbab59a5ee6b
patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents:
16712
diff
changeset
|
1395 if (check_secure()) |
fbab59a5ee6b
patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents:
16712
diff
changeset
|
1396 return; |
fbab59a5ee6b
patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents:
16712
diff
changeset
|
1397 |
1462 | 1398 #ifdef FEAT_EVAL |
1399 if (ignore_script) | |
1400 /* Not reading from script, also don't open one. Warning message? */ | |
1401 return; | |
1402 #endif | |
7 | 1403 |
1404 if (scriptin[curscript] != NULL) /* already reading script */ | |
1405 ++curscript; | |
1406 /* use NameBuff for expanded name */ | |
1407 expand_env(name, NameBuff, MAXPATHL); | |
1408 if ((scriptin[curscript] = mch_fopen((char *)NameBuff, READBIN)) == NULL) | |
1409 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
1410 semsg(_(e_notopen), name); |
7 | 1411 if (curscript) |
1412 --curscript; | |
1413 return; | |
1414 } | |
1415 if (save_typebuf() == FAIL) | |
1416 return; | |
1417 | |
1418 /* | |
1419 * Execute the commands from the file right now when using ":source!" | |
1420 * after ":global" or ":argdo" or in a loop. Also when another command | |
1421 * follows. This means the display won't be updated. Don't do this | |
1422 * always, "make test" would fail. | |
1423 */ | |
1424 if (directly) | |
1425 { | |
1426 oparg_T oa; | |
1427 int oldcurscript; | |
1428 int save_State = State; | |
1429 int save_restart_edit = restart_edit; | |
1430 int save_insertmode = p_im; | |
1431 int save_finish_op = finish_op; | |
1432 int save_msg_scroll = msg_scroll; | |
1433 | |
1434 State = NORMAL; | |
1435 msg_scroll = FALSE; /* no msg scrolling in Normal mode */ | |
1436 restart_edit = 0; /* don't go to Insert mode */ | |
1437 p_im = FALSE; /* don't use 'insertmode' */ | |
1438 clear_oparg(&oa); | |
1439 finish_op = FALSE; | |
1440 | |
1441 oldcurscript = curscript; | |
1442 do | |
1443 { | |
16712
329e28ed10fd
patch 8.1.1358: cannot enter character with a CSI byte
Bram Moolenaar <Bram@vim.org>
parents:
16531
diff
changeset
|
1444 update_topline_cursor(); // update cursor position and topline |
329e28ed10fd
patch 8.1.1358: cannot enter character with a CSI byte
Bram Moolenaar <Bram@vim.org>
parents:
16531
diff
changeset
|
1445 normal_cmd(&oa, FALSE); // execute one command |
329e28ed10fd
patch 8.1.1358: cannot enter character with a CSI byte
Bram Moolenaar <Bram@vim.org>
parents:
16531
diff
changeset
|
1446 vpeekc(); // check for end of file |
7 | 1447 } |
1448 while (scriptin[oldcurscript] != NULL); | |
1449 | |
1450 State = save_State; | |
1451 msg_scroll = save_msg_scroll; | |
1452 restart_edit = save_restart_edit; | |
1453 p_im = save_insertmode; | |
1454 finish_op = save_finish_op; | |
1455 } | |
1456 } | |
1457 | |
1458 /* | |
1459 * Close the currently active input script. | |
1460 */ | |
1461 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1462 closescript(void) |
7 | 1463 { |
1464 free_typebuf(); | |
1465 typebuf = saved_typebuf[curscript]; | |
1466 | |
1467 fclose(scriptin[curscript]); | |
1468 scriptin[curscript] = NULL; | |
1469 if (curscript > 0) | |
1470 --curscript; | |
1471 } | |
1472 | |
358 | 1473 #if defined(EXITFREE) || defined(PROTO) |
1474 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1475 close_all_scripts(void) |
358 | 1476 { |
1477 while (scriptin[0] != NULL) | |
1478 closescript(); | |
1479 } | |
1480 #endif | |
1481 | |
7 | 1482 #if defined(FEAT_INS_EXPAND) || defined(PROTO) |
1483 /* | |
1484 * Return TRUE when reading keys from a script file. | |
1485 */ | |
1486 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1487 using_script(void) |
7 | 1488 { |
1489 return scriptin[curscript] != NULL; | |
1490 } | |
1491 #endif | |
1492 | |
1493 /* | |
365 | 1494 * This function is called just before doing a blocking wait. Thus after |
1495 * waiting 'updatetime' for a character to arrive. | |
1496 */ | |
1497 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1498 before_blocking(void) |
365 | 1499 { |
1500 updatescript(0); | |
1501 #ifdef FEAT_EVAL | |
958 | 1502 if (may_garbage_collect) |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
1503 garbage_collect(FALSE); |
365 | 1504 #endif |
1505 } | |
1506 | |
1507 /* | |
7 | 1508 * updatescipt() is called when a character can be written into the script file |
1509 * or when we have waited some time for a character (c == 0) | |
1510 * | |
1511 * All the changed memfiles are synced if c == 0 or when the number of typed | |
1512 * characters reaches 'updatecount' and 'updatecount' is non-zero. | |
1513 */ | |
1514 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1515 updatescript(int c) |
7 | 1516 { |
1517 static int count = 0; | |
1518 | |
1519 if (c && scriptout) | |
1520 putc(c, scriptout); | |
1521 if (c == 0 || (p_uc > 0 && ++count >= p_uc)) | |
1522 { | |
1523 ml_sync_all(c == 0, TRUE); | |
1524 count = 0; | |
1525 } | |
1526 } | |
1527 | |
1528 /* | |
1529 * Get the next input character. | |
1530 * Can return a special key or a multi-byte character. | |
1531 * Can return NUL when called recursively, use safe_vgetc() if that's not | |
1532 * wanted. | |
1533 * This translates escaped K_SPECIAL and CSI bytes to a K_SPECIAL or CSI byte. | |
1534 * Collects the bytes of a multibyte character into the whole character. | |
1992 | 1535 * Returns the modifiers in the global "mod_mask". |
7 | 1536 */ |
1537 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1538 vgetc(void) |
7 | 1539 { |
1540 int c, c2; | |
1541 int n; | |
3549 | 1542 char_u buf[MB_MAXBYTES + 1]; |
7 | 1543 int i; |
1544 | |
958 | 1545 #ifdef FEAT_EVAL |
1546 /* Do garbage collection when garbagecollect() was called previously and | |
1547 * we are now at the toplevel. */ | |
1548 if (may_garbage_collect && want_garbage_collect) | |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
1549 garbage_collect(FALSE); |
958 | 1550 #endif |
1551 | |
7 | 1552 /* |
1553 * If a character was put back with vungetc, it was already processed. | |
1554 * Return it directly. | |
1555 */ | |
1556 if (old_char != -1) | |
1557 { | |
1558 c = old_char; | |
1559 old_char = -1; | |
1560 mod_mask = old_mod_mask; | |
4227 | 1561 #ifdef FEAT_MOUSE |
1562 mouse_row = old_mouse_row; | |
1563 mouse_col = old_mouse_col; | |
1564 #endif | |
7 | 1565 } |
958 | 1566 else |
7 | 1567 { |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1568 mod_mask = 0x0; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1569 last_recorded_len = 0; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1570 for (;;) // this is done twice if there are modifiers |
7 | 1571 { |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1572 int did_inc = FALSE; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1573 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1574 if (mod_mask |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1575 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1576 || im_is_preediting() |
7 | 1577 #endif |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1578 ) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1579 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1580 // no mapping after modifier has been read |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1581 ++no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1582 ++allow_keys; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1583 did_inc = TRUE; // mod_mask may change value |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1584 } |
7 | 1585 c = vgetorpeek(TRUE); |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1586 if (did_inc) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1587 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1588 --no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1589 --allow_keys; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1590 } |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1591 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1592 // Get two extra bytes for special keys |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1593 if (c == K_SPECIAL |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1594 #ifdef FEAT_GUI |
16470
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1595 || (gui.in_use && c == CSI) |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1596 #endif |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1597 ) |
7 | 1598 { |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1599 int save_allow_keys = allow_keys; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1600 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1601 ++no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1602 allow_keys = 0; // make sure BS is not found |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1603 c2 = vgetorpeek(TRUE); // no mapping for these chars |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1604 c = vgetorpeek(TRUE); |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1605 --no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1606 allow_keys = save_allow_keys; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1607 if (c2 == KS_MODIFIER) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1608 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1609 mod_mask = c; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1610 continue; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1611 } |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1612 c = TO_SPECIAL(c2, c); |
7 | 1613 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1614 #if defined(FEAT_GUI_MSWIN) && defined(FEAT_MENU) && defined(FEAT_TEAROFF) |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1615 // Handle K_TEAROFF here, the caller of vgetc() doesn't need to |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1616 // know that a menu was torn off |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
1617 if ( |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
1618 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
1619 gui.in_use && |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
1620 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
1621 c == K_TEAROFF) |
7 | 1622 { |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1623 char_u name[200]; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1624 int i; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1625 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1626 // get menu path, it ends with a <CR> |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1627 for (i = 0; (c = vgetorpeek(TRUE)) != '\r'; ) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1628 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1629 name[i] = c; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1630 if (i < 199) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1631 ++i; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1632 } |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1633 name[i] = NUL; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1634 gui_make_tearoff(name); |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1635 continue; |
7 | 1636 } |
1637 #endif | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1638 #if defined(FEAT_GUI) && defined(FEAT_GUI_GTK) && defined(FEAT_MENU) |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1639 // GTK: <F10> normally selects the menu, but it's passed until |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1640 // here to allow mapping it. Intercept and invoke the GTK |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1641 // behavior if it's not mapped. |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1642 if (c == K_F10 && gui.menubar != NULL) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1643 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1644 gtk_menu_shell_select_first( |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1645 GTK_MENU_SHELL(gui.menubar), FALSE); |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1646 continue; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1647 } |
36 | 1648 #endif |
7 | 1649 #ifdef FEAT_GUI |
16470
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1650 if (gui.in_use) |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1651 { |
16470
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1652 // Handle focus event here, so that the caller doesn't |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1653 // need to know about it. Return K_IGNORE so that we loop |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1654 // once (needed if 'lazyredraw' is set). |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1655 if (c == K_FOCUSGAINED || c == K_FOCUSLOST) |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1656 { |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1657 ui_focus_change(c == K_FOCUSGAINED); |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1658 c = K_IGNORE; |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1659 } |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1660 |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1661 // Translate K_CSI to CSI. The special key is only used |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1662 // to avoid it being recognized as the start of a special |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1663 // key. |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1664 if (c == K_CSI) |
d8ade1c5f823
patch 8.1.1239: key with byte sequence containing CSI does not work
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
1665 c = CSI; |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1666 } |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1667 #endif |
1380 | 1668 } |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1669 // a keypad or special function key was not mapped, use it like |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1670 // its ASCII equivalent |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1671 switch (c) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1672 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1673 case K_KPLUS: c = '+'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1674 case K_KMINUS: c = '-'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1675 case K_KDIVIDE: c = '/'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1676 case K_KMULTIPLY: c = '*'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1677 case K_KENTER: c = CAR; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1678 case K_KPOINT: |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1679 #ifdef MSWIN |
14403
e29cbac5e8f6
patch 8.1.0216: part of file not indented properly
Christian Brabandt <cb@256bit.org>
parents:
14247
diff
changeset
|
1680 // Can be either '.' or a ',', |
e29cbac5e8f6
patch 8.1.0216: part of file not indented properly
Christian Brabandt <cb@256bit.org>
parents:
14247
diff
changeset
|
1681 // depending on the type of keypad. |
e29cbac5e8f6
patch 8.1.0216: part of file not indented properly
Christian Brabandt <cb@256bit.org>
parents:
14247
diff
changeset
|
1682 c = MapVirtualKey(VK_DECIMAL, 2); break; |
36 | 1683 #else |
14403
e29cbac5e8f6
patch 8.1.0216: part of file not indented properly
Christian Brabandt <cb@256bit.org>
parents:
14247
diff
changeset
|
1684 c = '.'; break; |
36 | 1685 #endif |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1686 case K_K0: c = '0'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1687 case K_K1: c = '1'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1688 case K_K2: c = '2'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1689 case K_K3: c = '3'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1690 case K_K4: c = '4'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1691 case K_K5: c = '5'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1692 case K_K6: c = '6'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1693 case K_K7: c = '7'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1694 case K_K8: c = '8'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1695 case K_K9: c = '9'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1696 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1697 case K_XHOME: |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1698 case K_ZHOME: if (mod_mask == MOD_MASK_SHIFT) |
229 | 1699 { |
1700 c = K_S_HOME; | |
1701 mod_mask = 0; | |
1702 } | |
1703 else if (mod_mask == MOD_MASK_CTRL) | |
1704 { | |
1705 c = K_C_HOME; | |
1706 mod_mask = 0; | |
1707 } | |
1708 else | |
1709 c = K_HOME; | |
1710 break; | |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1711 case K_XEND: |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1712 case K_ZEND: if (mod_mask == MOD_MASK_SHIFT) |
229 | 1713 { |
1714 c = K_S_END; | |
1715 mod_mask = 0; | |
1716 } | |
1717 else if (mod_mask == MOD_MASK_CTRL) | |
1718 { | |
1719 c = K_C_END; | |
1720 mod_mask = 0; | |
1721 } | |
1722 else | |
1723 c = K_END; | |
1724 break; | |
1725 | |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1726 case K_XUP: c = K_UP; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1727 case K_XDOWN: c = K_DOWN; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1728 case K_XLEFT: c = K_LEFT; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1729 case K_XRIGHT: c = K_RIGHT; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1730 } |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1731 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1732 // For a multi-byte character get all the bytes and return the |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1733 // converted character. |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1734 // Note: This will loop until enough bytes are received! |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1735 if (has_mbyte && (n = MB_BYTE2LEN_CHECK(c)) > 1) |
7 | 1736 { |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1737 ++no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1738 buf[0] = c; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1739 for (i = 1; i < n; ++i) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1740 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1741 buf[i] = vgetorpeek(TRUE); |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1742 if (buf[i] == K_SPECIAL |
7 | 1743 #ifdef FEAT_GUI |
16712
329e28ed10fd
patch 8.1.1358: cannot enter character with a CSI byte
Bram Moolenaar <Bram@vim.org>
parents:
16531
diff
changeset
|
1744 || ( |
329e28ed10fd
patch 8.1.1358: cannot enter character with a CSI byte
Bram Moolenaar <Bram@vim.org>
parents:
16531
diff
changeset
|
1745 # ifdef VIMDLL |
329e28ed10fd
patch 8.1.1358: cannot enter character with a CSI byte
Bram Moolenaar <Bram@vim.org>
parents:
16531
diff
changeset
|
1746 gui.in_use && |
329e28ed10fd
patch 8.1.1358: cannot enter character with a CSI byte
Bram Moolenaar <Bram@vim.org>
parents:
16531
diff
changeset
|
1747 # endif |
329e28ed10fd
patch 8.1.1358: cannot enter character with a CSI byte
Bram Moolenaar <Bram@vim.org>
parents:
16531
diff
changeset
|
1748 buf[i] == CSI) |
7 | 1749 #endif |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1750 ) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1751 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1752 // Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1753 // sequence, which represents a K_SPECIAL (0x80), |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1754 // or a CSI - KS_EXTRA - KE_CSI sequence, which |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1755 // represents a CSI (0x9B), |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1756 // or a K_SPECIAL - KS_EXTRA - KE_CSI, which is CSI |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1757 // too. |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1758 c = vgetorpeek(TRUE); |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1759 if (vgetorpeek(TRUE) == (int)KE_CSI && c == KS_EXTRA) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1760 buf[i] = CSI; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1761 } |
7 | 1762 } |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1763 --no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1764 c = (*mb_ptr2char)(buf); |
7 | 1765 } |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1766 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1767 break; |
7 | 1768 } |
1769 } | |
958 | 1770 |
1771 #ifdef FEAT_EVAL | |
1772 /* | |
1773 * In the main loop "may_garbage_collect" can be set to do garbage | |
1774 * collection in the first next vgetc(). It's disabled after that to | |
1775 * avoid internally used Lists and Dicts to be freed. | |
1776 */ | |
1777 may_garbage_collect = FALSE; | |
1778 #endif | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
1779 #ifdef FEAT_BEVAL_TERM |
17282
6f1679e1082d
patch 8.1.1640: the CursorHold autocommand takes down a balloon
Bram Moolenaar <Bram@vim.org>
parents:
17184
diff
changeset
|
1780 if (c != K_MOUSEMOVE && c != K_IGNORE && c != K_CURSORHOLD) |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1781 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1782 /* Don't trigger 'balloonexpr' unless only the mouse was moved. */ |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1783 bevalexpr_due_set = FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1784 ui_remove_balloon(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1785 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1786 #endif |
16880
998603a243d7
patch 8.1.1441: popup window filter not yet implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1787 #ifdef FEAT_TEXT_PROP |
998603a243d7
patch 8.1.1441: popup window filter not yet implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1788 if (popup_do_filter(c)) |
998603a243d7
patch 8.1.1441: popup window filter not yet implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1789 c = K_IGNORE; |
998603a243d7
patch 8.1.1441: popup window filter not yet implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1790 #endif |
958 | 1791 |
1792 return c; | |
7 | 1793 } |
1794 | |
1795 /* | |
1796 * Like vgetc(), but never return a NUL when called recursively, get a key | |
1797 * directly from the user (ignoring typeahead). | |
1798 */ | |
1799 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1800 safe_vgetc(void) |
7 | 1801 { |
1802 int c; | |
1803 | |
1804 c = vgetc(); | |
1805 if (c == NUL) | |
1806 c = get_keystroke(); | |
1807 return c; | |
1808 } | |
1809 | |
1810 /* | |
1389 | 1811 * Like safe_vgetc(), but loop to handle K_IGNORE. |
1812 * Also ignore scrollbar events. | |
1813 */ | |
1814 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1815 plain_vgetc(void) |
1389 | 1816 { |
1817 int c; | |
1818 | |
1819 do | |
1820 c = safe_vgetc(); | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15995
diff
changeset
|
1821 while (c == K_IGNORE || c == K_VER_SCROLLBAR || c == K_HOR_SCROLLBAR); |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
1822 |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
1823 if (c == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
1824 /* Only handle the first pasted character. Drop the rest, since we |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
1825 * don't know what to do with it. */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
1826 c = bracketed_paste(PASTE_ONE_CHAR, FALSE, NULL); |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
1827 |
1389 | 1828 return c; |
1829 } | |
1830 | |
1831 /* | |
7 | 1832 * Check if a character is available, such that vgetc() will not block. |
1833 * If the next character is a special character or multi-byte, the returned | |
1834 * character is not valid!. | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1835 * Returns NUL if no character is available. |
7 | 1836 */ |
1837 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1838 vpeekc(void) |
7 | 1839 { |
1840 if (old_char != -1) | |
1841 return old_char; | |
1842 return vgetorpeek(FALSE); | |
1843 } | |
1844 | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
1845 #if defined(FEAT_TERMRESPONSE) || defined(FEAT_TERMINAL) || defined(PROTO) |
7 | 1846 /* |
1847 * Like vpeekc(), but don't allow mapping. Do allow checking for terminal | |
1848 * codes. | |
1849 */ | |
1850 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1851 vpeekc_nomap(void) |
7 | 1852 { |
1853 int c; | |
1854 | |
1855 ++no_mapping; | |
1856 ++allow_keys; | |
1857 c = vpeekc(); | |
1858 --no_mapping; | |
1859 --allow_keys; | |
1860 return c; | |
1861 } | |
1862 #endif | |
1863 | |
5930 | 1864 #if defined(FEAT_INS_EXPAND) || defined(FEAT_EVAL) || defined(PROTO) |
7 | 1865 /* |
1866 * Check if any character is available, also half an escape sequence. | |
1867 * Trick: when no typeahead found, but there is something in the typeahead | |
1868 * buffer, it must be an ESC that is recognized as the start of a key code. | |
1869 */ | |
1870 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1871 vpeekc_any(void) |
7 | 1872 { |
1873 int c; | |
1874 | |
1875 c = vpeekc(); | |
1876 if (c == NUL && typebuf.tb_len > 0) | |
1877 c = ESC; | |
1878 return c; | |
1879 } | |
1880 #endif | |
1881 | |
1882 /* | |
1883 * Call vpeekc() without causing anything to be mapped. | |
1884 * Return TRUE if a character is available, FALSE otherwise. | |
1885 */ | |
1886 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1887 char_avail(void) |
7 | 1888 { |
1889 int retval; | |
1890 | |
8011
26f555e9aab1
commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents:
7860
diff
changeset
|
1891 #ifdef FEAT_EVAL |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1892 /* When test_override("char_avail", 1) was called pretend there is no |
8011
26f555e9aab1
commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents:
7860
diff
changeset
|
1893 * typeahead. */ |
26f555e9aab1
commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents:
7860
diff
changeset
|
1894 if (disable_char_avail_for_testing) |
26f555e9aab1
commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents:
7860
diff
changeset
|
1895 return FALSE; |
26f555e9aab1
commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents:
7860
diff
changeset
|
1896 #endif |
7 | 1897 ++no_mapping; |
1898 retval = vpeekc(); | |
1899 --no_mapping; | |
1900 return (retval != NUL); | |
1901 } | |
1902 | |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1903 typedef enum { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1904 map_result_fail, // failed, break loop |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1905 map_result_get, // get a character from typeahead |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1906 map_result_retry, // try to map again |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1907 map_result_nomatch // no matching mapping, get char |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1908 } map_result_T; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1909 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1910 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1911 * Handle mappings in the typeahead buffer. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1912 * - When something was mapped, return map_result_retry for recursive mappings. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1913 * - When nothing mapped and typeahead has a character return map_result_get. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1914 * - When there is no match yet, return map_result_nomatch, need to get more |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1915 * typeahead. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1916 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1917 static int |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1918 handle_mapping( |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1919 int *keylenp, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1920 int *timedout, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1921 int *mapdepth) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1922 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1923 mapblock_T *mp = NULL; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1924 mapblock_T *mp2; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1925 mapblock_T *mp_match; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1926 int mp_match_len = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1927 int max_mlen = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1928 int tb_c1; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1929 int mlen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1930 #ifdef FEAT_LANGMAP |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1931 int nolmaplen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1932 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1933 int keylen = *keylenp; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1934 int i; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1935 int local_State = get_real_state(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1936 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1937 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1938 * Check for a mappable key sequence. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1939 * Walk through one maphash[] list until we find an |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1940 * entry that matches. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1941 * |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1942 * Don't look for mappings if: |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1943 * - no_mapping set: mapping disabled (e.g. for CTRL-V) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1944 * - maphash_valid not set: no mappings present. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1945 * - typebuf.tb_buf[typebuf.tb_off] should not be remapped |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1946 * - in insert or cmdline mode and 'paste' option set |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1947 * - waiting for "hit return to continue" and CR or SPACE |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1948 * typed |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1949 * - waiting for a char with --more-- |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1950 * - in Ctrl-X mode, and we get a valid char for that mode |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1951 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1952 tb_c1 = typebuf.tb_buf[typebuf.tb_off]; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1953 if (no_mapping == 0 && is_maphash_valid() |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1954 && (no_zero_mapping == 0 || tb_c1 != '0') |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1955 && (typebuf.tb_maplen == 0 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1956 || (p_remap |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1957 && (typebuf.tb_noremap[typebuf.tb_off] |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1958 & (RM_NONE|RM_ABBR)) == 0)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1959 && !(p_paste && (State & (INSERT + CMDLINE))) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1960 && !(State == HITRETURN && (tb_c1 == CAR || tb_c1 == ' ')) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1961 && State != ASKMORE |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1962 && State != CONFIRM |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1963 #ifdef FEAT_INS_EXPAND |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1964 && !((ctrl_x_mode_not_default() |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1965 && vim_is_ctrl_x_key(tb_c1)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1966 || ((compl_cont_status & CONT_LOCAL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1967 && (tb_c1 == Ctrl_N || tb_c1 == Ctrl_P))) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1968 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1969 ) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1970 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1971 #ifdef FEAT_LANGMAP |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1972 if (tb_c1 == K_SPECIAL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1973 nolmaplen = 2; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1974 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1975 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1976 LANGMAP_ADJUST(tb_c1, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1977 (State & (CMDLINE | INSERT)) == 0 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1978 && get_real_state() != SELECTMODE); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1979 nolmaplen = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1980 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1981 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1982 // First try buffer-local mappings. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1983 mp = get_buf_maphash_list(local_State, tb_c1); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1984 mp2 = get_maphash_list(local_State, tb_c1); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1985 if (mp == NULL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1986 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1987 // There are no buffer-local mappings. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1988 mp = mp2; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1989 mp2 = NULL; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1990 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1991 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1992 * Loop until a partly matching mapping is found or |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1993 * all (local) mappings have been checked. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1994 * The longest full match is remembered in "mp_match". |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1995 * A full match is only accepted if there is no partly |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1996 * match, so "aa" and "aaa" can both be mapped. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1997 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1998 mp_match = NULL; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
1999 mp_match_len = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2000 for ( ; mp != NULL; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2001 mp->m_next == NULL ? (mp = mp2, mp2 = NULL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2002 : (mp = mp->m_next)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2003 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2004 // Only consider an entry if the first character |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2005 // matches and it is for the current state. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2006 // Skip ":lmap" mappings if keys were mapped. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2007 if (mp->m_keys[0] == tb_c1 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2008 && (mp->m_mode & local_State) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2009 && ((mp->m_mode & LANGMAP) == 0 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2010 || typebuf.tb_maplen == 0)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2011 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2012 #ifdef FEAT_LANGMAP |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2013 int nomap = nolmaplen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2014 int c2; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2015 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2016 // find the match length of this mapping |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2017 for (mlen = 1; mlen < typebuf.tb_len; ++mlen) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2018 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2019 #ifdef FEAT_LANGMAP |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2020 c2 = typebuf.tb_buf[typebuf.tb_off + mlen]; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2021 if (nomap > 0) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2022 --nomap; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2023 else if (c2 == K_SPECIAL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2024 nomap = 2; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2025 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2026 LANGMAP_ADJUST(c2, TRUE); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2027 if (mp->m_keys[mlen] != c2) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2028 #else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2029 if (mp->m_keys[mlen] != |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2030 typebuf.tb_buf[typebuf.tb_off + mlen]) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2031 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2032 break; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2033 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2034 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2035 // Don't allow mapping the first byte(s) of a |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2036 // multi-byte char. Happens when mapping |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2037 // <M-a> and then changing 'encoding'. Beware |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2038 // that 0x80 is escaped. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2039 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2040 char_u *p1 = mp->m_keys; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2041 char_u *p2 = mb_unescape(&p1); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2042 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2043 if (has_mbyte && p2 != NULL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2044 && MB_BYTE2LEN(tb_c1) > MB_PTR2LEN(p2)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2045 mlen = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2046 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2047 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2048 // Check an entry whether it matches. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2049 // - Full match: mlen == keylen |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2050 // - Partly match: mlen == typebuf.tb_len |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2051 keylen = mp->m_keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2052 if (mlen == keylen |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2053 || (mlen == typebuf.tb_len |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2054 && typebuf.tb_len < keylen)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2055 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2056 char_u *s; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2057 int n; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2058 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2059 // If only script-local mappings are |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2060 // allowed, check if the mapping starts |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2061 // with K_SNR. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2062 s = typebuf.tb_noremap + typebuf.tb_off; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2063 if (*s == RM_SCRIPT |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2064 && (mp->m_keys[0] != K_SPECIAL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2065 || mp->m_keys[1] != KS_EXTRA |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2066 || mp->m_keys[2] |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2067 != (int)KE_SNR)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2068 continue; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2069 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2070 // If one of the typed keys cannot be |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2071 // remapped, skip the entry. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2072 for (n = mlen; --n >= 0; ) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2073 if (*s++ & (RM_NONE|RM_ABBR)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2074 break; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2075 if (n >= 0) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2076 continue; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2077 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2078 if (keylen > typebuf.tb_len) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2079 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2080 if (!*timedout && !(mp_match != NULL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2081 && mp_match->m_nowait)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2082 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2083 // break at a partly match |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2084 keylen = KEYLEN_PART_MAP; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2085 break; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2086 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2087 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2088 else if (keylen > mp_match_len) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2089 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2090 // found a longer match |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2091 mp_match = mp; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2092 mp_match_len = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2093 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2094 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2095 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2096 // No match; may have to check for |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2097 // termcode at next character. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2098 if (max_mlen < mlen) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2099 max_mlen = mlen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2100 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2101 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2102 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2103 // If no partly match found, use the longest full |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2104 // match. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2105 if (keylen != KEYLEN_PART_MAP) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2106 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2107 mp = mp_match; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2108 keylen = mp_match_len; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2109 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2110 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2111 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2112 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2113 * Check for match with 'pastetoggle' |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2114 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2115 if (*p_pt != NUL && mp == NULL && (State & (INSERT|NORMAL))) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2116 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2117 for (mlen = 0; mlen < typebuf.tb_len && p_pt[mlen]; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2118 ++mlen) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2119 if (p_pt[mlen] != typebuf.tb_buf[typebuf.tb_off |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2120 + mlen]) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2121 break; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2122 if (p_pt[mlen] == NUL) // match |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2123 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2124 // write chars to script file(s) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2125 if (mlen > typebuf.tb_maplen) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2126 gotchars(typebuf.tb_buf + typebuf.tb_off |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2127 + typebuf.tb_maplen, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2128 mlen - typebuf.tb_maplen); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2129 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2130 del_typebuf(mlen, 0); // remove the chars |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2131 set_option_value((char_u *)"paste", |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2132 (long)!p_paste, NULL, 0); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2133 if (!(State & INSERT)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2134 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2135 msg_col = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2136 msg_row = Rows - 1; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2137 msg_clr_eos(); // clear ruler |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2138 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2139 status_redraw_all(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2140 redraw_statuslines(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2141 showmode(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2142 setcursor(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2143 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2144 return map_result_retry; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2145 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2146 // Need more chars for partly match. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2147 if (mlen == typebuf.tb_len) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2148 keylen = KEYLEN_PART_KEY; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2149 else if (max_mlen < mlen) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2150 // no match, may have to check for termcode at |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2151 // next character |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2152 max_mlen = mlen + 1; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2153 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2154 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2155 if ((mp == NULL || max_mlen >= mp_match_len) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2156 && keylen != KEYLEN_PART_MAP) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2157 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2158 int save_keylen = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2159 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2160 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2161 * When no matching mapping found or found a |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2162 * non-matching mapping that matches at least what the |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2163 * matching mapping matched: |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2164 * Check if we have a terminal code, when: |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2165 * mapping is allowed, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2166 * keys have not been mapped, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2167 * and not an ESC sequence, not in insert mode or |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2168 * p_ek is on, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2169 * and when not timed out, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2170 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2171 if ((no_mapping == 0 || allow_keys != 0) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2172 && (typebuf.tb_maplen == 0 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2173 || (p_remap && typebuf.tb_noremap[ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2174 typebuf.tb_off] == RM_YES)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2175 && !*timedout) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2176 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2177 keylen = check_termcode(max_mlen + 1, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2178 NULL, 0, NULL); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2179 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2180 // If no termcode matched but 'pastetoggle' |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2181 // matched partially it's like an incomplete key |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2182 // sequence. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2183 if (keylen == 0 && save_keylen == KEYLEN_PART_KEY) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2184 keylen = KEYLEN_PART_KEY; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2185 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2186 // When getting a partial match, but the last |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2187 // characters were not typed, don't wait for a |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2188 // typed character to complete the termcode. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2189 // This helps a lot when a ":normal" command ends |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2190 // in an ESC. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2191 if (keylen < 0 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2192 && typebuf.tb_len == typebuf.tb_maplen) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2193 keylen = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2194 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2195 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2196 keylen = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2197 if (keylen == 0) // no matching terminal code |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2198 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2199 #ifdef AMIGA // check for window bounds report |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2200 if (typebuf.tb_maplen == 0 && (typebuf.tb_buf[ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2201 typebuf.tb_off] & 0xff) == CSI) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2202 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2203 char_u *s; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2204 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2205 for (s = typebuf.tb_buf + typebuf.tb_off + 1; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2206 s < typebuf.tb_buf + typebuf.tb_off |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2207 + typebuf.tb_len |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2208 && (VIM_ISDIGIT(*s) || *s == ';' |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2209 || *s == ' '); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2210 ++s) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2211 ; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2212 if (*s == 'r' || *s == '|') // found one |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2213 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2214 del_typebuf((int)(s + 1 - |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2215 (typebuf.tb_buf + typebuf.tb_off)), 0); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2216 // get size and redraw screen |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2217 shell_resized(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2218 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2219 return map_result_retry; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2220 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2221 if (*s == NUL) // need more characters |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2222 keylen = KEYLEN_PART_KEY; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2223 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2224 if (keylen >= 0) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2225 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2226 // When there was a matching mapping and no |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2227 // termcode could be replaced after another one, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2228 // use that mapping (loop around). If there was |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2229 // no mapping at all use the character from the |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2230 // typeahead buffer right here. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2231 if (mp == NULL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2232 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2233 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2234 return map_result_get; // got character, break for loop |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2235 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2236 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2237 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2238 if (keylen > 0) // full matching terminal code |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2239 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2240 #if defined(FEAT_GUI) && defined(FEAT_MENU) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2241 if (typebuf.tb_len >= 2 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2242 && typebuf.tb_buf[typebuf.tb_off] == K_SPECIAL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2243 && typebuf.tb_buf[typebuf.tb_off + 1] |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2244 == KS_MENU) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2245 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2246 int idx; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2247 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2248 // Using a menu may cause a break in undo! |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2249 // It's like using gotchars(), but without |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2250 // recording or writing to a script file. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2251 may_sync_undo(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2252 del_typebuf(3, 0); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2253 idx = get_menu_index(current_menu, local_State); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2254 if (idx != MENU_INDEX_INVALID) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2255 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2256 // In Select mode and a Visual mode menu |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2257 // is used: Switch to Visual mode |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2258 // temporarily. Append K_SELECT to switch |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2259 // back to Select mode. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2260 if (VIsual_active && VIsual_select |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2261 && (current_menu->modes & VISUAL)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2262 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2263 VIsual_select = FALSE; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2264 (void)ins_typebuf(K_SELECT_STRING, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2265 REMAP_NONE, 0, TRUE, FALSE); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2266 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2267 ins_typebuf(current_menu->strings[idx], |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2268 current_menu->noremap[idx], |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2269 0, TRUE, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2270 current_menu->silent[idx]); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2271 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2272 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2273 #endif // FEAT_GUI && FEAT_MENU |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2274 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2275 return map_result_retry; // try mapping again |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2276 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2277 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2278 // Partial match: get some more characters. When a |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2279 // matching mapping was found use that one. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2280 if (mp == NULL || keylen < 0) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2281 keylen = KEYLEN_PART_KEY; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2282 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2283 keylen = mp_match_len; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2284 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2285 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2286 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2287 * complete match |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2288 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2289 if (keylen >= 0 && keylen <= typebuf.tb_len) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2290 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2291 char_u *map_str; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2292 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2293 #ifdef FEAT_EVAL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2294 int save_m_expr; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2295 int save_m_noremap; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2296 int save_m_silent; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2297 char_u *save_m_keys; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2298 char_u *save_m_str; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2299 #else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2300 # define save_m_noremap mp->m_noremap |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2301 # define save_m_silent mp->m_silent |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2302 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2303 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2304 // write chars to script file(s) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2305 if (keylen > typebuf.tb_maplen) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2306 gotchars(typebuf.tb_buf + typebuf.tb_off |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2307 + typebuf.tb_maplen, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2308 keylen - typebuf.tb_maplen); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2309 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2310 cmd_silent = (typebuf.tb_silent > 0); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2311 del_typebuf(keylen, 0); // remove the mapped keys |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2312 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2313 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2314 * Put the replacement string in front of mapstr. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2315 * The depth check catches ":map x y" and ":map y x". |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2316 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2317 if (++*mapdepth >= p_mmd) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2318 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2319 emsg(_("E223: recursive mapping")); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2320 if (State & CMDLINE) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2321 redrawcmdline(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2322 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2323 setcursor(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2324 flush_buffers(FLUSH_MINIMAL); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2325 *mapdepth = 0; /* for next one */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2326 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2327 return map_result_fail; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2328 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2329 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2330 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2331 * In Select mode and a Visual mode mapping is used: |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2332 * Switch to Visual mode temporarily. Append K_SELECT |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2333 * to switch back to Select mode. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2334 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2335 if (VIsual_active && VIsual_select |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2336 && (mp->m_mode & VISUAL)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2337 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2338 VIsual_select = FALSE; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2339 (void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2340 0, TRUE, FALSE); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2341 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2342 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2343 #ifdef FEAT_EVAL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2344 // Copy the values from *mp that are used, because |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2345 // evaluating the expression may invoke a function |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2346 // that redefines the mapping, thereby making *mp |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2347 // invalid. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2348 save_m_expr = mp->m_expr; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2349 save_m_noremap = mp->m_noremap; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2350 save_m_silent = mp->m_silent; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2351 save_m_keys = NULL; // only saved when needed |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2352 save_m_str = NULL; // only saved when needed |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2353 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2354 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2355 * Handle ":map <expr>": evaluate the {rhs} as an |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2356 * expression. Also save and restore the command line |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2357 * for "normal :". |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2358 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2359 if (mp->m_expr) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2360 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2361 int save_vgetc_busy = vgetc_busy; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2362 int save_may_garbage_collect = may_garbage_collect; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2363 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2364 vgetc_busy = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2365 may_garbage_collect = FALSE; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2366 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2367 save_m_keys = vim_strsave(mp->m_keys); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2368 save_m_str = vim_strsave(mp->m_str); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2369 map_str = eval_map_expr(save_m_str, NUL); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2370 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2371 vgetc_busy = save_vgetc_busy; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2372 may_garbage_collect = save_may_garbage_collect; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2373 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2374 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2375 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2376 map_str = mp->m_str; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2377 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2378 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2379 * Insert the 'to' part in the typebuf.tb_buf. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2380 * If 'from' field is the same as the start of the |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2381 * 'to' field, don't remap the first character (but do |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2382 * allow abbreviations). |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2383 * If m_noremap is set, don't remap the whole 'to' |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2384 * part. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2385 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2386 if (map_str == NULL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2387 i = FAIL; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2388 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2389 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2390 int noremap; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2391 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2392 if (save_m_noremap != REMAP_YES) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2393 noremap = save_m_noremap; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2394 else if ( |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2395 #ifdef FEAT_EVAL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2396 STRNCMP(map_str, save_m_keys != NULL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2397 ? save_m_keys : mp->m_keys, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2398 (size_t)keylen) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2399 #else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2400 STRNCMP(map_str, mp->m_keys, (size_t)keylen) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2401 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2402 != 0) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2403 noremap = REMAP_YES; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2404 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2405 noremap = REMAP_SKIP; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2406 i = ins_typebuf(map_str, noremap, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2407 0, TRUE, cmd_silent || save_m_silent); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2408 #ifdef FEAT_EVAL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2409 if (save_m_expr) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2410 vim_free(map_str); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2411 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2412 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2413 #ifdef FEAT_EVAL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2414 vim_free(save_m_keys); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2415 vim_free(save_m_str); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2416 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2417 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2418 if (i == FAIL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2419 return map_result_fail; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2420 return map_result_retry; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2421 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2422 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2423 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2424 return map_result_nomatch; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2425 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2426 |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2427 /* |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2428 * unget one character (can only be done once!) |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2429 */ |
7 | 2430 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2431 vungetc(int c) |
7 | 2432 { |
2433 old_char = c; | |
2434 old_mod_mask = mod_mask; | |
4227 | 2435 #ifdef FEAT_MOUSE |
2436 old_mouse_row = mouse_row; | |
2437 old_mouse_col = mouse_col; | |
2438 #endif | |
7 | 2439 } |
2440 | |
2441 /* | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
2442 * Get a byte: |
7 | 2443 * 1. from the stuffbuffer |
2444 * This is used for abbreviated commands like "D" -> "d$". | |
2445 * Also used to redo a command for ".". | |
2446 * 2. from the typeahead buffer | |
2447 * Stores text obtained previously but not used yet. | |
2448 * Also stores the result of mappings. | |
2449 * Also used for the ":normal" command. | |
2450 * 3. from the user | |
2451 * This may do a blocking wait if "advance" is TRUE. | |
2452 * | |
2453 * if "advance" is TRUE (vgetc()): | |
9980
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
2454 * Really get the character. |
7 | 2455 * KeyTyped is set to TRUE in the case the user typed the key. |
2456 * KeyStuffed is TRUE if the character comes from the stuff buffer. | |
2457 * if "advance" is FALSE (vpeekc()): | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2458 * Just look whether there is a character available. |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2459 * Return NUL if not. |
7 | 2460 * |
2461 * When "no_mapping" is zero, checks for mappings in the current mode. | |
2462 * Only returns one byte (of a multi-byte character). | |
2463 * K_SPECIAL and CSI may be escaped, need to get two more bytes then. | |
2464 */ | |
2465 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2466 vgetorpeek(int advance) |
7 | 2467 { |
2468 int c, c1; | |
2469 int timedout = FALSE; /* waited for more than 1 second | |
2470 for mapping to complete */ | |
2471 int mapdepth = 0; /* check for recursive mapping */ | |
2472 int mode_deleted = FALSE; /* set when mode has been deleted */ | |
721 | 2473 int i; |
7 | 2474 #ifdef FEAT_CMDL_INFO |
2475 int new_wcol, new_wrow; | |
2476 #endif | |
2477 #ifdef FEAT_GUI | |
2478 int shape_changed = FALSE; /* adjusted cursor shape */ | |
2479 #endif | |
2480 int n; | |
2481 int old_wcol, old_wrow; | |
202 | 2482 int wait_tb_len; |
7 | 2483 |
2484 /* | |
2485 * This function doesn't work very well when called recursively. This may | |
2486 * happen though, because of: | |
2487 * 1. The call to add_to_showcmd(). char_avail() is then used to check if | |
2488 * there is a character available, which calls this function. In that | |
2489 * case we must return NUL, to indicate no character is available. | |
2490 * 2. A GUI callback function writes to the screen, causing a | |
2491 * wait_return(). | |
2492 * Using ":normal" can also do this, but it saves the typeahead buffer, | |
2493 * thus it should be OK. But don't get a key from the user then. | |
2494 */ | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
2495 if (vgetc_busy > 0 && ex_normal_busy == 0) |
7 | 2496 return NUL; |
2497 | |
822 | 2498 ++vgetc_busy; |
7 | 2499 |
2500 if (advance) | |
2501 KeyStuffed = FALSE; | |
2502 | |
2503 init_typebuf(); | |
2504 start_stuff(); | |
2505 if (advance && typebuf.tb_maplen == 0) | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
2506 reg_executing = 0; |
7 | 2507 do |
2508 { | |
2509 /* | |
2510 * get a character: 1. from the stuffbuffer | |
2511 */ | |
2512 if (typeahead_char != 0) | |
2513 { | |
2514 c = typeahead_char; | |
2515 if (advance) | |
2516 typeahead_char = 0; | |
2517 } | |
2518 else | |
5649 | 2519 c = read_readbuffers(advance); |
7 | 2520 if (c != NUL && !got_int) |
2521 { | |
2522 if (advance) | |
2523 { | |
2524 /* KeyTyped = FALSE; When the command that stuffed something | |
2525 * was typed, behave like the stuffed command was typed. | |
10549
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
2526 * needed for CTRL-W CTRL-] to open a fold, for example. */ |
7 | 2527 KeyStuffed = TRUE; |
2528 } | |
2529 if (typebuf.tb_no_abbr_cnt == 0) | |
2530 typebuf.tb_no_abbr_cnt = 1; /* no abbreviations now */ | |
2531 } | |
2532 else | |
2533 { | |
2534 /* | |
2535 * Loop until we either find a matching mapped key, or we | |
2536 * are sure that it is not a mapped key. | |
2537 * If a mapped key sequence is found we go back to the start to | |
2538 * try re-mapping. | |
2539 */ | |
2540 for (;;) | |
2541 { | |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2542 long wait_time; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2543 int keylen = 0; |
16227
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2544 |
7 | 2545 /* |
2546 * ui_breakcheck() is slow, don't use it too often when | |
2547 * inside a mapping. But call it each time for typed | |
2548 * characters. | |
2549 */ | |
2550 if (typebuf.tb_maplen) | |
2551 line_breakcheck(); | |
2552 else | |
2553 ui_breakcheck(); /* check for CTRL-C */ | |
2554 if (got_int) | |
2555 { | |
2556 /* flush all input */ | |
12281
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
2557 c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L); |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2558 |
7 | 2559 /* |
2560 * If inchar() returns TRUE (script file was active) or we | |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
2561 * are inside a mapping, get out of Insert mode. |
7 | 2562 * Otherwise we behave like having gotten a CTRL-C. |
2563 * As a result typing CTRL-C in insert mode will | |
2564 * really insert a CTRL-C. | |
2565 */ | |
2566 if ((c || typebuf.tb_maplen) | |
2567 && (State & (INSERT + CMDLINE))) | |
2568 c = ESC; | |
2569 else | |
2570 c = Ctrl_C; | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2571 flush_buffers(FLUSH_INPUT); // flush all typeahead |
7 | 2572 |
988 | 2573 if (advance) |
2574 { | |
2575 /* Also record this character, it might be needed to | |
2576 * get out of Insert mode. */ | |
2577 *typebuf.tb_buf = c; | |
2578 gotchars(typebuf.tb_buf, 1); | |
2579 } | |
7 | 2580 cmd_silent = FALSE; |
2581 | |
2582 break; | |
2583 } | |
2584 else if (typebuf.tb_len > 0) | |
2585 { | |
2586 /* | |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2587 * Check for a mapping in "typebuf". |
7 | 2588 */ |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2589 map_result_T result = handle_mapping( |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2590 &keylen, &timedout, &mapdepth); |
7 | 2591 |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2592 if (result == map_result_retry) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2593 // try mapping again |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2594 continue; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2595 if (result == map_result_fail) |
7 | 2596 { |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2597 // failed, use the outer loop |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2598 c = -1; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2599 break; |
7 | 2600 } |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2601 if (result == map_result_get) |
7 | 2602 { |
2603 /* | |
2604 * get a character: 2. from the typeahead buffer | |
2605 */ | |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2606 c = typebuf.tb_buf[typebuf.tb_off] & 255; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2607 if (advance) /* remove chars from tb_buf */ |
7 | 2608 { |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2609 cmd_silent = (typebuf.tb_silent > 0); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2610 if (typebuf.tb_maplen > 0) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2611 KeyTyped = FALSE; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2612 else |
7 | 2613 { |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2614 KeyTyped = TRUE; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2615 /* write char to script file(s) */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2616 gotchars(typebuf.tb_buf |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2617 + typebuf.tb_off, 1); |
7 | 2618 } |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2619 KeyNoremap = typebuf.tb_noremap[ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2620 typebuf.tb_off]; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2621 del_typebuf(1, 0); |
7 | 2622 } |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2623 break; |
7 | 2624 } |
2625 | |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2626 // not enough characters, get more |
7 | 2627 } |
2628 | |
2629 /* | |
2630 * get a character: 3. from the user - handle <Esc> in Insert mode | |
2631 */ | |
2632 /* | |
11490
6a06738f8948
patch 8.0.0628: cursor disappears after silent mapping
Christian Brabandt <cb@256bit.org>
parents:
11486
diff
changeset
|
2633 * Special case: if we get an <ESC> in insert mode and there |
7 | 2634 * are no more characters at once, we pretend to go out of |
2635 * insert mode. This prevents the one second delay after | |
2636 * typing an <ESC>. If we get something after all, we may | |
2637 * have to redisplay the mode. That the cursor is in the wrong | |
2638 * place does not matter. | |
2639 */ | |
2640 c = 0; | |
2641 #ifdef FEAT_CMDL_INFO | |
2642 new_wcol = curwin->w_wcol; | |
2643 new_wrow = curwin->w_wrow; | |
2644 #endif | |
2645 if ( advance | |
2646 && typebuf.tb_len == 1 | |
2647 && typebuf.tb_buf[typebuf.tb_off] == ESC | |
2648 && !no_mapping | |
2649 && ex_normal_busy == 0 | |
2650 && typebuf.tb_maplen == 0 | |
2651 && (State & INSERT) | |
2672 | 2652 && (p_timeout |
2653 || (keylen == KEYLEN_PART_KEY && p_ttimeout)) | |
7 | 2654 && (c = inchar(typebuf.tb_buf + typebuf.tb_off |
12281
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
2655 + typebuf.tb_len, 3, 25L)) == 0) |
7 | 2656 { |
2657 colnr_T col = 0, vcol; | |
2658 char_u *ptr; | |
2659 | |
643 | 2660 if (mode_displayed) |
7 | 2661 { |
2662 unshowmode(TRUE); | |
2663 mode_deleted = TRUE; | |
2664 } | |
2665 #ifdef FEAT_GUI | |
11490
6a06738f8948
patch 8.0.0628: cursor disappears after silent mapping
Christian Brabandt <cb@256bit.org>
parents:
11486
diff
changeset
|
2666 /* may show a different cursor shape */ |
6a06738f8948
patch 8.0.0628: cursor disappears after silent mapping
Christian Brabandt <cb@256bit.org>
parents:
11486
diff
changeset
|
2667 if (gui.in_use && State != NORMAL && !cmd_silent) |
7 | 2668 { |
2669 int save_State; | |
2670 | |
2671 save_State = State; | |
2672 State = NORMAL; | |
2673 gui_update_cursor(TRUE, FALSE); | |
2674 State = save_State; | |
2675 shape_changed = TRUE; | |
2676 } | |
2677 #endif | |
2678 validate_cursor(); | |
2679 old_wcol = curwin->w_wcol; | |
2680 old_wrow = curwin->w_wrow; | |
2681 | |
2682 /* move cursor left, if possible */ | |
2683 if (curwin->w_cursor.col != 0) | |
2684 { | |
2685 if (curwin->w_wcol > 0) | |
2686 { | |
2687 if (did_ai) | |
2688 { | |
2689 /* | |
2690 * We are expecting to truncate the trailing | |
2691 * white-space, so find the last non-white | |
2692 * character -- webb | |
2693 */ | |
2694 col = vcol = curwin->w_wcol = 0; | |
2695 ptr = ml_get_curline(); | |
2696 while (col < curwin->w_cursor.col) | |
2697 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11026
diff
changeset
|
2698 if (!VIM_ISWHITE(ptr[col])) |
7 | 2699 curwin->w_wcol = vcol; |
5995 | 2700 vcol += lbr_chartabsize(ptr, ptr + col, |
7 | 2701 (colnr_T)vcol); |
2702 if (has_mbyte) | |
474 | 2703 col += (*mb_ptr2len)(ptr + col); |
7 | 2704 else |
2705 ++col; | |
2706 } | |
2707 curwin->w_wrow = curwin->w_cline_row | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2708 + curwin->w_wcol / curwin->w_width; |
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2709 curwin->w_wcol %= curwin->w_width; |
7 | 2710 curwin->w_wcol += curwin_col_off(); |
2711 col = 0; /* no correction needed */ | |
2712 } | |
2713 else | |
2714 { | |
2715 --curwin->w_wcol; | |
2716 col = curwin->w_cursor.col - 1; | |
2717 } | |
2718 } | |
2719 else if (curwin->w_p_wrap && curwin->w_wrow) | |
2720 { | |
2721 --curwin->w_wrow; | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2722 curwin->w_wcol = curwin->w_width - 1; |
7 | 2723 col = curwin->w_cursor.col - 1; |
2724 } | |
2725 if (has_mbyte && col > 0 && curwin->w_wcol > 0) | |
2726 { | |
2727 /* Correct when the cursor is on the right halve | |
2728 * of a double-wide character. */ | |
2729 ptr = ml_get_curline(); | |
2730 col -= (*mb_head_off)(ptr, ptr + col); | |
2731 if ((*mb_ptr2cells)(ptr + col) > 1) | |
2732 --curwin->w_wcol; | |
2733 } | |
2734 } | |
2735 setcursor(); | |
2736 out_flush(); | |
2737 #ifdef FEAT_CMDL_INFO | |
2738 new_wcol = curwin->w_wcol; | |
2739 new_wrow = curwin->w_wrow; | |
2740 #endif | |
2741 curwin->w_wcol = old_wcol; | |
2742 curwin->w_wrow = old_wrow; | |
2743 } | |
2744 if (c < 0) | |
2745 continue; /* end of input script reached */ | |
6087 | 2746 |
2747 /* Allow mapping for just typed characters. When we get here c | |
2748 * is the number of extra bytes and typebuf.tb_len is 1. */ | |
2749 for (n = 1; n <= c; ++n) | |
2750 typebuf.tb_noremap[typebuf.tb_off + n] = RM_YES; | |
7 | 2751 typebuf.tb_len += c; |
2752 | |
2753 /* buffer full, don't map */ | |
2754 if (typebuf.tb_len >= typebuf.tb_maplen + MAXMAPLEN) | |
2755 { | |
2756 timedout = TRUE; | |
2757 continue; | |
2758 } | |
2759 | |
2760 if (ex_normal_busy > 0) | |
2761 { | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
2762 #ifdef FEAT_CMDWIN |
7 | 2763 static int tc = 0; |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
2764 #endif |
7 | 2765 |
2766 /* No typeahead left and inside ":normal". Must return | |
2767 * something to avoid getting stuck. When an incomplete | |
2768 * mapping is present, behave like it timed out. */ | |
2769 if (typebuf.tb_len > 0) | |
2770 { | |
2771 timedout = TRUE; | |
2772 continue; | |
2773 } | |
2774 /* When 'insertmode' is set, ESC just beeps in Insert | |
2775 * mode. Use CTRL-L to make edit() return. | |
2776 * For the command line only CTRL-C always breaks it. | |
2777 * For the cmdline window: Alternate between ESC and | |
2778 * CTRL-C: ESC for most situations and CTRL-C to close the | |
2779 * cmdline window. */ | |
2780 if (p_im && (State & INSERT)) | |
2781 c = Ctrl_L; | |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
2782 #ifdef FEAT_TERMINAL |
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
2783 else if (terminal_is_active()) |
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
2784 c = K_CANCEL; |
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
2785 #endif |
7 | 2786 else if ((State & CMDLINE) |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
2787 #ifdef FEAT_CMDWIN |
7 | 2788 || (cmdwin_type > 0 && tc == ESC) |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
2789 #endif |
7 | 2790 ) |
2791 c = Ctrl_C; | |
2792 else | |
2793 c = ESC; | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
2794 #ifdef FEAT_CMDWIN |
7 | 2795 tc = c; |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
2796 #endif |
7 | 2797 break; |
2798 } | |
2799 | |
2800 /* | |
2801 * get a character: 3. from the user - update display | |
2802 */ | |
2803 /* In insert mode a screen update is skipped when characters | |
2804 * are still available. But when those available characters | |
2805 * are part of a mapping, and we are going to do a blocking | |
2806 * wait here. Need to update the screen to display the | |
2721 | 2807 * changed text so far. Also for when 'lazyredraw' is set and |
2808 * redrawing was postponed because there was something in the | |
2809 * input buffer (e.g., termresponse). */ | |
2723 | 2810 if (((State & INSERT) != 0 || p_lz) && (State & CMDLINE) == 0 |
2811 && advance && must_redraw != 0 && !need_wait_return) | |
7 | 2812 { |
2813 update_screen(0); | |
2814 setcursor(); /* put cursor back where it belongs */ | |
2815 } | |
2816 | |
2817 /* | |
2818 * If we have a partial match (and are going to wait for more | |
2819 * input from the user), show the partially matched characters | |
2820 * to the user with showcmd. | |
2821 */ | |
2822 #ifdef FEAT_CMDL_INFO | |
2823 i = 0; | |
2824 #endif | |
2825 c1 = 0; | |
2826 if (typebuf.tb_len > 0 && advance && !exmode_active) | |
2827 { | |
2828 if (((State & (NORMAL | INSERT)) || State == LANGMAP) | |
2829 && State != HITRETURN) | |
2830 { | |
2831 /* this looks nice when typing a dead character map */ | |
2832 if (State & INSERT | |
2833 && ptr2cells(typebuf.tb_buf + typebuf.tb_off | |
2834 + typebuf.tb_len - 1) == 1) | |
2835 { | |
2836 edit_putchar(typebuf.tb_buf[typebuf.tb_off | |
2837 + typebuf.tb_len - 1], FALSE); | |
2838 setcursor(); /* put cursor back where it belongs */ | |
2839 c1 = 1; | |
2840 } | |
2841 #ifdef FEAT_CMDL_INFO | |
2842 /* need to use the col and row from above here */ | |
2843 old_wcol = curwin->w_wcol; | |
2844 old_wrow = curwin->w_wrow; | |
2845 curwin->w_wcol = new_wcol; | |
2846 curwin->w_wrow = new_wrow; | |
2847 push_showcmd(); | |
2848 if (typebuf.tb_len > SHOWCMD_COLS) | |
2849 i = typebuf.tb_len - SHOWCMD_COLS; | |
2850 while (i < typebuf.tb_len) | |
2851 (void)add_to_showcmd(typebuf.tb_buf[typebuf.tb_off | |
2852 + i++]); | |
2853 curwin->w_wcol = old_wcol; | |
2854 curwin->w_wrow = old_wrow; | |
2855 #endif | |
2856 } | |
2857 | |
2858 /* this looks nice when typing a dead character map */ | |
2859 if ((State & CMDLINE) | |
2860 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2861 && cmdline_star == 0 | |
2862 #endif | |
2863 && ptr2cells(typebuf.tb_buf + typebuf.tb_off | |
2864 + typebuf.tb_len - 1) == 1) | |
2865 { | |
2866 putcmdline(typebuf.tb_buf[typebuf.tb_off | |
2867 + typebuf.tb_len - 1], FALSE); | |
2868 c1 = 1; | |
2869 } | |
2870 } | |
2871 | |
2872 /* | |
2873 * get a character: 3. from the user - get it | |
2874 */ | |
14069
bc91de20ba43
patch 8.1.0052: when mapping to <Nop> times out the next mapping is skipped
Christian Brabandt <cb@256bit.org>
parents:
14009
diff
changeset
|
2875 if (typebuf.tb_len == 0) |
bc91de20ba43
patch 8.1.0052: when mapping to <Nop> times out the next mapping is skipped
Christian Brabandt <cb@256bit.org>
parents:
14009
diff
changeset
|
2876 // timedout may have been set while waiting for a mapping |
bc91de20ba43
patch 8.1.0052: when mapping to <Nop> times out the next mapping is skipped
Christian Brabandt <cb@256bit.org>
parents:
14009
diff
changeset
|
2877 // that has a <Nop> RHS. |
bc91de20ba43
patch 8.1.0052: when mapping to <Nop> times out the next mapping is skipped
Christian Brabandt <cb@256bit.org>
parents:
14009
diff
changeset
|
2878 timedout = FALSE; |
bc91de20ba43
patch 8.1.0052: when mapping to <Nop> times out the next mapping is skipped
Christian Brabandt <cb@256bit.org>
parents:
14009
diff
changeset
|
2879 |
16227
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2880 if (advance) |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2881 { |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2882 if (typebuf.tb_len == 0 |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2883 || !(p_timeout |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2884 || (p_ttimeout && keylen == KEYLEN_PART_KEY))) |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2885 // blocking wait |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2886 wait_time = -1L; |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2887 else if (keylen == KEYLEN_PART_KEY && p_ttm >= 0) |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2888 wait_time = p_ttm; |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2889 else |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2890 wait_time = p_tm; |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2891 } |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2892 else |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2893 wait_time = 0; |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2894 |
202 | 2895 wait_tb_len = typebuf.tb_len; |
7 | 2896 c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, |
2897 typebuf.tb_buflen - typebuf.tb_off - typebuf.tb_len - 1, | |
16227
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2898 wait_time); |
7 | 2899 |
2900 #ifdef FEAT_CMDL_INFO | |
2901 if (i != 0) | |
2902 pop_showcmd(); | |
2903 #endif | |
2904 if (c1 == 1) | |
2905 { | |
2906 if (State & INSERT) | |
2907 edit_unputchar(); | |
2908 if (State & CMDLINE) | |
2909 unputcmdline(); | |
3560 | 2910 else |
2911 setcursor(); /* put cursor back where it belongs */ | |
7 | 2912 } |
2913 | |
2914 if (c < 0) | |
2915 continue; /* end of input script reached */ | |
2916 if (c == NUL) /* no character available */ | |
2917 { | |
2918 if (!advance) | |
2919 break; | |
202 | 2920 if (wait_tb_len > 0) /* timed out */ |
7 | 2921 { |
2922 timedout = TRUE; | |
2923 continue; | |
2924 } | |
2925 } | |
2926 else | |
2927 { /* allow mapping for just typed characters */ | |
2928 while (typebuf.tb_buf[typebuf.tb_off | |
2929 + typebuf.tb_len] != NUL) | |
2930 typebuf.tb_noremap[typebuf.tb_off | |
2931 + typebuf.tb_len++] = RM_YES; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13344
diff
changeset
|
2932 #ifdef HAVE_INPUT_METHOD |
7 | 2933 /* Get IM status right after getting keys, not after the |
2934 * timeout for a mapping (focus may be lost by then). */ | |
2935 vgetc_im_active = im_get_status(); | |
2936 #endif | |
2937 } | |
2938 } /* for (;;) */ | |
2939 } /* if (!character from stuffbuf) */ | |
2940 | |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
2941 /* if advance is FALSE don't loop on NULs */ |
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
2942 } while ((c < 0 && c != K_CANCEL) || (advance && c == NUL)); |
7 | 2943 |
2944 /* | |
2945 * The "INSERT" message is taken care of here: | |
2946 * if we return an ESC to exit insert mode, the message is deleted | |
2947 * if we don't return an ESC but deleted the message before, redisplay it | |
2948 */ | |
641 | 2949 if (advance && p_smd && msg_silent == 0 && (State & INSERT)) |
7 | 2950 { |
643 | 2951 if (c == ESC && !mode_deleted && !no_mapping && mode_displayed) |
7 | 2952 { |
2953 if (typebuf.tb_len && !KeyTyped) | |
2954 redraw_cmdline = TRUE; /* delete mode later */ | |
2955 else | |
2956 unshowmode(FALSE); | |
2957 } | |
2958 else if (c != ESC && mode_deleted) | |
2959 { | |
2960 if (typebuf.tb_len && !KeyTyped) | |
2961 redraw_cmdline = TRUE; /* show mode later */ | |
2962 else | |
2963 showmode(); | |
2964 } | |
2965 } | |
2966 #ifdef FEAT_GUI | |
2967 /* may unshow different cursor shape */ | |
11490
6a06738f8948
patch 8.0.0628: cursor disappears after silent mapping
Christian Brabandt <cb@256bit.org>
parents:
11486
diff
changeset
|
2968 if (gui.in_use && shape_changed) |
6a06738f8948
patch 8.0.0628: cursor disappears after silent mapping
Christian Brabandt <cb@256bit.org>
parents:
11486
diff
changeset
|
2969 gui_update_cursor(TRUE, FALSE); |
7 | 2970 #endif |
15995
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2971 if (timedout && c == ESC) |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2972 { |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2973 char_u nop_buf[3]; |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2974 |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2975 // When recording there will be no timeout. Add a <Nop> after the ESC |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2976 // to avoid that it forms a key code with following characters. |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2977 nop_buf[0] = K_SPECIAL; |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2978 nop_buf[1] = KS_EXTRA; |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2979 nop_buf[2] = KE_NOP; |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2980 gotchars(nop_buf, 3); |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
2981 } |
7 | 2982 |
822 | 2983 --vgetc_busy; |
7 | 2984 |
2985 return c; | |
2986 } | |
2987 | |
2988 /* | |
2989 * inchar() - get one character from | |
2990 * 1. a scriptfile | |
2991 * 2. the keyboard | |
2992 * | |
2993 * As much characters as we can get (upto 'maxlen') are put in "buf" and | |
2994 * NUL terminated (buffer length must be 'maxlen' + 1). | |
2995 * Minimum for "maxlen" is 3!!!! | |
2996 * | |
2997 * "tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into | |
2998 * it. When typebuf.tb_change_cnt changes (e.g., when a message is received | |
2999 * from a remote client) "buf" can no longer be used. "tb_change_cnt" is 0 | |
3000 * otherwise. | |
3001 * | |
3002 * If we got an interrupt all input is read until none is available. | |
3003 * | |
3004 * If wait_time == 0 there is no waiting for the char. | |
3005 * If wait_time == n we wait for n msec for a character to arrive. | |
3006 * If wait_time == -1 we wait forever for a character to arrive. | |
3007 * | |
3008 * Return the number of obtained characters. | |
3009 * Return -1 when end of input script reached. | |
3010 */ | |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9121
diff
changeset
|
3011 static int |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3012 inchar( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3013 char_u *buf, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3014 int maxlen, |
12281
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3015 long wait_time) /* milli seconds */ |
7 | 3016 { |
3017 int len = 0; /* init for GCC */ | |
3018 int retesc = FALSE; /* return ESC with gotint */ | |
3019 int script_char; | |
12281
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3020 int tb_change_cnt = typebuf.tb_change_cnt; |
7 | 3021 |
3022 if (wait_time == -1L || wait_time > 100L) /* flush output before waiting */ | |
3023 { | |
3024 cursor_on(); | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
3025 out_flush_cursor(FALSE, FALSE); |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
3026 #if defined(FEAT_GUI) && defined(FEAT_MOUSESHAPE) |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
3027 if (gui.in_use && postponed_mouseshape) |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
3028 update_mouseshape(-1); |
7 | 3029 #endif |
3030 } | |
3031 | |
3032 /* | |
3033 * Don't reset these when at the hit-return prompt, otherwise a endless | |
3034 * recursive loop may result (write error in swapfile, hit-return, timeout | |
3035 * on char wait, flush swapfile, write error....). | |
3036 */ | |
3037 if (State != HITRETURN) | |
3038 { | |
3039 did_outofmem_msg = FALSE; /* display out of memory message (again) */ | |
3040 did_swapwrite_msg = FALSE; /* display swap file write error again */ | |
3041 } | |
3042 undo_off = FALSE; /* restart undo now */ | |
3043 | |
3044 /* | |
1462 | 3045 * Get a character from a script file if there is one. |
3046 * If interrupted: Stop reading script files, close them all. | |
7 | 3047 */ |
3048 script_char = -1; | |
1462 | 3049 while (scriptin[curscript] != NULL && script_char < 0 |
3050 #ifdef FEAT_EVAL | |
3051 && !ignore_script | |
3052 #endif | |
3053 ) | |
7 | 3054 { |
1618 | 3055 |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
6907
diff
changeset
|
3056 #ifdef MESSAGE_QUEUE |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
6907
diff
changeset
|
3057 parse_queued_messages(); |
1618 | 3058 #endif |
3059 | |
7 | 3060 if (got_int || (script_char = getc(scriptin[curscript])) < 0) |
3061 { | |
3062 /* Reached EOF. | |
3063 * Careful: closescript() frees typebuf.tb_buf[] and buf[] may | |
3064 * point inside typebuf.tb_buf[]. Don't use buf[] after this! */ | |
3065 closescript(); | |
3066 /* | |
3067 * When reading script file is interrupted, return an ESC to get | |
3068 * back to normal mode. | |
3069 * Otherwise return -1, because typebuf.tb_buf[] has changed. | |
3070 */ | |
3071 if (got_int) | |
3072 retesc = TRUE; | |
3073 else | |
3074 return -1; | |
3075 } | |
3076 else | |
3077 { | |
3078 buf[0] = script_char; | |
3079 len = 1; | |
3080 } | |
3081 } | |
3082 | |
3083 if (script_char < 0) /* did not get a character from script */ | |
3084 { | |
3085 /* | |
3086 * If we got an interrupt, skip all previously typed characters and | |
3087 * return TRUE if quit reading script file. | |
3088 * Stop reading typeahead when a single CTRL-C was read, | |
3089 * fill_input_buf() returns this when not able to read from stdin. | |
3090 * Don't use buf[] here, closescript() may have freed typebuf.tb_buf[] | |
3091 * and buf may be pointing inside typebuf.tb_buf[]. | |
3092 */ | |
3093 if (got_int) | |
3094 { | |
3095 #define DUM_LEN MAXMAPLEN * 3 + 3 | |
3096 char_u dum[DUM_LEN + 1]; | |
3097 | |
3098 for (;;) | |
3099 { | |
3100 len = ui_inchar(dum, DUM_LEN, 0L, 0); | |
3101 if (len == 0 || (len == 1 && dum[0] == 3)) | |
3102 break; | |
3103 } | |
3104 return retesc; | |
3105 } | |
3106 | |
3107 /* | |
3108 * Always flush the output characters when getting input characters | |
15629
dd2e0b83a660
patch 8.1.0822: peeking and flushing output slows down execution
Bram Moolenaar <Bram@vim.org>
parents:
15605
diff
changeset
|
3109 * from the user and not just peeking. |
7 | 3110 */ |
15629
dd2e0b83a660
patch 8.1.0822: peeking and flushing output slows down execution
Bram Moolenaar <Bram@vim.org>
parents:
15605
diff
changeset
|
3111 if (wait_time == -1L || wait_time > 10L) |
dd2e0b83a660
patch 8.1.0822: peeking and flushing output slows down execution
Bram Moolenaar <Bram@vim.org>
parents:
15605
diff
changeset
|
3112 out_flush(); |
7 | 3113 |
3114 /* | |
3115 * Fill up to a third of the buffer, because each character may be | |
3116 * tripled below. | |
3117 */ | |
3118 len = ui_inchar(buf, maxlen / 3, wait_time, tb_change_cnt); | |
3119 } | |
3120 | |
12281
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3121 /* If the typebuf was changed further down, it is like nothing was added by |
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3122 * this call. */ |
7 | 3123 if (typebuf_changed(tb_change_cnt)) |
3124 return 0; | |
3125 | |
12281
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3126 /* Note the change in the typeahead buffer, this matters for when |
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3127 * vgetorpeek() is called recursively, e.g. using getchar(1) in a timer |
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3128 * function. */ |
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3129 if (len > 0 && ++typebuf.tb_change_cnt == 0) |
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3130 typebuf.tb_change_cnt = 1; |
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3131 |
9896
7b39615c0db1
commit https://github.com/vim/vim/commit/6bff02eb530aa29aafa2cb5627399837be7a5dd5
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3132 return fix_input_buffer(buf, len); |
7 | 3133 } |
3134 | |
3135 /* | |
3136 * Fix typed characters for use by vgetc() and check_termcode(). | |
16531
5c6bd4431d98
patch 8.1.1269: MS-Windows GUI: multibyte chars with a 0x80 byte do not work
Bram Moolenaar <Bram@vim.org>
parents:
16495
diff
changeset
|
3137 * "buf[]" must have room to triple the number of bytes! |
7 | 3138 * Returns the new length. |
3139 */ | |
3140 int | |
9896
7b39615c0db1
commit https://github.com/vim/vim/commit/6bff02eb530aa29aafa2cb5627399837be7a5dd5
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3141 fix_input_buffer(char_u *buf, int len) |
7 | 3142 { |
3143 int i; | |
3144 char_u *p = buf; | |
3145 | |
3146 /* | |
3147 * Two characters are special: NUL and K_SPECIAL. | |
3148 * When compiled With the GUI CSI is also special. | |
3149 * Replace NUL by K_SPECIAL KS_ZERO KE_FILLER | |
3150 * Replace K_SPECIAL by K_SPECIAL KS_SPECIAL KE_FILLER | |
3151 * Replace CSI by K_SPECIAL KS_EXTRA KE_CSI | |
3152 */ | |
3153 for (i = len; --i >= 0; ++p) | |
3154 { | |
3155 #ifdef FEAT_GUI | |
3156 /* When the GUI is used any character can come after a CSI, don't | |
3157 * escape it. */ | |
3158 if (gui.in_use && p[0] == CSI && i >= 2) | |
3159 { | |
3160 p += 2; | |
3161 i -= 2; | |
3162 } | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3163 # ifndef MSWIN |
7 | 3164 /* When the GUI is not used CSI needs to be escaped. */ |
3165 else if (!gui.in_use && p[0] == CSI) | |
3166 { | |
3167 mch_memmove(p + 3, p + 1, (size_t)i); | |
3168 *p++ = K_SPECIAL; | |
3169 *p++ = KS_EXTRA; | |
3170 *p = (int)KE_CSI; | |
3171 len += 2; | |
3172 } | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3173 # endif |
7 | 3174 else |
3175 #endif | |
9896
7b39615c0db1
commit https://github.com/vim/vim/commit/6bff02eb530aa29aafa2cb5627399837be7a5dd5
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3176 if (p[0] == NUL || (p[0] == K_SPECIAL |
16531
5c6bd4431d98
patch 8.1.1269: MS-Windows GUI: multibyte chars with a 0x80 byte do not work
Bram Moolenaar <Bram@vim.org>
parents:
16495
diff
changeset
|
3177 // timeout may generate K_CURSORHOLD |
202 | 3178 && (i < 2 || p[1] != KS_EXTRA || p[2] != (int)KE_CURSORHOLD) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3179 #if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL)) |
16531
5c6bd4431d98
patch 8.1.1269: MS-Windows GUI: multibyte chars with a 0x80 byte do not work
Bram Moolenaar <Bram@vim.org>
parents:
16495
diff
changeset
|
3180 // Win32 console passes modifiers |
5c6bd4431d98
patch 8.1.1269: MS-Windows GUI: multibyte chars with a 0x80 byte do not work
Bram Moolenaar <Bram@vim.org>
parents:
16495
diff
changeset
|
3181 && ( |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3182 # ifdef VIMDLL |
16531
5c6bd4431d98
patch 8.1.1269: MS-Windows GUI: multibyte chars with a 0x80 byte do not work
Bram Moolenaar <Bram@vim.org>
parents:
16495
diff
changeset
|
3183 gui.in_use || |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3184 # endif |
16531
5c6bd4431d98
patch 8.1.1269: MS-Windows GUI: multibyte chars with a 0x80 byte do not work
Bram Moolenaar <Bram@vim.org>
parents:
16495
diff
changeset
|
3185 (i < 2 || p[1] != KS_MODIFIER)) |
7 | 3186 #endif |
3187 )) | |
3188 { | |
3189 mch_memmove(p + 3, p + 1, (size_t)i); | |
3190 p[2] = K_THIRD(p[0]); | |
3191 p[1] = K_SECOND(p[0]); | |
3192 p[0] = K_SPECIAL; | |
3193 p += 2; | |
3194 len += 2; | |
3195 } | |
3196 } | |
16531
5c6bd4431d98
patch 8.1.1269: MS-Windows GUI: multibyte chars with a 0x80 byte do not work
Bram Moolenaar <Bram@vim.org>
parents:
16495
diff
changeset
|
3197 *p = NUL; // add trailing NUL |
7 | 3198 return len; |
3199 } | |
3200 | |
3201 #if defined(USE_INPUT_BUF) || defined(PROTO) | |
3202 /* | |
3203 * Return TRUE when bytes are in the input buffer or in the typeahead buffer. | |
3204 * Normally the input buffer would be sufficient, but the server_to_input_buf() | |
842 | 3205 * or feedkeys() may insert characters in the typeahead buffer while we are |
841 | 3206 * waiting for input to arrive. |
7 | 3207 */ |
3208 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3209 input_available(void) |
7 | 3210 { |
3211 return (!vim_is_input_buf_empty() | |
841 | 3212 # if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
3213 || typebuf_was_filled | |
7 | 3214 # endif |
3215 ); | |
3216 } | |
3217 #endif |