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