Mercurial > vim
annotate src/getchar.c @ 28595:a336c53b6ffb
Added tag v8.2.4821 for changeset 294771aab3aef54f79e587eff755f73bc9858257
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 24 Apr 2022 22:45:04 +0200 |
parents | 4dcccb2673fe |
children | ce202d2984a0 |
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 /* | |
26224
7d66d585bffa
patch 8.2.3643: header for source file is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26125
diff
changeset
|
11 * getchar.c: Code related to getting a character from the user or a script |
7d66d585bffa
patch 8.2.3643: header for source file is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26125
diff
changeset
|
12 * file, manipulations with redo buffer and stuff buffer. |
7 | 13 */ |
14 | |
15 #include "vim.h" | |
16 | |
17 /* | |
18 * These buffers are used for storing: | |
19 * - stuffed characters: A command that is translated into another command. | |
20 * - redo characters: will redo the last change. | |
1992 | 21 * - recorded characters: for the "q" command. |
7 | 22 * |
23 * The bytes are stored like in the typeahead buffer: | |
24 * - K_SPECIAL introduces a special key (two more bytes follow). A literal | |
25 * K_SPECIAL is stored as K_SPECIAL KS_SPECIAL KE_FILLER. | |
26 * - CSI introduces a GUI termcap code (also when gui.in_use is FALSE, | |
27 * otherwise switching the GUI on would make mappings invalid). | |
28 * A literal CSI is stored as CSI KS_EXTRA KE_CSI. | |
29 * These translations are also done on multi-byte characters! | |
30 * | |
31 * Escaping CSI bytes is done by the system-specific input functions, called | |
32 * by ui_inchar(). | |
33 * Escaping K_SPECIAL is done by inchar(). | |
34 * Un-escaping is done by vgetc(). | |
35 */ | |
36 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
37 #define MINIMAL_SIZE 20 // minimal size for b_str |
7 | 38 |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
39 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
|
40 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
|
41 static buffheader_T recordbuff = {{NULL, {NUL}}, NULL, 0, 0}; |
7 | 42 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
43 static int typeahead_char = 0; // typeahead char that's not flushed |
7 | 44 |
45 /* | |
46 * when block_redo is TRUE redo buffer will not be changed | |
47 * used by edit() to repeat insertions and 'V' command for redoing | |
48 */ | |
49 static int block_redo = FALSE; | |
50 | |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18281
diff
changeset
|
51 static int KeyNoremap = 0; // remapping flags |
7 | 52 |
53 /* | |
9228
ea504064c996
commit https://github.com/vim/vim/commit/fd89d7ea81b18d32363456b16258174dc9e095dc
Christian Brabandt <cb@256bit.org>
parents:
9205
diff
changeset
|
54 * Variables used by vgetorpeek() and flush_buffers(). |
7 | 55 * |
56 * typebuf.tb_buf[] contains all characters that are not consumed yet. | |
57 * typebuf.tb_buf[typebuf.tb_off] is the first valid character. | |
58 * typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1] is the last valid char. | |
59 * typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] must be NUL. | |
60 * The head of the buffer may contain the result of mappings, abbreviations | |
61 * and @a commands. The length of this part is typebuf.tb_maplen. | |
62 * typebuf.tb_silent is the part where <silent> applies. | |
63 * After the head are characters that come from the terminal. | |
64 * typebuf.tb_no_abbr_cnt is the number of characters in typebuf.tb_buf that | |
65 * should not be considered for abbreviations. | |
66 * Some parts of typebuf.tb_buf may not be mapped. These parts are remembered | |
67 * in typebuf.tb_noremap[], which is the same length as typebuf.tb_buf and | |
68 * contains RM_NONE for the characters that are not to be remapped. | |
69 * typebuf.tb_noremap[typebuf.tb_off] is the first valid flag. | |
70 * (typebuf has been put in globals.h, because check_termcode() needs it). | |
71 */ | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
72 #define RM_YES 0 // tb_noremap: remap |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
73 #define RM_NONE 1 // tb_noremap: don't remap |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
74 #define RM_SCRIPT 2 // tb_noremap: remap local script mappings |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
75 #define RM_ABBR 4 // tb_noremap: don't remap, do abbrev. |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
76 |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
77 // typebuf.tb_buf has three parts: room in front (for result of mappings), the |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
78 // middle for typeahead and room for new characters (which needs to be 3 * |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26592
diff
changeset
|
79 // MAXMAPLEN for the Amiga). |
7 | 80 #define TYPELEN_INIT (5 * (MAXMAPLEN + 3)) |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
81 static char_u typebuf_init[TYPELEN_INIT]; // initial typebuf.tb_buf |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
82 static char_u noremapbuf_init[TYPELEN_INIT]; // initial typebuf.tb_noremap |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
83 |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
84 static int last_recorded_len = 0; // number of last recorded chars |
7 | 85 |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
86 #ifdef FEAT_EVAL |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
87 mapblock_T *last_used_map = NULL; |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
88 #endif |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
89 |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
90 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
|
91 static void init_typebuf(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
92 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
|
93 static void free_typebuf(void); |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
94 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
|
95 static void updatescript(int c); |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
96 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
|
97 static int inchar(char_u *buf, int maxlen, long wait_time); |
7 | 98 |
99 /* | |
100 * Free and clear a buffer. | |
101 */ | |
19916
dcec86d796bc
patch 8.2.0514: several global functions are used in only one file
Bram Moolenaar <Bram@vim.org>
parents:
19627
diff
changeset
|
102 static void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
103 free_buff(buffheader_T *buf) |
7 | 104 { |
5649 | 105 buffblock_T *p, *np; |
7 | 106 |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
107 for (p = buf->bh_first.b_next; p != NULL; p = np) |
7 | 108 { |
109 np = p->b_next; | |
110 vim_free(p); | |
111 } | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
112 buf->bh_first.b_next = NULL; |
27416
0b3bf3cbe42f
patch 8.2.4236: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents:
27414
diff
changeset
|
113 buf->bh_curr = 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, |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
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 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
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, |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
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); | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
206 if (slen == 0) // don't add empty strings |
7 | 207 return; |
208 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
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 } |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
214 else if (buf->bh_curr == NULL) // buffer has already been read |
7 | 215 { |
26861
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
216 iemsg(_(e_add_to_internal_buffer_that_was_already_read_from)); |
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) |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
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 } | |
248 | |
249 /* | |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
250 * Delete "slen" bytes from the end of "buf". |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
251 * Only works when it was just added. |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
252 */ |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
253 static void |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
254 delete_buff_tail(buffheader_T *buf, int slen) |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
255 { |
27410
5d6774c0df4f
patch 8.2.4233: crash when recording and using Select mode
Bram Moolenaar <Bram@vim.org>
parents:
27239
diff
changeset
|
256 int len; |
5d6774c0df4f
patch 8.2.4233: crash when recording and using Select mode
Bram Moolenaar <Bram@vim.org>
parents:
27239
diff
changeset
|
257 |
27414
b2d0357fec12
patch 8.2.4235: invalid check for NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27410
diff
changeset
|
258 if (buf->bh_curr == NULL) |
27410
5d6774c0df4f
patch 8.2.4233: crash when recording and using Select mode
Bram Moolenaar <Bram@vim.org>
parents:
27239
diff
changeset
|
259 return; // nothing to delete |
5d6774c0df4f
patch 8.2.4233: crash when recording and using Select mode
Bram Moolenaar <Bram@vim.org>
parents:
27239
diff
changeset
|
260 len = (int)STRLEN(buf->bh_curr->b_str); |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
261 if (len >= slen) |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
262 { |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
263 buf->bh_curr->b_str[len - slen] = NUL; |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
264 buf->bh_space += slen; |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
265 } |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
266 } |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
267 |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
268 /* |
7 | 269 * Add number "n" to buffer "buf". |
270 */ | |
271 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
272 add_num_buff(buffheader_T *buf, long n) |
7 | 273 { |
274 char_u number[32]; | |
275 | |
276 sprintf((char *)number, "%ld", n); | |
277 add_buff(buf, number, -1L); | |
278 } | |
279 | |
280 /* | |
281 * Add character 'c' to buffer "buf". | |
282 * Translates special keys, NUL, CSI, K_SPECIAL and multibyte characters. | |
283 */ | |
284 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
285 add_char_buff(buffheader_T *buf, int c) |
7 | 286 { |
287 char_u bytes[MB_MAXBYTES + 1]; | |
288 int len; | |
289 int i; | |
290 char_u temp[4]; | |
291 | |
292 if (IS_SPECIAL(c)) | |
293 len = 1; | |
294 else | |
295 len = (*mb_char2bytes)(c, bytes); | |
296 for (i = 0; i < len; ++i) | |
297 { | |
298 if (!IS_SPECIAL(c)) | |
299 c = bytes[i]; | |
300 | |
301 if (IS_SPECIAL(c) || c == K_SPECIAL || c == NUL) | |
302 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
303 // translate special key code into three byte sequence |
7 | 304 temp[0] = K_SPECIAL; |
305 temp[1] = K_SECOND(c); | |
306 temp[2] = K_THIRD(c); | |
307 temp[3] = NUL; | |
308 } | |
309 #ifdef FEAT_GUI | |
310 else if (c == CSI) | |
311 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
312 // Translate a CSI to a CSI - KS_EXTRA - KE_CSI sequence |
7 | 313 temp[0] = CSI; |
314 temp[1] = KS_EXTRA; | |
315 temp[2] = (int)KE_CSI; | |
316 temp[3] = NUL; | |
317 } | |
318 #endif | |
319 else | |
320 { | |
321 temp[0] = c; | |
322 temp[1] = NUL; | |
323 } | |
324 add_buff(buf, temp, -1L); | |
325 } | |
326 } | |
327 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
328 // 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
|
329 static buffheader_T readbuf1 = {{NULL, {NUL}}, NULL, 0, 0}; |
5649 | 330 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
331 // 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
|
332 static buffheader_T readbuf2 = {{NULL, {NUL}}, NULL, 0, 0}; |
5649 | 333 |
7 | 334 /* |
5649 | 335 * Get one byte from the read buffers. Use readbuf1 one first, use readbuf2 |
336 * if that one is empty. | |
7 | 337 * If advance == TRUE go to the next char. |
338 * No translation is done K_SPECIAL and CSI are escaped. | |
339 */ | |
340 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
341 read_readbuffers(int advance) |
7 | 342 { |
5649 | 343 int c; |
344 | |
345 c = read_readbuf(&readbuf1, advance); | |
346 if (c == NUL) | |
347 c = read_readbuf(&readbuf2, advance); | |
348 return c; | |
349 } | |
350 | |
351 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
352 read_readbuf(buffheader_T *buf, int advance) |
5649 | 353 { |
354 char_u c; | |
355 buffblock_T *curr; | |
356 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
357 if (buf->bh_first.b_next == NULL) // buffer is empty |
7 | 358 return NUL; |
359 | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
360 curr = buf->bh_first.b_next; |
5649 | 361 c = curr->b_str[buf->bh_index]; |
7 | 362 |
363 if (advance) | |
364 { | |
5649 | 365 if (curr->b_str[++buf->bh_index] == NUL) |
7 | 366 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
367 buf->bh_first.b_next = curr->b_next; |
7 | 368 vim_free(curr); |
5649 | 369 buf->bh_index = 0; |
7 | 370 } |
371 } | |
372 return c; | |
373 } | |
374 | |
375 /* | |
5670 | 376 * Prepare the read buffers for reading (if they contain something). |
7 | 377 */ |
378 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
379 start_stuff(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 if (readbuf1.bh_first.b_next != NULL) |
7 | 382 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
383 readbuf1.bh_curr = &(readbuf1.bh_first); |
5649 | 384 readbuf1.bh_space = 0; |
385 } | |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
386 if (readbuf2.bh_first.b_next != NULL) |
5649 | 387 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
388 readbuf2.bh_curr = &(readbuf2.bh_first); |
5649 | 389 readbuf2.bh_space = 0; |
7 | 390 } |
391 } | |
392 | |
393 /* | |
394 * Return TRUE if the stuff buffer is empty. | |
395 */ | |
396 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
397 stuff_empty(void) |
7 | 398 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
399 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
|
400 && readbuf2.bh_first.b_next == NULL); |
5649 | 401 } |
402 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
403 #if defined(FEAT_EVAL) || defined(PROTO) |
5649 | 404 /* |
405 * Return TRUE if readbuf1 is empty. There may still be redo characters in | |
406 * redbuf2. | |
407 */ | |
408 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
409 readbuf1_empty(void) |
5649 | 410 { |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13702
diff
changeset
|
411 return (readbuf1.bh_first.b_next == NULL); |
7 | 412 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
413 #endif |
7 | 414 |
415 /* | |
416 * Set a typeahead character that won't be flushed. | |
417 */ | |
418 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
419 typeahead_noflush(int c) |
7 | 420 { |
421 typeahead_char = c; | |
422 } | |
423 | |
424 /* | |
425 * Remove the contents of the stuff buffer and the mapped characters in the | |
3263 | 426 * typeahead buffer (used in case of an error). If "flush_typeahead" is true, |
7 | 427 * flush all typeahead characters (used when interrupted by a CTRL-C). |
428 */ | |
429 void | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
430 flush_buffers(flush_buffers_T flush_typeahead) |
7 | 431 { |
432 init_typebuf(); | |
433 | |
434 start_stuff(); | |
5649 | 435 while (read_readbuffers(TRUE) != NUL) |
7 | 436 ; |
437 | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
438 if (flush_typeahead == FLUSH_MINIMAL) |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
439 { |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
440 // remove mapped characters at the start only |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
441 typebuf.tb_off += typebuf.tb_maplen; |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
442 typebuf.tb_len -= typebuf.tb_maplen; |
19627
6b1564fcab92
patch 8.2.0370: the typebuf_was_filled flag is sometimes not reset
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
443 #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
6b1564fcab92
patch 8.2.0370: the typebuf_was_filled flag is sometimes not reset
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
444 if (typebuf.tb_len == 0) |
6b1564fcab92
patch 8.2.0370: the typebuf_was_filled flag is sometimes not reset
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
445 typebuf_was_filled = FALSE; |
6b1564fcab92
patch 8.2.0370: the typebuf_was_filled flag is sometimes not reset
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
446 #endif |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
447 } |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
448 else |
7 | 449 { |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
450 // remove typeahead |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
451 if (flush_typeahead == FLUSH_INPUT) |
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
452 // 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
|
453 // 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
|
454 // 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
|
455 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
|
456 ; |
7 | 457 typebuf.tb_off = MAXMAPLEN; |
458 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
|
459 #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
460 // Reset the flag that text received from a client or from feedkeys() |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
461 // was inserted in the typeahead buffer. |
11577
2bc04093ed28
patch 8.0.0671: hang when typing CTRL-C in confirm() in timer
Christian Brabandt <cb@256bit.org>
parents:
11490
diff
changeset
|
462 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
|
463 #endif |
7 | 464 } |
465 typebuf.tb_maplen = 0; | |
466 typebuf.tb_silent = 0; | |
467 cmd_silent = FALSE; | |
468 typebuf.tb_no_abbr_cnt = 0; | |
21654
bb0c4325a712
patch 8.2.1377: triggering the ATTENTION prompt causes typeahead mess up
Bram Moolenaar <Bram@vim.org>
parents:
21230
diff
changeset
|
469 if (++typebuf.tb_change_cnt == 0) |
bb0c4325a712
patch 8.2.1377: triggering the ATTENTION prompt causes typeahead mess up
Bram Moolenaar <Bram@vim.org>
parents:
21230
diff
changeset
|
470 typebuf.tb_change_cnt = 1; |
7 | 471 } |
472 | |
473 /* | |
474 * The previous contents of the redo buffer is kept in old_redobuffer. | |
475 * This is used for the CTRL-O <.> command in insert mode. | |
476 */ | |
477 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
478 ResetRedobuff(void) |
7 | 479 { |
480 if (!block_redo) | |
481 { | |
482 free_buff(&old_redobuff); | |
483 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
|
484 redobuff.bh_first.b_next = NULL; |
7 | 485 } |
486 } | |
487 | |
3324 | 488 /* |
489 * Discard the contents of the redo buffer and restore the previous redo | |
490 * buffer. | |
491 */ | |
492 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
493 CancelRedo(void) |
3324 | 494 { |
495 if (!block_redo) | |
496 { | |
497 free_buff(&redobuff); | |
498 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
|
499 old_redobuff.bh_first.b_next = NULL; |
3324 | 500 start_stuff(); |
5649 | 501 while (read_readbuffers(TRUE) != NUL) |
3324 | 502 ; |
503 } | |
504 } | |
505 | |
7 | 506 /* |
507 * Save redobuff and old_redobuff to save_redobuff and save_old_redobuff. | |
508 * Used before executing autocommands and user functions. | |
509 */ | |
510 void | |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
511 saveRedobuff(save_redo_T *save_redo) |
7 | 512 { |
513 char_u *s; | |
514 | |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
515 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
|
516 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
|
517 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
|
518 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
|
519 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
520 // Make a copy, so that ":normal ." in a function works. |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
521 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
|
522 if (s != NULL) |
7 | 523 { |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
524 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
|
525 vim_free(s); |
7 | 526 } |
527 } | |
528 | |
529 /* | |
530 * Restore redobuff and old_redobuff from save_redobuff and save_old_redobuff. | |
531 * Used after executing autocommands and user functions. | |
532 */ | |
533 void | |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
534 restoreRedobuff(save_redo_T *save_redo) |
7 | 535 { |
11325
77f3b7316d8b
patch 8.0.0548: saving the redo buffer only works one time
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
536 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
|
537 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
|
538 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
|
539 old_redobuff = save_redo->sr_old_redobuff; |
7 | 540 } |
541 | |
542 /* | |
543 * Append "s" to the redo buffer. | |
544 * K_SPECIAL and CSI should already have been escaped. | |
545 */ | |
546 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
547 AppendToRedobuff(char_u *s) |
7 | 548 { |
549 if (!block_redo) | |
550 add_buff(&redobuff, s, -1L); | |
551 } | |
552 | |
553 /* | |
554 * Append to Redo buffer literally, escaping special characters with CTRL-V. | |
555 * K_SPECIAL and CSI are escaped as well. | |
556 */ | |
557 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
558 AppendToRedobuffLit( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
559 char_u *str, |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
560 int len) // length of "str" or -1 for up to the NUL |
7 | 561 { |
620 | 562 char_u *s = str; |
7 | 563 int c; |
564 char_u *start; | |
565 | |
566 if (block_redo) | |
567 return; | |
568 | |
620 | 569 while (len < 0 ? *s != NUL : s - str < len) |
7 | 570 { |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
571 // Put a string of normal characters in the redo buffer (that's |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
572 // faster). |
7 | 573 start = s; |
27490
fb4c30606b4a
patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
27416
diff
changeset
|
574 while (*s >= ' ' && *s < DEL && (len < 0 || s - str < len)) |
7 | 575 ++s; |
576 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
577 // Don't put '0' or '^' as last character, just in case a CTRL-D is |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
578 // typed next. |
7 | 579 if (*s == NUL && (s[-1] == '0' || s[-1] == '^')) |
580 --s; | |
581 if (s > start) | |
582 add_buff(&redobuff, start, (long)(s - start)); | |
583 | |
620 | 584 if (*s == NUL || (len >= 0 && s - str >= len)) |
585 break; | |
586 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
587 // Handle a special or multibyte character. |
620 | 588 if (has_mbyte) |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
589 // Handle composing chars separately. |
620 | 590 c = mb_cptr2char_adv(&s); |
591 else | |
592 c = *s++; | |
593 if (c < ' ' || c == DEL || (*s == NUL && (c == '0' || c == '^'))) | |
594 add_char_buff(&redobuff, Ctrl_V); | |
595 | |
27490
fb4c30606b4a
patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
27416
diff
changeset
|
596 // CTRL-V '0' must be inserted as CTRL-V 048 |
620 | 597 if (*s == NUL && c == '0') |
598 add_buff(&redobuff, (char_u *)"048", 3L); | |
599 else | |
600 add_char_buff(&redobuff, c); | |
7 | 601 } |
602 } | |
603 | |
604 /* | |
605 * Append a character to the redo buffer. | |
606 * Translates special keys, NUL, CSI, K_SPECIAL and multibyte characters. | |
607 */ | |
608 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
609 AppendCharToRedobuff(int c) |
7 | 610 { |
611 if (!block_redo) | |
612 add_char_buff(&redobuff, c); | |
613 } | |
614 | |
615 /* | |
616 * Append a number to the redo buffer. | |
617 */ | |
618 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
619 AppendNumberToRedobuff(long n) |
7 | 620 { |
621 if (!block_redo) | |
622 add_num_buff(&redobuff, n); | |
623 } | |
624 | |
625 /* | |
626 * Append string "s" to the stuff buffer. | |
627 * CSI and K_SPECIAL must already have been escaped. | |
628 */ | |
629 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
630 stuffReadbuff(char_u *s) |
7 | 631 { |
5649 | 632 add_buff(&readbuf1, s, -1L); |
7 | 633 } |
634 | |
6098 | 635 /* |
636 * Append string "s" to the redo stuff buffer. | |
637 * CSI and K_SPECIAL must already have been escaped. | |
638 */ | |
639 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
640 stuffRedoReadbuff(char_u *s) |
6098 | 641 { |
642 add_buff(&readbuf2, s, -1L); | |
643 } | |
644 | |
25567
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
645 static void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
646 stuffReadbuffLen(char_u *s, long len) |
7 | 647 { |
5649 | 648 add_buff(&readbuf1, s, len); |
7 | 649 } |
650 | |
651 #if defined(FEAT_EVAL) || defined(PROTO) | |
652 /* | |
653 * Stuff "s" into the stuff buffer, leaving special key codes unmodified and | |
654 * escaping other K_SPECIAL and CSI bytes. | |
2784 | 655 * Change CR, LF and ESC into a space. |
7 | 656 */ |
657 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
658 stuffReadbuffSpec(char_u *s) |
7 | 659 { |
2784 | 660 int c; |
661 | |
7 | 662 while (*s != NUL) |
663 { | |
664 if (*s == K_SPECIAL && s[1] != NUL && s[2] != NUL) | |
665 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
666 // Insert special key literally. |
7 | 667 stuffReadbuffLen(s, 3L); |
668 s += 3; | |
669 } | |
670 else | |
2784 | 671 { |
672 c = mb_ptr2char_adv(&s); | |
673 if (c == CAR || c == NL || c == ESC) | |
674 c = ' '; | |
675 stuffcharReadbuff(c); | |
676 } | |
7 | 677 } |
678 } | |
679 #endif | |
680 | |
681 /* | |
682 * Append a character to the stuff buffer. | |
683 * Translates special keys, NUL, CSI, K_SPECIAL and multibyte characters. | |
684 */ | |
685 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
686 stuffcharReadbuff(int c) |
7 | 687 { |
5649 | 688 add_char_buff(&readbuf1, c); |
7 | 689 } |
690 | |
691 /* | |
692 * Append a number to the stuff buffer. | |
693 */ | |
694 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
695 stuffnumReadbuff(long n) |
7 | 696 { |
5649 | 697 add_num_buff(&readbuf1, n); |
7 | 698 } |
699 | |
700 /* | |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
701 * Stuff a string into the typeahead buffer, such that edit() will insert it |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
702 * literally ("literally" TRUE) or interpret is as typed characters. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
703 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
704 void |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
705 stuffescaped(char_u *arg, int literally) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
706 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
707 int c; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
708 char_u *start; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
709 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
710 while (*arg != NUL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
711 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
712 // Stuff a sequence of normal ASCII characters, that's fast. Also |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
713 // stuff K_SPECIAL to get the effect of a special key when "literally" |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
714 // is TRUE. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
715 start = arg; |
27490
fb4c30606b4a
patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
27416
diff
changeset
|
716 while ((*arg >= ' ' && *arg < DEL) |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
717 || (*arg == K_SPECIAL && !literally)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
718 ++arg; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
719 if (arg > start) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
720 stuffReadbuffLen(start, (long)(arg - start)); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
721 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
722 // stuff a single special character |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
723 if (*arg != NUL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
724 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
725 if (has_mbyte) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
726 c = mb_cptr2char_adv(&arg); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
727 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
728 c = *arg++; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
729 if (literally && ((c < ' ' && c != TAB) || c == DEL)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
730 stuffcharReadbuff(Ctrl_V); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
731 stuffcharReadbuff(c); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
732 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
733 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
734 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
735 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
736 /* |
7 | 737 * Read a character from the redo buffer. Translates K_SPECIAL, CSI and |
738 * multibyte characters. | |
739 * The redo buffer is left as it is. | |
3324 | 740 * If init is TRUE, prepare for redo, return FAIL if nothing to redo, OK |
741 * otherwise. | |
742 * If old is TRUE, use old_redobuff instead of redobuff. | |
7 | 743 */ |
744 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
745 read_redo(int init, int old_redo) |
7 | 746 { |
5649 | 747 static buffblock_T *bp; |
748 static char_u *p; | |
749 int c; | |
750 int n; | |
751 char_u buf[MB_MAXBYTES + 1]; | |
752 int i; | |
7 | 753 |
754 if (init) | |
755 { | |
756 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
|
757 bp = old_redobuff.bh_first.b_next; |
7 | 758 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
|
759 bp = redobuff.bh_first.b_next; |
7 | 760 if (bp == NULL) |
761 return FAIL; | |
762 p = bp->b_str; | |
763 return OK; | |
764 } | |
765 if ((c = *p) != NUL) | |
766 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
767 // Reverse the conversion done by add_char_buff() |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
768 // For a multi-byte character get all the bytes and return the |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
769 // converted character. |
7 | 770 if (has_mbyte && (c != K_SPECIAL || p[1] == KS_SPECIAL)) |
771 n = MB_BYTE2LEN_CHECK(c); | |
772 else | |
773 n = 1; | |
774 for (i = 0; ; ++i) | |
775 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
776 if (c == K_SPECIAL) // special key or escaped K_SPECIAL |
7 | 777 { |
778 c = TO_SPECIAL(p[1], p[2]); | |
779 p += 2; | |
780 } | |
781 #ifdef FEAT_GUI | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
782 if (c == CSI) // escaped CSI |
7 | 783 p += 2; |
784 #endif | |
785 if (*++p == NUL && bp->b_next != NULL) | |
786 { | |
787 bp = bp->b_next; | |
788 p = bp->b_str; | |
789 } | |
790 buf[i] = c; | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
791 if (i == n - 1) // last byte of a character |
7 | 792 { |
793 if (n != 1) | |
794 c = (*mb_ptr2char)(buf); | |
795 break; | |
796 } | |
797 c = *p; | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
798 if (c == NUL) // cannot happen? |
7 | 799 break; |
800 } | |
801 } | |
802 | |
803 return c; | |
804 } | |
805 | |
806 /* | |
807 * Copy the rest of the redo buffer into the stuff buffer (in a slow way). | |
808 * If old_redo is TRUE, use old_redobuff instead of redobuff. | |
809 * The escaped K_SPECIAL and CSI are copied without translation. | |
810 */ | |
811 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
812 copy_redo(int old_redo) |
7 | 813 { |
814 int c; | |
815 | |
816 while ((c = read_redo(FALSE, old_redo)) != NUL) | |
5649 | 817 add_char_buff(&readbuf2, c); |
7 | 818 } |
819 | |
820 /* | |
5649 | 821 * Stuff the redo buffer into readbuf2. |
7 | 822 * Insert the redo count into the command. |
823 * If "old_redo" is TRUE, the last but one command is repeated | |
824 * instead of the last command (inserting text). This is used for | |
825 * CTRL-O <.> in insert mode | |
826 * | |
827 * return FAIL for failure, OK otherwise | |
828 */ | |
829 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
830 start_redo(long count, int old_redo) |
7 | 831 { |
832 int c; | |
833 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
834 // init the pointers; return if nothing to redo |
7 | 835 if (read_redo(TRUE, old_redo) == FAIL) |
836 return FAIL; | |
837 | |
838 c = read_redo(FALSE, old_redo); | |
839 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
840 // copy the buffer name, if present |
7 | 841 if (c == '"') |
842 { | |
5649 | 843 add_buff(&readbuf2, (char_u *)"\"", 1L); |
7 | 844 c = read_redo(FALSE, old_redo); |
845 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
846 // if a numbered buffer is used, increment the number |
7 | 847 if (c >= '1' && c < '9') |
848 ++c; | |
5649 | 849 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
|
850 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
851 // the expression register should be re-evaluated |
14009
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
852 if (c == '=') |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
853 { |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
854 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
|
855 cmd_silent = TRUE; |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
856 } |
830a47e48791
patch 8.1.0022: repeating put from expression register fails
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
857 |
7 | 858 c = read_redo(FALSE, old_redo); |
859 } | |
860 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
861 if (c == 'v') // redo Visual |
7 | 862 { |
863 VIsual = curwin->w_cursor; | |
864 VIsual_active = TRUE; | |
865 VIsual_select = FALSE; | |
866 VIsual_reselect = TRUE; | |
867 redo_VIsual_busy = TRUE; | |
868 c = read_redo(FALSE, old_redo); | |
869 } | |
870 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
871 // try to enter the count (in place of a previous count) |
7 | 872 if (count) |
873 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
874 while (VIM_ISDIGIT(c)) // skip "old" count |
7 | 875 c = read_redo(FALSE, old_redo); |
5649 | 876 add_num_buff(&readbuf2, count); |
7 | 877 } |
878 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
879 // copy from the redo buffer into the stuff buffer |
5649 | 880 add_char_buff(&readbuf2, c); |
7 | 881 copy_redo(old_redo); |
882 return OK; | |
883 } | |
884 | |
885 /* | |
886 * Repeat the last insert (R, o, O, a, A, i or I command) by stuffing | |
5649 | 887 * the redo buffer into readbuf2. |
7 | 888 * return FAIL for failure, OK otherwise |
889 */ | |
890 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
891 start_redo_ins(void) |
7 | 892 { |
893 int c; | |
894 | |
895 if (read_redo(TRUE, FALSE) == FAIL) | |
896 return FAIL; | |
897 start_stuff(); | |
898 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
899 // skip the count and the command character |
7 | 900 while ((c = read_redo(FALSE, FALSE)) != NUL) |
901 { | |
902 if (vim_strchr((char_u *)"AaIiRrOo", c) != NULL) | |
903 { | |
904 if (c == 'O' || c == 'o') | |
5649 | 905 add_buff(&readbuf2, NL_STR, -1L); |
7 | 906 break; |
907 } | |
908 } | |
909 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
910 // copy the typed text from the redo buffer into the stuff buffer |
7 | 911 copy_redo(FALSE); |
912 block_redo = TRUE; | |
913 return OK; | |
914 } | |
915 | |
916 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
917 stop_redo_ins(void) |
7 | 918 { |
919 block_redo = FALSE; | |
920 } | |
921 | |
922 /* | |
923 * Initialize typebuf.tb_buf to point to typebuf_init. | |
924 * alloc() cannot be used here: In out-of-memory situations it would | |
925 * be impossible to type anything. | |
926 */ | |
927 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
928 init_typebuf(void) |
7 | 929 { |
930 if (typebuf.tb_buf == NULL) | |
931 { | |
932 typebuf.tb_buf = typebuf_init; | |
933 typebuf.tb_noremap = noremapbuf_init; | |
934 typebuf.tb_buflen = TYPELEN_INIT; | |
935 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
|
936 typebuf.tb_off = MAXMAPLEN + 4; |
7 | 937 typebuf.tb_change_cnt = 1; |
938 } | |
939 } | |
940 | |
941 /* | |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
942 * 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
|
943 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
944 int |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
945 noremap_keys(void) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
946 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
947 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
|
948 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
949 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
17522
diff
changeset
|
950 /* |
7408
1886f2863437
commit https://github.com/vim/vim/commit/e7fedb6ebe72d9a475aa65109b77d5ed4667067a
Christian Brabandt <cb@256bit.org>
parents:
7117
diff
changeset
|
951 * 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
|
952 * and ":normal" command, vgetorpeek() and check_termcode()). |
7 | 953 * |
954 * If noremap is REMAP_YES, new string can be mapped again. | |
955 * If noremap is REMAP_NONE, new string cannot be mapped again. | |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26592
diff
changeset
|
956 * If noremap is REMAP_SKIP, first char of new string cannot be mapped again, |
10 | 957 * but abbreviations are allowed. |
7 | 958 * If noremap is REMAP_SCRIPT, new string cannot be mapped again, except for |
959 * script-local mappings. | |
960 * If noremap is > 0, that many characters of the new string cannot be mapped. | |
961 * | |
962 * If nottyped is TRUE, the string does not return KeyTyped (don't use when | |
963 * offset is non-zero!). | |
964 * | |
965 * If silent is TRUE, cmd_silent is set when the characters are obtained. | |
966 * | |
967 * return FAIL for failure, OK otherwise | |
968 */ | |
969 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
970 ins_typebuf( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
971 char_u *str, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
972 int noremap, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
973 int offset, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
974 int nottyped, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
975 int silent) |
7 | 976 { |
977 char_u *s1, *s2; | |
978 int newlen; | |
979 int addlen; | |
980 int i; | |
981 int newoff; | |
982 int val; | |
983 int nrm; | |
984 | |
985 init_typebuf(); | |
986 if (++typebuf.tb_change_cnt == 0) | |
987 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
|
988 state_no_longer_safe("ins_typebuf()"); |
7 | 989 |
990 addlen = (int)STRLEN(str); | |
1130 | 991 |
7 | 992 if (offset == 0 && addlen <= typebuf.tb_off) |
993 { | |
10549
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
994 /* |
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
995 * 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
|
996 */ |
7 | 997 typebuf.tb_off -= addlen; |
998 mch_memmove(typebuf.tb_buf + typebuf.tb_off, str, (size_t)addlen); | |
999 } | |
11331
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
1000 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
|
1001 >= 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
|
1002 { |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
1003 /* |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
1004 * 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
|
1005 * 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
|
1006 */ |
ff27a6a3a243
patch 8.0.0551: the typeahead buffer is reallocated too often
Christian Brabandt <cb@256bit.org>
parents:
11325
diff
changeset
|
1007 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
|
1008 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
|
1009 } |
7 | 1010 else |
1011 { | |
26125
18114bb393e0
patch 8.2.3595: check for signed overflow might not work everywhere
Bram Moolenaar <Bram@vim.org>
parents:
25913
diff
changeset
|
1012 int extra; |
18114bb393e0
patch 8.2.3595: check for signed overflow might not work everywhere
Bram Moolenaar <Bram@vim.org>
parents:
25913
diff
changeset
|
1013 |
10549
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1014 /* |
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1015 * 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
|
1016 * 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
|
1017 * 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
|
1018 * often. |
055b1633aed7
patch 8.0.0164: outdated and misplaced comments
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1019 */ |
7 | 1020 newoff = MAXMAPLEN + 4; |
26125
18114bb393e0
patch 8.2.3595: check for signed overflow might not work everywhere
Bram Moolenaar <Bram@vim.org>
parents:
25913
diff
changeset
|
1021 extra = addlen + newoff + 4 * (MAXMAPLEN + 4); |
18114bb393e0
patch 8.2.3595: check for signed overflow might not work everywhere
Bram Moolenaar <Bram@vim.org>
parents:
25913
diff
changeset
|
1022 if (typebuf.tb_len > 2147483647 - extra) |
7 | 1023 { |
26125
18114bb393e0
patch 8.2.3595: check for signed overflow might not work everywhere
Bram Moolenaar <Bram@vim.org>
parents:
25913
diff
changeset
|
1024 // string is getting too long for a 32 bit int |
26436
ef0c07cbf53f
patch 8.2.3749: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
26224
diff
changeset
|
1025 emsg(_(e_command_too_complex)); // also calls flush_buffers |
7 | 1026 setcursor(); |
1027 return FAIL; | |
1028 } | |
26125
18114bb393e0
patch 8.2.3595: check for signed overflow might not work everywhere
Bram Moolenaar <Bram@vim.org>
parents:
25913
diff
changeset
|
1029 newlen = typebuf.tb_len + extra; |
7 | 1030 s1 = alloc(newlen); |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1031 if (s1 == NULL) // out of memory |
7 | 1032 return FAIL; |
1033 s2 = alloc(newlen); | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1034 if (s2 == NULL) // out of memory |
7 | 1035 { |
1036 vim_free(s1); | |
1037 return FAIL; | |
1038 } | |
1039 typebuf.tb_buflen = newlen; | |
1040 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1041 // copy the old chars, before the insertion point |
7 | 1042 mch_memmove(s1 + newoff, typebuf.tb_buf + typebuf.tb_off, |
1043 (size_t)offset); | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1044 // copy the new chars |
7 | 1045 mch_memmove(s1 + newoff + offset, str, (size_t)addlen); |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1046 // copy the old chars, after the insertion point, including the NUL at |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1047 // the end |
7 | 1048 mch_memmove(s1 + newoff + offset + addlen, |
1049 typebuf.tb_buf + typebuf.tb_off + offset, | |
1050 (size_t)(typebuf.tb_len - offset + 1)); | |
1051 if (typebuf.tb_buf != typebuf_init) | |
1052 vim_free(typebuf.tb_buf); | |
1053 typebuf.tb_buf = s1; | |
1054 | |
1055 mch_memmove(s2 + newoff, typebuf.tb_noremap + typebuf.tb_off, | |
1056 (size_t)offset); | |
1057 mch_memmove(s2 + newoff + offset + addlen, | |
1058 typebuf.tb_noremap + typebuf.tb_off + offset, | |
1059 (size_t)(typebuf.tb_len - offset)); | |
1060 if (typebuf.tb_noremap != noremapbuf_init) | |
1061 vim_free(typebuf.tb_noremap); | |
1062 typebuf.tb_noremap = s2; | |
1063 | |
1064 typebuf.tb_off = newoff; | |
1065 } | |
1066 typebuf.tb_len += addlen; | |
1067 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1068 // If noremap == REMAP_SCRIPT: do remap script-local mappings. |
7 | 1069 if (noremap == REMAP_SCRIPT) |
1070 val = RM_SCRIPT; | |
10 | 1071 else if (noremap == REMAP_SKIP) |
1072 val = RM_ABBR; | |
7 | 1073 else |
1074 val = RM_NONE; | |
1075 | |
1076 /* | |
1077 * Adjust typebuf.tb_noremap[] for the new characters: | |
1078 * If noremap == REMAP_NONE or REMAP_SCRIPT: new characters are | |
1079 * (sometimes) not remappable | |
1080 * If noremap == REMAP_YES: all the new characters are mappable | |
1081 * If noremap > 0: "noremap" characters are not remappable, the rest | |
1082 * mappable | |
1083 */ | |
10 | 1084 if (noremap == REMAP_SKIP) |
1085 nrm = 1; | |
1086 else if (noremap < 0) | |
7 | 1087 nrm = addlen; |
1088 else | |
1089 nrm = noremap; | |
1090 for (i = 0; i < addlen; ++i) | |
1091 typebuf.tb_noremap[typebuf.tb_off + i + offset] = | |
1092 (--nrm >= 0) ? val : RM_YES; | |
1093 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1094 // tb_maplen and tb_silent only remember the length of mapped and/or |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1095 // silent mappings at the start of the buffer, assuming that a mapped |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1096 // sequence doesn't result in typed characters. |
7 | 1097 if (nottyped || typebuf.tb_maplen > offset) |
1098 typebuf.tb_maplen += addlen; | |
1099 if (silent || typebuf.tb_silent > offset) | |
1100 { | |
1101 typebuf.tb_silent += addlen; | |
1102 cmd_silent = TRUE; | |
1103 } | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1104 if (typebuf.tb_no_abbr_cnt && offset == 0) // and not used for abbrev.s |
7 | 1105 typebuf.tb_no_abbr_cnt += addlen; |
1106 | |
1107 return OK; | |
1108 } | |
1109 | |
1110 /* | |
852 | 1111 * Put character "c" back into the typeahead buffer. |
1112 * Can be used for a character obtained by vgetc() that needs to be put back. | |
1051 | 1113 * Uses cmd_silent, KeyTyped and KeyNoremap to restore the flags belonging to |
1114 * the char. | |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1115 * Returns the length of what was inserted. |
852 | 1116 */ |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1117 int |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1118 ins_char_typebuf(int c, int modifier) |
852 | 1119 { |
26946
8d4b44cc324e
patch 8.2.4002: first char typed in Select mode can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
26944
diff
changeset
|
1120 char_u buf[MB_MAXBYTES * 3 + 4]; |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1121 int len = 0; |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1122 |
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1123 if (modifier != 0) |
852 | 1124 { |
1125 buf[0] = K_SPECIAL; | |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1126 buf[1] = KS_MODIFIER; |
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1127 buf[2] = modifier; |
852 | 1128 buf[3] = NUL; |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1129 len = 3; |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1130 } |
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1131 if (IS_SPECIAL(c)) |
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1132 { |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1133 buf[len] = K_SPECIAL; |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1134 buf[len + 1] = K_SECOND(c); |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1135 buf[len + 2] = K_THIRD(c); |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1136 buf[len + 3] = NUL; |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1137 len += 3; |
852 | 1138 } |
1139 else | |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1140 { |
27748
49b667252942
patch 8.2.4400: MS-Windows: cannot use the mouse in the console with VIMDLL
Bram Moolenaar <Bram@vim.org>
parents:
27736
diff
changeset
|
1141 char_u *end = add_char2buf(c, buf + len); |
49b667252942
patch 8.2.4400: MS-Windows: cannot use the mouse in the console with VIMDLL
Bram Moolenaar <Bram@vim.org>
parents:
27736
diff
changeset
|
1142 *end = NUL; |
49b667252942
patch 8.2.4400: MS-Windows: cannot use the mouse in the console with VIMDLL
Bram Moolenaar <Bram@vim.org>
parents:
27736
diff
changeset
|
1143 len = end - buf; |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1144 } |
1051 | 1145 (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent); |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1146 return len; |
852 | 1147 } |
1148 | |
1149 /* | |
7 | 1150 * Return TRUE if the typeahead buffer was changed (while waiting for a |
841 | 1151 * character to arrive). Happens when a message was received from a client or |
842 | 1152 * from feedkeys(). |
7 | 1153 * But check in a more generic way to avoid trouble: When "typebuf.tb_buf" |
1154 * changed it was reallocated and the old pointer can no longer be used. | |
1155 * Or "typebuf.tb_off" may have been changed and we would overwrite characters | |
1156 * that was just added. | |
1157 */ | |
1158 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1159 typebuf_changed( |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1160 int tb_change_cnt) // old value of typebuf.tb_change_cnt |
7 | 1161 { |
1162 return (tb_change_cnt != 0 && (typebuf.tb_change_cnt != tb_change_cnt | |
841 | 1163 #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
1164 || typebuf_was_filled | |
7 | 1165 #endif |
1166 )); | |
1167 } | |
1168 | |
1169 /* | |
1170 * Return TRUE if there are no characters in the typeahead buffer that have | |
1171 * not been typed (result from a mapping or come from ":normal"). | |
1172 */ | |
1173 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1174 typebuf_typed(void) |
7 | 1175 { |
1176 return typebuf.tb_maplen == 0; | |
1177 } | |
1178 | |
1179 /* | |
1180 * Return the number of characters that are mapped (or not typed). | |
1181 */ | |
1182 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1183 typebuf_maplen(void) |
7 | 1184 { |
1185 return typebuf.tb_maplen; | |
1186 } | |
1187 | |
1188 /* | |
1189 * remove "len" characters from typebuf.tb_buf[typebuf.tb_off + offset] | |
1190 */ | |
1191 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1192 del_typebuf(int len, int offset) |
7 | 1193 { |
1194 int i; | |
1195 | |
1196 if (len == 0) | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1197 return; // nothing to do |
7 | 1198 |
1199 typebuf.tb_len -= len; | |
1200 | |
1201 /* | |
1202 * Easy case: Just increase typebuf.tb_off. | |
1203 */ | |
1204 if (offset == 0 && typebuf.tb_buflen - (typebuf.tb_off + len) | |
1205 >= 3 * MAXMAPLEN + 3) | |
1206 typebuf.tb_off += len; | |
1207 /* | |
1208 * Have to move the characters in typebuf.tb_buf[] and typebuf.tb_noremap[] | |
1209 */ | |
1210 else | |
1211 { | |
1212 i = typebuf.tb_off + offset; | |
1213 /* | |
1214 * Leave some extra room at the end to avoid reallocation. | |
1215 */ | |
1216 if (typebuf.tb_off > MAXMAPLEN) | |
1217 { | |
1218 mch_memmove(typebuf.tb_buf + MAXMAPLEN, | |
1219 typebuf.tb_buf + typebuf.tb_off, (size_t)offset); | |
1220 mch_memmove(typebuf.tb_noremap + MAXMAPLEN, | |
1221 typebuf.tb_noremap + typebuf.tb_off, (size_t)offset); | |
1222 typebuf.tb_off = MAXMAPLEN; | |
1223 } | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1224 // adjust typebuf.tb_buf (include the NUL at the end) |
7 | 1225 mch_memmove(typebuf.tb_buf + typebuf.tb_off + offset, |
1226 typebuf.tb_buf + i + len, | |
1227 (size_t)(typebuf.tb_len - offset + 1)); | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1228 // adjust typebuf.tb_noremap[] |
7 | 1229 mch_memmove(typebuf.tb_noremap + typebuf.tb_off + offset, |
1230 typebuf.tb_noremap + i + len, | |
1231 (size_t)(typebuf.tb_len - offset)); | |
1232 } | |
1233 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1234 if (typebuf.tb_maplen > offset) // adjust tb_maplen |
7 | 1235 { |
1236 if (typebuf.tb_maplen < offset + len) | |
1237 typebuf.tb_maplen = offset; | |
1238 else | |
1239 typebuf.tb_maplen -= len; | |
1240 } | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1241 if (typebuf.tb_silent > offset) // adjust tb_silent |
7 | 1242 { |
1243 if (typebuf.tb_silent < offset + len) | |
1244 typebuf.tb_silent = offset; | |
1245 else | |
1246 typebuf.tb_silent -= len; | |
1247 } | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1248 if (typebuf.tb_no_abbr_cnt > offset) // adjust tb_no_abbr_cnt |
7 | 1249 { |
1250 if (typebuf.tb_no_abbr_cnt < offset + len) | |
1251 typebuf.tb_no_abbr_cnt = offset; | |
1252 else | |
1253 typebuf.tb_no_abbr_cnt -= len; | |
1254 } | |
1255 | |
841 | 1256 #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1257 // Reset the flag that text received from a client or from feedkeys() |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1258 // was inserted in the typeahead buffer. |
841 | 1259 typebuf_was_filled = FALSE; |
7 | 1260 #endif |
1261 if (++typebuf.tb_change_cnt == 0) | |
1262 typebuf.tb_change_cnt = 1; | |
1263 } | |
1264 | |
1265 /* | |
1266 * Write typed characters to script file. | |
1267 * If recording is on put the character in the recordbuffer. | |
1268 */ | |
1269 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1270 gotchars(char_u *chars, int len) |
7 | 1271 { |
14247
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1272 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
|
1273 int i; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1274 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
|
1275 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
|
1276 int todo = len; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1277 |
1130 | 1278 while (todo--) |
7 | 1279 { |
14247
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1280 buf[buflen++] = *s++; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1281 |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1282 // 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
|
1283 // 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
|
1284 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
|
1285 continue; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1286 if (buflen == 2) |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1287 continue; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1288 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
|
1289 && (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
|
1290 { |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1291 // 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
|
1292 // recording. |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1293 buflen = 0; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1294 continue; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1295 } |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1296 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1297 // 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
|
1298 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
|
1299 updatescript(buf[i]); |
7 | 1300 |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13950
diff
changeset
|
1301 if (reg_recording != 0) |
7 | 1302 { |
14247
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1303 buf[buflen] = NUL; |
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1304 add_buff(&recordbuff, buf, (long)buflen); |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1305 // remember how many chars were last recorded |
14247
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1306 last_recorded_len += buflen; |
7 | 1307 } |
14247
381b01f77461
patch 8.1.0140: recording into a register has focus events
Christian Brabandt <cb@256bit.org>
parents:
14069
diff
changeset
|
1308 buflen = 0; |
7 | 1309 } |
1310 may_sync_undo(); | |
1311 | |
1312 #ifdef FEAT_EVAL | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1313 // output "debug mode" message next time in debug mode |
7 | 1314 debug_did_msg = FALSE; |
1315 #endif | |
1316 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1317 // Since characters have been typed, consider the following to be in |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1318 // another mapping. Search string will be kept in history. |
7 | 1319 ++maptick; |
1320 } | |
1321 | |
1322 /* | |
26929
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1323 * Undo the last gotchars() for "len" bytes. To be used when putting a typed |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1324 * character back into the typeahead buffer, thus gotchars() will be called |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1325 * again. |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1326 * Only affects recorded characters. |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1327 */ |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1328 void |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1329 ungetchars(int len) |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1330 { |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1331 if (reg_recording != 0) |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1332 { |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1333 delete_buff_tail(&recordbuff, len); |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1334 last_recorded_len -= len; |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1335 } |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1336 } |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1337 |
9975bd408d6c
patch 8.2.3993: when recording a change in Select mode char appears twice
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1338 /* |
7 | 1339 * Sync undo. Called when typed characters are obtained from the typeahead |
1340 * buffer, or when a menu is used. | |
1341 * Do not sync: | |
1342 * - In Insert mode, unless cursor key has been used. | |
1343 * - While reading a script file. | |
1344 * - When no_u_sync is non-zero. | |
1345 */ | |
1346 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1347 may_sync_undo(void) |
7 | 1348 { |
1349 if ((!(State & (INSERT + CMDLINE)) || arrow_used) | |
825 | 1350 && scriptin[curscript] == NULL) |
1351 u_sync(FALSE); | |
7 | 1352 } |
1353 | |
1354 /* | |
1355 * Make "typebuf" empty and allocate new buffers. | |
1356 * Returns FAIL when out of memory. | |
1357 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17659
diff
changeset
|
1358 static int |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1359 alloc_typebuf(void) |
7 | 1360 { |
1361 typebuf.tb_buf = alloc(TYPELEN_INIT); | |
1362 typebuf.tb_noremap = alloc(TYPELEN_INIT); | |
1363 if (typebuf.tb_buf == NULL || typebuf.tb_noremap == NULL) | |
1364 { | |
1365 free_typebuf(); | |
1366 return FAIL; | |
1367 } | |
1368 typebuf.tb_buflen = TYPELEN_INIT; | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1369 typebuf.tb_off = MAXMAPLEN + 4; // can insert without realloc |
7 | 1370 typebuf.tb_len = 0; |
1371 typebuf.tb_maplen = 0; | |
1372 typebuf.tb_silent = 0; | |
1373 typebuf.tb_no_abbr_cnt = 0; | |
1374 if (++typebuf.tb_change_cnt == 0) | |
1375 typebuf.tb_change_cnt = 1; | |
19627
6b1564fcab92
patch 8.2.0370: the typebuf_was_filled flag is sometimes not reset
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
1376 #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
6b1564fcab92
patch 8.2.0370: the typebuf_was_filled flag is sometimes not reset
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
1377 typebuf_was_filled = FALSE; |
6b1564fcab92
patch 8.2.0370: the typebuf_was_filled flag is sometimes not reset
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
1378 #endif |
7 | 1379 return OK; |
1380 } | |
1381 | |
1382 /* | |
1383 * Free the buffers of "typebuf". | |
1384 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17659
diff
changeset
|
1385 static void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1386 free_typebuf(void) |
7 | 1387 { |
1462 | 1388 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
|
1389 internal_error("Free typebuf 1"); |
1462 | 1390 else |
18193
f31b0ac6e175
patch 8.1.2091: double free when memory allocation fails
Bram Moolenaar <Bram@vim.org>
parents:
18116
diff
changeset
|
1391 VIM_CLEAR(typebuf.tb_buf); |
1992 | 1392 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
|
1393 internal_error("Free typebuf 2"); |
1462 | 1394 else |
18193
f31b0ac6e175
patch 8.1.2091: double free when memory allocation fails
Bram Moolenaar <Bram@vim.org>
parents:
18116
diff
changeset
|
1395 VIM_CLEAR(typebuf.tb_noremap); |
7 | 1396 } |
1397 | |
1398 /* | |
1399 * When doing ":so! file", the current typeahead needs to be saved, and | |
1400 * restored when "file" has been read completely. | |
1401 */ | |
1402 static typebuf_T saved_typebuf[NSCRIPT]; | |
1403 | |
1404 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1405 save_typebuf(void) |
7 | 1406 { |
1407 init_typebuf(); | |
1408 saved_typebuf[curscript] = typebuf; | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1409 // If out of memory: restore typebuf and close file. |
7 | 1410 if (alloc_typebuf() == FAIL) |
1411 { | |
1412 closescript(); | |
1413 return FAIL; | |
1414 } | |
1415 return OK; | |
1416 } | |
1417 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1418 static int old_char = -1; // character put back by vungetc() |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1419 static int old_mod_mask; // mod_mask for ungotten character |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1420 static int old_mouse_row; // mouse_row related to old_char |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1421 static int old_mouse_col; // mouse_col related to old_char |
28333
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
1422 static int old_KeyStuffed; // whether old_char was stuffed |
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
1423 |
28359
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
1424 static int can_get_old_char(void) |
28333
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
1425 { |
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
1426 // If the old character was not stuffed and characters have been added to |
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
1427 // the stuff buffer, need to first get the stuffed characters instead. |
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
1428 return old_char != -1 && (old_KeyStuffed || stuff_empty()); |
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
1429 } |
1928 | 1430 |
7 | 1431 /* |
1432 * Save all three kinds of typeahead, so that the user must type at a prompt. | |
1433 */ | |
1434 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1435 save_typeahead(tasave_T *tp) |
7 | 1436 { |
1437 tp->save_typebuf = typebuf; | |
1438 tp->typebuf_valid = (alloc_typebuf() == OK); | |
1439 if (!tp->typebuf_valid) | |
1440 typebuf = tp->save_typebuf; | |
1441 | |
1928 | 1442 tp->old_char = old_char; |
1443 tp->old_mod_mask = old_mod_mask; | |
1444 old_char = -1; | |
1445 | |
5649 | 1446 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
|
1447 readbuf1.bh_first.b_next = NULL; |
5649 | 1448 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
|
1449 readbuf2.bh_first.b_next = NULL; |
7 | 1450 # ifdef USE_INPUT_BUF |
1451 tp->save_inputbuf = get_input_buf(); | |
1452 # endif | |
1453 } | |
1454 | |
1455 /* | |
1456 * Restore the typeahead to what it was before calling save_typeahead(). | |
1457 * The allocated memory is freed, can only be called once! | |
24846
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24838
diff
changeset
|
1458 * When "overwrite" is FALSE input typed later is kept. |
7 | 1459 */ |
1460 void | |
24846
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24838
diff
changeset
|
1461 restore_typeahead(tasave_T *tp, int overwrite UNUSED) |
7 | 1462 { |
1463 if (tp->typebuf_valid) | |
1464 { | |
1465 free_typebuf(); | |
1466 typebuf = tp->save_typebuf; | |
1467 } | |
1468 | |
1928 | 1469 old_char = tp->old_char; |
1470 old_mod_mask = tp->old_mod_mask; | |
1471 | |
5649 | 1472 free_buff(&readbuf1); |
1473 readbuf1 = tp->save_readbuf1; | |
1474 free_buff(&readbuf2); | |
1475 readbuf2 = tp->save_readbuf2; | |
7 | 1476 # ifdef USE_INPUT_BUF |
24846
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24838
diff
changeset
|
1477 set_input_buf(tp->save_inputbuf, overwrite); |
7 | 1478 # endif |
1479 } | |
1480 | |
1481 /* | |
1482 * Open a new script file for the ":source!" command. | |
1483 */ | |
1484 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1485 openscript( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1486 char_u *name, |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1487 int directly) // when TRUE execute directly |
7 | 1488 { |
1489 if (curscript + 1 == NSCRIPT) | |
1490 { | |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24846
diff
changeset
|
1491 emsg(_(e_scripts_nested_too_deep)); |
7 | 1492 return; |
1493 } | |
16726
fbab59a5ee6b
patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents:
16712
diff
changeset
|
1494 |
fbab59a5ee6b
patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents:
16712
diff
changeset
|
1495 // 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
|
1496 // 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
|
1497 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
|
1498 return; |
fbab59a5ee6b
patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents:
16712
diff
changeset
|
1499 |
1462 | 1500 #ifdef FEAT_EVAL |
1501 if (ignore_script) | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1502 // Not reading from script, also don't open one. Warning message? |
1462 | 1503 return; |
1504 #endif | |
7 | 1505 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1506 if (scriptin[curscript] != NULL) // already reading script |
7 | 1507 ++curscript; |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1508 // use NameBuff for expanded name |
7 | 1509 expand_env(name, NameBuff, MAXPATHL); |
1510 if ((scriptin[curscript] = mch_fopen((char *)NameBuff, READBIN)) == NULL) | |
1511 { | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26875
diff
changeset
|
1512 semsg(_(e_cant_open_file_str), name); |
7 | 1513 if (curscript) |
1514 --curscript; | |
1515 return; | |
1516 } | |
1517 if (save_typebuf() == FAIL) | |
1518 return; | |
1519 | |
1520 /* | |
1521 * Execute the commands from the file right now when using ":source!" | |
1522 * after ":global" or ":argdo" or in a loop. Also when another command | |
1523 * follows. This means the display won't be updated. Don't do this | |
1524 * always, "make test" would fail. | |
1525 */ | |
1526 if (directly) | |
1527 { | |
1528 oparg_T oa; | |
1529 int oldcurscript; | |
1530 int save_State = State; | |
1531 int save_restart_edit = restart_edit; | |
1532 int save_insertmode = p_im; | |
1533 int save_finish_op = finish_op; | |
1534 int save_msg_scroll = msg_scroll; | |
1535 | |
1536 State = NORMAL; | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1537 msg_scroll = FALSE; // no msg scrolling in Normal mode |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1538 restart_edit = 0; // don't go to Insert mode |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1539 p_im = FALSE; // don't use 'insertmode' |
7 | 1540 clear_oparg(&oa); |
1541 finish_op = FALSE; | |
1542 | |
1543 oldcurscript = curscript; | |
1544 do | |
1545 { | |
16712
329e28ed10fd
patch 8.1.1358: cannot enter character with a CSI byte
Bram Moolenaar <Bram@vim.org>
parents:
16531
diff
changeset
|
1546 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
|
1547 normal_cmd(&oa, FALSE); // execute one command |
21230
e67123c115d2
patch 8.2.1166: once mouse move events are enabled getchar() returns them
Bram Moolenaar <Bram@vim.org>
parents:
20800
diff
changeset
|
1548 (void)vpeekc(); // check for end of file |
7 | 1549 } |
1550 while (scriptin[oldcurscript] != NULL); | |
1551 | |
1552 State = save_State; | |
1553 msg_scroll = save_msg_scroll; | |
1554 restart_edit = save_restart_edit; | |
1555 p_im = save_insertmode; | |
1556 finish_op = save_finish_op; | |
1557 } | |
1558 } | |
1559 | |
1560 /* | |
1561 * Close the currently active input script. | |
1562 */ | |
1563 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1564 closescript(void) |
7 | 1565 { |
1566 free_typebuf(); | |
1567 typebuf = saved_typebuf[curscript]; | |
1568 | |
1569 fclose(scriptin[curscript]); | |
1570 scriptin[curscript] = NULL; | |
1571 if (curscript > 0) | |
1572 --curscript; | |
1573 } | |
1574 | |
358 | 1575 #if defined(EXITFREE) || defined(PROTO) |
1576 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1577 close_all_scripts(void) |
358 | 1578 { |
1579 while (scriptin[0] != NULL) | |
1580 closescript(); | |
1581 } | |
1582 #endif | |
1583 | |
7 | 1584 /* |
1585 * Return TRUE when reading keys from a script file. | |
1586 */ | |
1587 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1588 using_script(void) |
7 | 1589 { |
1590 return scriptin[curscript] != NULL; | |
1591 } | |
1592 | |
1593 /* | |
365 | 1594 * This function is called just before doing a blocking wait. Thus after |
1595 * waiting 'updatetime' for a character to arrive. | |
1596 */ | |
1597 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1598 before_blocking(void) |
365 | 1599 { |
1600 updatescript(0); | |
1601 #ifdef FEAT_EVAL | |
958 | 1602 if (may_garbage_collect) |
8881
ed0b39dd7fd6
commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
1603 garbage_collect(FALSE); |
365 | 1604 #endif |
1605 } | |
1606 | |
1607 /* | |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18412
diff
changeset
|
1608 * updatescript() is called when a character can be written into the script file |
7 | 1609 * or when we have waited some time for a character (c == 0) |
1610 * | |
1611 * All the changed memfiles are synced if c == 0 or when the number of typed | |
1612 * characters reaches 'updatecount' and 'updatecount' is non-zero. | |
1613 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17659
diff
changeset
|
1614 static void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1615 updatescript(int c) |
7 | 1616 { |
1617 static int count = 0; | |
1618 | |
1619 if (c && scriptout) | |
1620 putc(c, scriptout); | |
1621 if (c == 0 || (p_uc > 0 && ++count >= p_uc)) | |
1622 { | |
1623 ml_sync_all(c == 0, TRUE); | |
1624 count = 0; | |
1625 } | |
1626 } | |
1627 | |
1628 /* | |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
1629 * Convert "c" plus "modifiers" to merge the effect of modifyOtherKeys into the |
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
|
1630 * 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
|
1631 */ |
14d2a210fab1
patch 8.1.2350: other text for CTRL-V in Insert mode with modifyOtherKeys
Bram Moolenaar <Bram@vim.org>
parents:
18689
diff
changeset
|
1632 int |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
1633 merge_modifyOtherKeys(int c_arg, int *modifiers) |
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
|
1634 { |
14d2a210fab1
patch 8.1.2350: other text for CTRL-V in Insert mode with modifyOtherKeys
Bram Moolenaar <Bram@vim.org>
parents:
18689
diff
changeset
|
1635 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
|
1636 |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
1637 if (*modifiers & MOD_MASK_CTRL) |
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
|
1638 { |
14d2a210fab1
patch 8.1.2350: other text for CTRL-V in Insert mode with modifyOtherKeys
Bram Moolenaar <Bram@vim.org>
parents:
18689
diff
changeset
|
1639 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
|
1640 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
|
1641 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
|
1642 // 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
|
1643 c = 0x1e; |
20595
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1644 #ifdef FEAT_GUI_GTK |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1645 // These mappings look arbitrary at the first glance, but in fact |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1646 // resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1647 // machine. The only difference is BS vs. DEL for CTRL-8 (makes |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1648 // more sense and is consistent with usual terminal behaviour). |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1649 else if (c == '2') |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1650 c = NUL; |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1651 else if (c >= '3' && c <= '7') |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1652 c = c ^ 0x28; |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1653 else if (c == '8') |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1654 c = BS; |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1655 else if (c == '?') |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1656 c = DEL; |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1657 #endif |
3609e842f822
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1658 if (c != c_arg) |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
1659 *modifiers &= ~MOD_MASK_CTRL; |
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
|
1660 } |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
1661 if ((*modifiers & (MOD_MASK_META | MOD_MASK_ALT)) |
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
|
1662 && 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
|
1663 { |
14d2a210fab1
patch 8.1.2350: other text for CTRL-V in Insert mode with modifyOtherKeys
Bram Moolenaar <Bram@vim.org>
parents:
18689
diff
changeset
|
1664 c += 0x80; |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
1665 *modifiers &= ~(MOD_MASK_META|MOD_MASK_ALT); |
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
|
1666 } |
14d2a210fab1
patch 8.1.2350: other text for CTRL-V in Insert mode with modifyOtherKeys
Bram Moolenaar <Bram@vim.org>
parents:
18689
diff
changeset
|
1667 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
|
1668 } |
14d2a210fab1
patch 8.1.2350: other text for CTRL-V in Insert mode with modifyOtherKeys
Bram Moolenaar <Bram@vim.org>
parents:
18689
diff
changeset
|
1669 |
14d2a210fab1
patch 8.1.2350: other text for CTRL-V in Insert mode with modifyOtherKeys
Bram Moolenaar <Bram@vim.org>
parents:
18689
diff
changeset
|
1670 /* |
7 | 1671 * Get the next input character. |
1672 * Can return a special key or a multi-byte character. | |
1673 * Can return NUL when called recursively, use safe_vgetc() if that's not | |
1674 * wanted. | |
1675 * This translates escaped K_SPECIAL and CSI bytes to a K_SPECIAL or CSI byte. | |
1676 * Collects the bytes of a multibyte character into the whole character. | |
1992 | 1677 * Returns the modifiers in the global "mod_mask". |
7 | 1678 */ |
1679 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1680 vgetc(void) |
7 | 1681 { |
1682 int c, c2; | |
1683 int n; | |
3549 | 1684 char_u buf[MB_MAXBYTES + 1]; |
7 | 1685 int i; |
1686 | |
958 | 1687 #ifdef FEAT_EVAL |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1688 // Do garbage collection when garbagecollect() was called previously and |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1689 // we are now at the toplevel. |
958 | 1690 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
|
1691 garbage_collect(FALSE); |
958 | 1692 #endif |
1693 | |
7 | 1694 /* |
1695 * If a character was put back with vungetc, it was already processed. | |
1696 * Return it directly. | |
1697 */ | |
28333
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
1698 if (can_get_old_char()) |
7 | 1699 { |
1700 c = old_char; | |
1701 old_char = -1; | |
1702 mod_mask = old_mod_mask; | |
4227 | 1703 mouse_row = old_mouse_row; |
1704 mouse_col = old_mouse_col; | |
7 | 1705 } |
958 | 1706 else |
7 | 1707 { |
28395
a0cd2b7a78ef
patch 8.2.4722: ending recording with mapping records too much
Bram Moolenaar <Bram@vim.org>
parents:
28359
diff
changeset
|
1708 // number of characters recorded from the last vgetc() call |
a0cd2b7a78ef
patch 8.2.4722: ending recording with mapping records too much
Bram Moolenaar <Bram@vim.org>
parents:
28359
diff
changeset
|
1709 static int last_vgetc_recorded_len = 0; |
a0cd2b7a78ef
patch 8.2.4722: ending recording with mapping records too much
Bram Moolenaar <Bram@vim.org>
parents:
28359
diff
changeset
|
1710 |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1711 mod_mask = 0; |
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1712 vgetc_mod_mask = 0; |
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1713 vgetc_char = 0; |
28395
a0cd2b7a78ef
patch 8.2.4722: ending recording with mapping records too much
Bram Moolenaar <Bram@vim.org>
parents:
28359
diff
changeset
|
1714 |
a0cd2b7a78ef
patch 8.2.4722: ending recording with mapping records too much
Bram Moolenaar <Bram@vim.org>
parents:
28359
diff
changeset
|
1715 // last_recorded_len can be larger than last_vgetc_recorded_len |
a0cd2b7a78ef
patch 8.2.4722: ending recording with mapping records too much
Bram Moolenaar <Bram@vim.org>
parents:
28359
diff
changeset
|
1716 // if peeking records more |
a0cd2b7a78ef
patch 8.2.4722: ending recording with mapping records too much
Bram Moolenaar <Bram@vim.org>
parents:
28359
diff
changeset
|
1717 last_recorded_len -= last_vgetc_recorded_len; |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1718 |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1719 for (;;) // this is done twice if there are modifiers |
7 | 1720 { |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1721 int did_inc = FALSE; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1722 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1723 if (mod_mask |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1724 #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
|
1725 || im_is_preediting() |
7 | 1726 #endif |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18717
diff
changeset
|
1727 #if defined(FEAT_PROP_POPUP) |
17604
506dd2efcbb2
patch 8.1.1799: cannot avoid mapping for a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17602
diff
changeset
|
1728 || popup_no_mapping() |
506dd2efcbb2
patch 8.1.1799: cannot avoid mapping for a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17602
diff
changeset
|
1729 #endif |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1730 ) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1731 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1732 // no mapping after modifier has been read |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1733 ++no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1734 ++allow_keys; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1735 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
|
1736 } |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
1737 c = vgetorpeek(TRUE); |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1738 if (did_inc) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1739 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1740 --no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1741 --allow_keys; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1742 } |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1743 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1744 // Get two extra bytes for special keys |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1745 if (c == K_SPECIAL |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1746 #ifdef FEAT_GUI |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1747 || (c == CSI) |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1748 #endif |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1749 ) |
7 | 1750 { |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1751 int save_allow_keys = allow_keys; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1752 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1753 ++no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1754 allow_keys = 0; // make sure BS is not found |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
1755 c2 = vgetorpeek(TRUE); // no mapping for these chars |
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
1756 c = vgetorpeek(TRUE); |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1757 --no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1758 allow_keys = save_allow_keys; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1759 if (c2 == KS_MODIFIER) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1760 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1761 mod_mask = c; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1762 continue; |
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 c = TO_SPECIAL(c2, c); |
7 | 1765 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1766 #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
|
1767 // 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
|
1768 // 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
|
1769 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
|
1770 # 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
|
1771 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
|
1772 # 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
|
1773 c == K_TEAROFF) |
7 | 1774 { |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1775 char_u name[200]; |
27523
4c7bb6fd383f
patch 8.2.4289: warnings reported by MSVC
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1776 int j; |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1777 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1778 // get menu path, it ends with a <CR> |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
1779 for (j = 0; (c = vgetorpeek(TRUE)) != '\r'; ) |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1780 { |
27523
4c7bb6fd383f
patch 8.2.4289: warnings reported by MSVC
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1781 name[j] = c; |
4c7bb6fd383f
patch 8.2.4289: warnings reported by MSVC
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1782 if (j < 199) |
4c7bb6fd383f
patch 8.2.4289: warnings reported by MSVC
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1783 ++j; |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1784 } |
27523
4c7bb6fd383f
patch 8.2.4289: warnings reported by MSVC
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1785 name[j] = NUL; |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1786 gui_make_tearoff(name); |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1787 continue; |
7 | 1788 } |
1789 #endif | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1790 #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
|
1791 // 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
|
1792 // 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
|
1793 // behavior if it's not mapped. |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1794 if (c == K_F10 && gui.menubar != NULL) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1795 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1796 gtk_menu_shell_select_first( |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1797 GTK_MENU_SHELL(gui.menubar), FALSE); |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1798 continue; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1799 } |
36 | 1800 #endif |
7 | 1801 #ifdef FEAT_GUI |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1802 // Handle focus event here, so that the caller doesn't need to |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1803 // know about it. Return K_IGNORE so that we loop once (needed |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1804 // if 'lazyredraw' is set). |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1805 if (c == K_FOCUSGAINED || c == K_FOCUSLOST) |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1806 { |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1807 ui_focus_change(c == K_FOCUSGAINED); |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1808 c = K_IGNORE; |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1809 } |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1810 |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1811 // Translate K_CSI to CSI. The special key is only used to |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1812 // avoid it being recognized as the start of a special key. |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1813 if (c == K_CSI) |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1814 c = CSI; |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1815 #endif |
1380 | 1816 } |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1817 // 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
|
1818 // its ASCII equivalent |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1819 switch (c) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1820 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1821 case K_KPLUS: c = '+'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1822 case K_KMINUS: c = '-'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1823 case K_KDIVIDE: c = '/'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1824 case K_KMULTIPLY: c = '*'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1825 case K_KENTER: c = CAR; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1826 case K_KPOINT: |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1827 #ifdef MSWIN |
14403
e29cbac5e8f6
patch 8.1.0216: part of file not indented properly
Christian Brabandt <cb@256bit.org>
parents:
14247
diff
changeset
|
1828 // 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
|
1829 // 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
|
1830 c = MapVirtualKey(VK_DECIMAL, 2); break; |
36 | 1831 #else |
14403
e29cbac5e8f6
patch 8.1.0216: part of file not indented properly
Christian Brabandt <cb@256bit.org>
parents:
14247
diff
changeset
|
1832 c = '.'; break; |
36 | 1833 #endif |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1834 case K_K0: c = '0'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1835 case K_K1: c = '1'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1836 case K_K2: c = '2'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1837 case K_K3: c = '3'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1838 case K_K4: c = '4'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1839 case K_K5: c = '5'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1840 case K_K6: c = '6'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1841 case K_K7: c = '7'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1842 case K_K8: c = '8'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1843 case K_K9: c = '9'; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1844 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1845 case K_XHOME: |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1846 case K_ZHOME: if (mod_mask == MOD_MASK_SHIFT) |
229 | 1847 { |
1848 c = K_S_HOME; | |
1849 mod_mask = 0; | |
1850 } | |
1851 else if (mod_mask == MOD_MASK_CTRL) | |
1852 { | |
1853 c = K_C_HOME; | |
1854 mod_mask = 0; | |
1855 } | |
1856 else | |
1857 c = K_HOME; | |
1858 break; | |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1859 case K_XEND: |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1860 case K_ZEND: if (mod_mask == MOD_MASK_SHIFT) |
229 | 1861 { |
1862 c = K_S_END; | |
1863 mod_mask = 0; | |
1864 } | |
1865 else if (mod_mask == MOD_MASK_CTRL) | |
1866 { | |
1867 c = K_C_END; | |
1868 mod_mask = 0; | |
1869 } | |
1870 else | |
1871 c = K_END; | |
1872 break; | |
1873 | |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1874 case K_XUP: c = K_UP; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1875 case K_XDOWN: c = K_DOWN; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1876 case K_XLEFT: c = K_LEFT; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1877 case K_XRIGHT: c = K_RIGHT; break; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1878 } |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1879 |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1880 // 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
|
1881 // converted character. |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1882 // 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
|
1883 if (has_mbyte && (n = MB_BYTE2LEN_CHECK(c)) > 1) |
7 | 1884 { |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1885 ++no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1886 buf[0] = c; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1887 for (i = 1; i < n; ++i) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1888 { |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
1889 buf[i] = vgetorpeek(TRUE); |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1890 if (buf[i] == K_SPECIAL |
7 | 1891 #ifdef FEAT_GUI |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19433
diff
changeset
|
1892 || (buf[i] == CSI) |
7 | 1893 #endif |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1894 ) |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1895 { |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1896 // 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
|
1897 // sequence, which represents a K_SPECIAL (0x80), |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1898 // 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
|
1899 // represents a CSI (0x9B), |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1900 // 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
|
1901 // too. |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
1902 c = vgetorpeek(TRUE); |
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
1903 if (vgetorpeek(TRUE) == KE_CSI && c == KS_EXTRA) |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1904 buf[i] = CSI; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1905 } |
7 | 1906 } |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1907 --no_mapping; |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1908 c = (*mb_ptr2char)(buf); |
7 | 1909 } |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1910 |
20733
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
1911 if (vgetc_char == 0) |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1912 { |
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1913 vgetc_mod_mask = mod_mask; |
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1914 vgetc_char = c; |
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
1915 } |
18281
c67268c0398e
patch 8.1.2135: with modifyOtherKeys Alt-a does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
1916 |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1917 break; |
7 | 1918 } |
28395
a0cd2b7a78ef
patch 8.2.4722: ending recording with mapping records too much
Bram Moolenaar <Bram@vim.org>
parents:
28359
diff
changeset
|
1919 |
a0cd2b7a78ef
patch 8.2.4722: ending recording with mapping records too much
Bram Moolenaar <Bram@vim.org>
parents:
28359
diff
changeset
|
1920 last_vgetc_recorded_len = last_recorded_len; |
7 | 1921 } |
958 | 1922 |
1923 #ifdef FEAT_EVAL | |
1924 /* | |
1925 * In the main loop "may_garbage_collect" can be set to do garbage | |
1926 * collection in the first next vgetc(). It's disabled after that to | |
1927 * avoid internally used Lists and Dicts to be freed. | |
1928 */ | |
1929 may_garbage_collect = FALSE; | |
1930 #endif | |
18102
0d9ec3a2821f
patch 8.1.2046: SafeState may be triggered at the wrong moment
Bram Moolenaar <Bram@vim.org>
parents:
18094
diff
changeset
|
1931 |
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
|
1932 #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
|
1933 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
|
1934 { |
18102
0d9ec3a2821f
patch 8.1.2046: SafeState may be triggered at the wrong moment
Bram Moolenaar <Bram@vim.org>
parents:
18094
diff
changeset
|
1935 // 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
|
1936 bevalexpr_due_set = FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1937 ui_remove_balloon(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1938 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1939 #endif |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18717
diff
changeset
|
1940 #ifdef FEAT_PROP_POPUP |
22442
73be82f278c0
patch 8.2.1769: popup filter interferes with using :normal to move the cursor
Bram Moolenaar <Bram@vim.org>
parents:
22361
diff
changeset
|
1941 // Only filter keys that do not come from ":normal". Keys from feedkeys() |
73be82f278c0
patch 8.2.1769: popup filter interferes with using :normal to move the cursor
Bram Moolenaar <Bram@vim.org>
parents:
22361
diff
changeset
|
1942 // are filtered. |
73be82f278c0
patch 8.2.1769: popup filter interferes with using :normal to move the cursor
Bram Moolenaar <Bram@vim.org>
parents:
22361
diff
changeset
|
1943 if ((!ex_normal_busy || in_feedkeys) && 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
|
1944 { |
25535ef50842
patch 8.1.2110: CTRL-C closes two popups instead of one
Bram Moolenaar <Bram@vim.org>
parents:
18193
diff
changeset
|
1945 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
|
1946 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
|
1947 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
|
1948 } |
16880
998603a243d7
patch 8.1.1441: popup window filter not yet implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1949 #endif |
958 | 1950 |
18102
0d9ec3a2821f
patch 8.1.2046: SafeState may be triggered at the wrong moment
Bram Moolenaar <Bram@vim.org>
parents:
18094
diff
changeset
|
1951 // 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
|
1952 // else. |
0d9ec3a2821f
patch 8.1.2046: SafeState may be triggered at the wrong moment
Bram Moolenaar <Bram@vim.org>
parents:
18094
diff
changeset
|
1953 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
|
1954 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
|
1955 |
958 | 1956 return c; |
7 | 1957 } |
1958 | |
1959 /* | |
1960 * Like vgetc(), but never return a NUL when called recursively, get a key | |
1961 * directly from the user (ignoring typeahead). | |
1962 */ | |
1963 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1964 safe_vgetc(void) |
7 | 1965 { |
1966 int c; | |
1967 | |
1968 c = vgetc(); | |
1969 if (c == NUL) | |
1970 c = get_keystroke(); | |
1971 return c; | |
1972 } | |
1973 | |
1974 /* | |
1389 | 1975 * Like safe_vgetc(), but loop to handle K_IGNORE. |
1976 * Also ignore scrollbar events. | |
1977 */ | |
1978 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1979 plain_vgetc(void) |
1389 | 1980 { |
1981 int c; | |
1982 | |
1983 do | |
1984 c = safe_vgetc(); | |
24588
826ba03d0d22
patch 8.2.2833: two key command cancelled by moving mouse when using popup
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
1985 while (c == K_IGNORE |
826ba03d0d22
patch 8.2.2833: two key command cancelled by moving mouse when using popup
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
1986 || c == K_VER_SCROLLBAR || c == K_HOR_SCROLLBAR |
826ba03d0d22
patch 8.2.2833: two key command cancelled by moving mouse when using popup
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
1987 || c == K_MOUSEMOVE); |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
1988 |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
1989 if (c == K_PS) |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1990 // Only handle the first pasted character. Drop the rest, since we |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1991 // don't know what to do with it. |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10549
diff
changeset
|
1992 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
|
1993 |
1389 | 1994 return c; |
1995 } | |
1996 | |
1997 /* | |
7 | 1998 * Check if a character is available, such that vgetc() will not block. |
1999 * If the next character is a special character or multi-byte, the returned | |
2000 * character is not valid!. | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2001 * Returns NUL if no character is available. |
7 | 2002 */ |
2003 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2004 vpeekc(void) |
7 | 2005 { |
28333
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
2006 if (can_get_old_char()) |
7 | 2007 return old_char; |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
2008 return vgetorpeek(FALSE); |
7 | 2009 } |
2010 | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13210
diff
changeset
|
2011 #if defined(FEAT_TERMRESPONSE) || defined(FEAT_TERMINAL) || defined(PROTO) |
7 | 2012 /* |
2013 * Like vpeekc(), but don't allow mapping. Do allow checking for terminal | |
2014 * codes. | |
2015 */ | |
2016 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2017 vpeekc_nomap(void) |
7 | 2018 { |
2019 int c; | |
2020 | |
2021 ++no_mapping; | |
2022 ++allow_keys; | |
2023 c = vpeekc(); | |
2024 --no_mapping; | |
2025 --allow_keys; | |
2026 return c; | |
2027 } | |
2028 #endif | |
2029 | |
2030 /* | |
2031 * Check if any character is available, also half an escape sequence. | |
2032 * Trick: when no typeahead found, but there is something in the typeahead | |
2033 * buffer, it must be an ESC that is recognized as the start of a key code. | |
2034 */ | |
2035 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2036 vpeekc_any(void) |
7 | 2037 { |
2038 int c; | |
2039 | |
2040 c = vpeekc(); | |
2041 if (c == NUL && typebuf.tb_len > 0) | |
2042 c = ESC; | |
2043 return c; | |
2044 } | |
2045 | |
2046 /* | |
2047 * Call vpeekc() without causing anything to be mapped. | |
2048 * Return TRUE if a character is available, FALSE otherwise. | |
2049 */ | |
2050 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2051 char_avail(void) |
7 | 2052 { |
2053 int retval; | |
2054 | |
8011
26f555e9aab1
commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents:
7860
diff
changeset
|
2055 #ifdef FEAT_EVAL |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2056 // When test_override("char_avail", 1) was called pretend there is no |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2057 // typeahead. |
8011
26f555e9aab1
commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents:
7860
diff
changeset
|
2058 if (disable_char_avail_for_testing) |
26f555e9aab1
commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents:
7860
diff
changeset
|
2059 return FALSE; |
26f555e9aab1
commit https://github.com/vim/vim/commit/2ab375e54ef4eac438d1aef8b99d9e71f2fa0c63
Christian Brabandt <cb@256bit.org>
parents:
7860
diff
changeset
|
2060 #endif |
7 | 2061 ++no_mapping; |
2062 retval = vpeekc(); | |
2063 --no_mapping; | |
2064 return (retval != NUL); | |
2065 } | |
2066 | |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2067 #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
|
2068 /* |
24838
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2069 * "getchar()" and "getcharstr()" functions |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2070 */ |
24838
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2071 static void |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2072 getchar_common(typval_T *argvars, typval_T *rettv) |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2073 { |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2074 varnumber_T n; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2075 int error = FALSE; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2076 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
2077 if (in_vim9script() && check_for_opt_bool_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
2078 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
2079 |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2080 #ifdef MESSAGE_QUEUE |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2081 // 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
|
2082 // 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
|
2083 // 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
|
2084 parse_queued_messages(); |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2085 #endif |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2086 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2087 // Position the cursor. Needed after a message that ends in a space. |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2088 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
|
2089 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2090 ++no_mapping; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2091 ++allow_keys; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2092 for (;;) |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2093 { |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2094 if (argvars[0].v_type == VAR_UNKNOWN) |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2095 // getchar(): blocking wait. |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2096 n = plain_vgetc(); |
22107
679269735ec3
patch 8.2.1603: Vim9: cannot use "true" with getchar()
Bram Moolenaar <Bram@vim.org>
parents:
21654
diff
changeset
|
2097 else if (tv_get_bool_chk(&argvars[0], &error)) |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2098 // getchar(1): only check if char avail |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2099 n = vpeekc_any(); |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2100 else if (error || vpeekc_any() == NUL) |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2101 // illegal argument or getchar(0) and no char avail: return zero |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2102 n = 0; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2103 else |
22117
3ea773da9c4f
patch 8.2.1608: Vim9: getchar() test fails with GUI
Bram Moolenaar <Bram@vim.org>
parents:
22107
diff
changeset
|
2104 // getchar(0) and char avail() != NUL: get a character. |
3ea773da9c4f
patch 8.2.1608: Vim9: getchar() test fails with GUI
Bram Moolenaar <Bram@vim.org>
parents:
22107
diff
changeset
|
2105 // Note that vpeekc_any() returns K_SPECIAL for K_IGNORE. |
3ea773da9c4f
patch 8.2.1608: Vim9: getchar() test fails with GUI
Bram Moolenaar <Bram@vim.org>
parents:
22107
diff
changeset
|
2106 n = safe_vgetc(); |
3ea773da9c4f
patch 8.2.1608: Vim9: getchar() test fails with GUI
Bram Moolenaar <Bram@vim.org>
parents:
22107
diff
changeset
|
2107 |
3ea773da9c4f
patch 8.2.1608: Vim9: getchar() test fails with GUI
Bram Moolenaar <Bram@vim.org>
parents:
22107
diff
changeset
|
2108 if (n == K_IGNORE || n == K_MOUSEMOVE |
3ea773da9c4f
patch 8.2.1608: Vim9: getchar() test fails with GUI
Bram Moolenaar <Bram@vim.org>
parents:
22107
diff
changeset
|
2109 || n == K_VER_SCROLLBAR || n == K_HOR_SCROLLBAR) |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2110 continue; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2111 break; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2112 } |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2113 --no_mapping; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2114 --allow_keys; |
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 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
|
2117 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
|
2118 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
|
2119 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
|
2120 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2121 rettv->vval.v_number = n; |
27802
9b01fea87065
patch 8.2.4427: getchar() may return modifiers if no character is available
Bram Moolenaar <Bram@vim.org>
parents:
27752
diff
changeset
|
2122 if (n != 0 && (IS_SPECIAL(n) || mod_mask != 0)) |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2123 { |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2124 char_u temp[10]; // modifier: 3, mbyte-char: 6, NUL: 1 |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2125 int i = 0; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2126 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2127 // Turn a special key into three bytes, plus modifier. |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2128 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
|
2129 { |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2130 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
|
2131 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
|
2132 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
|
2133 } |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2134 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
|
2135 { |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2136 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
|
2137 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
|
2138 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
|
2139 } |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2140 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
|
2141 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
|
2142 else |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2143 temp[i++] = n; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2144 temp[i++] = NUL; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2145 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
|
2146 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
|
2147 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2148 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
|
2149 { |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2150 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
|
2151 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
|
2152 win_T *win; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2153 linenr_T lnum; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2154 win_T *wp; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2155 int winnr = 1; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2156 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2157 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
|
2158 { |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2159 // Find the window at the mouse coordinates and compute the |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2160 // text position. |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2161 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
|
2162 if (win == NULL) |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2163 return; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2164 (void)mouse_comp_pos(win, &row, &col, &lnum, NULL); |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18717
diff
changeset
|
2165 #ifdef FEAT_PROP_POPUP |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2166 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
|
2167 winnr = 0; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2168 else |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
2169 #endif |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2170 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
|
2171 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
|
2172 ++winnr; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2173 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
|
2174 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
|
2175 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
|
2176 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
|
2177 } |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2178 } |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2179 } |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2180 } |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2181 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2182 /* |
24838
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2183 * "getchar()" function |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2184 */ |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2185 void |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2186 f_getchar(typval_T *argvars, typval_T *rettv) |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2187 { |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2188 getchar_common(argvars, rettv); |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2189 } |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2190 |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2191 /* |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2192 * "getcharstr()" function |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2193 */ |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2194 void |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2195 f_getcharstr(typval_T *argvars, typval_T *rettv) |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2196 { |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2197 getchar_common(argvars, rettv); |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2198 |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2199 if (rettv->v_type == VAR_NUMBER) |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2200 { |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2201 char_u temp[7]; // mbyte-char: 6, NUL: 1 |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2202 varnumber_T n = rettv->vval.v_number; |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2203 int i = 0; |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2204 |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2205 if (n != 0) |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2206 { |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2207 if (has_mbyte) |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2208 i += (*mb_char2bytes)(n, temp + i); |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2209 else |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2210 temp[i++] = n; |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2211 } |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2212 temp[i++] = NUL; |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2213 rettv->v_type = VAR_STRING; |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2214 rettv->vval.v_string = vim_strsave(temp); |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2215 } |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2216 } |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2217 |
3f9053c21765
patch 8.2.2957: using getchar() in Vim9 script is problematic
Bram Moolenaar <Bram@vim.org>
parents:
24588
diff
changeset
|
2218 /* |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2219 * "getcharmod()" function |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2220 */ |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2221 void |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2222 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
|
2223 { |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2224 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
|
2225 } |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2226 #endif // FEAT_EVAL |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2227 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2228 #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
|
2229 # 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
|
2230 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2231 /* |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2232 * 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
|
2233 * Also check if any jobs have ended. |
25881
2ee0425960fe
patch 8.2.3474: some places use "Vimscript" instead of "Vim script"
Bram Moolenaar <Bram@vim.org>
parents:
25852
diff
changeset
|
2234 * These functions can call arbitrary Vim script and should only be called when |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2235 * 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
|
2236 */ |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2237 void |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2238 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
|
2239 { |
18412
6208e5c2eee7
patch 8.1.2200: crash when memory allocation fails
Bram Moolenaar <Bram@vim.org>
parents:
18394
diff
changeset
|
2240 int old_curwin_id; |
6208e5c2eee7
patch 8.1.2200: crash when memory allocation fails
Bram Moolenaar <Bram@vim.org>
parents:
18394
diff
changeset
|
2241 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
|
2242 int i; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2243 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
|
2244 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
|
2245 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
|
2246 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2247 // 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
|
2248 // change or be wiped while they are being redrawn. |
22800
8e7cbf73c3a0
patch 8.2.1948: GUI: crash when handling message while closing a window
Bram Moolenaar <Bram@vim.org>
parents:
22442
diff
changeset
|
2249 // Also bail out when parsing messages was explicitly disabled. |
8e7cbf73c3a0
patch 8.2.1948: GUI: crash when handling message while closing a window
Bram Moolenaar <Bram@vim.org>
parents:
22442
diff
changeset
|
2250 if (updating_screen || dont_parse_messages) |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2251 return; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2252 |
18412
6208e5c2eee7
patch 8.1.2200: crash when memory allocation fails
Bram Moolenaar <Bram@vim.org>
parents:
18394
diff
changeset
|
2253 // 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
|
2254 // curwin could be NULL. |
6208e5c2eee7
patch 8.1.2200: crash when memory allocation fails
Bram Moolenaar <Bram@vim.org>
parents:
18394
diff
changeset
|
2255 if (curbuf == NULL || curwin == NULL) |
6208e5c2eee7
patch 8.1.2200: crash when memory allocation fails
Bram Moolenaar <Bram@vim.org>
parents:
18394
diff
changeset
|
2256 return; |
6208e5c2eee7
patch 8.1.2200: crash when memory allocation fails
Bram Moolenaar <Bram@vim.org>
parents:
18394
diff
changeset
|
2257 |
6208e5c2eee7
patch 8.1.2200: crash when memory allocation fails
Bram Moolenaar <Bram@vim.org>
parents:
18394
diff
changeset
|
2258 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
|
2259 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
|
2260 |
18102
0d9ec3a2821f
patch 8.1.2046: SafeState may be triggered at the wrong moment
Bram Moolenaar <Bram@vim.org>
parents:
18094
diff
changeset
|
2261 ++entered; |
0d9ec3a2821f
patch 8.1.2046: SafeState may be triggered at the wrong moment
Bram Moolenaar <Bram@vim.org>
parents:
18094
diff
changeset
|
2262 |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2263 // 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
|
2264 // 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
|
2265 // 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
|
2266 // 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
|
2267 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
|
2268 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2269 // 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
|
2270 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
|
2271 { |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2272 // For Win32 mch_breakcheck() does not check for input, do it here. |
20277
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2273 # if (defined(MSWIN) || defined(__HAIKU__)) && defined(FEAT_JOB_CHANNEL) |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2274 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
|
2275 # endif |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2276 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2277 # 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
|
2278 // 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
|
2279 netbeans_parse_messages(); |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2280 # endif |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2281 # 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
|
2282 // 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
|
2283 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
|
2284 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2285 // 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
|
2286 channel_parse_messages(); |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2287 # endif |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2288 # 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
|
2289 // 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
|
2290 server_parse_messages(); |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2291 # endif |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2292 # 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
|
2293 // 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
|
2294 // 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
|
2295 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
|
2296 continue; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2297 # endif |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2298 # ifdef FEAT_TERMINAL |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2299 free_unused_terminals(); |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2300 # endif |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2301 # 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
|
2302 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
|
2303 invoke_sound_callback(); |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2304 # endif |
20800
e76b83c07bd8
patch 8.2.0952: no simple way to interrupt Vim
Bram Moolenaar <Bram@vim.org>
parents:
20733
diff
changeset
|
2305 #ifdef SIGUSR1 |
e76b83c07bd8
patch 8.2.0952: no simple way to interrupt Vim
Bram Moolenaar <Bram@vim.org>
parents:
20733
diff
changeset
|
2306 if (got_sigusr1) |
e76b83c07bd8
patch 8.2.0952: no simple way to interrupt Vim
Bram Moolenaar <Bram@vim.org>
parents:
20733
diff
changeset
|
2307 { |
e76b83c07bd8
patch 8.2.0952: no simple way to interrupt Vim
Bram Moolenaar <Bram@vim.org>
parents:
20733
diff
changeset
|
2308 apply_autocmds(EVENT_SIGUSR1, NULL, NULL, FALSE, curbuf); |
e76b83c07bd8
patch 8.2.0952: no simple way to interrupt Vim
Bram Moolenaar <Bram@vim.org>
parents:
20733
diff
changeset
|
2309 got_sigusr1 = FALSE; |
e76b83c07bd8
patch 8.2.0952: no simple way to interrupt Vim
Bram Moolenaar <Bram@vim.org>
parents:
20733
diff
changeset
|
2310 } |
e76b83c07bd8
patch 8.2.0952: no simple way to interrupt Vim
Bram Moolenaar <Bram@vim.org>
parents:
20733
diff
changeset
|
2311 #endif |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2312 break; |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2313 } |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2314 |
18102
0d9ec3a2821f
patch 8.1.2046: SafeState may be triggered at the wrong moment
Bram Moolenaar <Bram@vim.org>
parents:
18094
diff
changeset
|
2315 // 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
|
2316 // 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
|
2317 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
|
2318 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
|
2319 |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2320 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
|
2321 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2322 // 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
|
2323 // 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
|
2324 if (curwin->w_id != old_curwin_id || curbuf->b_fnum != old_curbuf_fnum) |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20563
diff
changeset
|
2325 ins_char_typebuf(K_IGNORE, 0); |
18102
0d9ec3a2821f
patch 8.1.2046: SafeState may be triggered at the wrong moment
Bram Moolenaar <Bram@vim.org>
parents:
18094
diff
changeset
|
2326 |
0d9ec3a2821f
patch 8.1.2046: SafeState may be triggered at the wrong moment
Bram Moolenaar <Bram@vim.org>
parents:
18094
diff
changeset
|
2327 --entered; |
18094
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2328 } |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2329 #endif |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2330 |
a1396a35444c
patch 8.1.2042: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2331 |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2332 typedef enum { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2333 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
|
2334 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
|
2335 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
|
2336 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
|
2337 } map_result_T; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2338 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2339 /* |
18394
084b28fb3d22
patch 8.1.2191: when using modifyOtherKeys CTRL-X mode may not work
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
2340 * 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
|
2341 * 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
|
2342 */ |
084b28fb3d22
patch 8.1.2191: when using modifyOtherKeys CTRL-X mode may not work
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
2343 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
|
2344 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
|
2345 { |
084b28fb3d22
patch 8.1.2191: when using modifyOtherKeys CTRL-X mode may not work
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
2346 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
|
2347 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
|
2348 |
084b28fb3d22
patch 8.1.2191: when using modifyOtherKeys CTRL-X mode may not work
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
2349 if (typebuf.tb_len > 3 |
27954
3de9be15de51
patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents:
27946
diff
changeset
|
2350 && (c == K_SPECIAL || c == CSI) // CSI is used by the GUI |
18394
084b28fb3d22
patch 8.1.2191: when using modifyOtherKeys CTRL-X mode may not work
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
2351 && 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
|
2352 && (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
|
2353 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
|
2354 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
|
2355 } |
084b28fb3d22
patch 8.1.2191: when using modifyOtherKeys CTRL-X mode may not work
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
2356 |
084b28fb3d22
patch 8.1.2191: when using modifyOtherKeys CTRL-X mode may not work
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
2357 /* |
23229
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23076
diff
changeset
|
2358 * Check if typebuf.tb_buf[] contains a modifier plus key that can be changed |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2359 * into just a key, apply that. |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2360 * Check from typebuf.tb_buf[typebuf.tb_off] to typebuf.tb_buf[typebuf.tb_off |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2361 * + "max_offset"]. |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2362 * Return the length of the replaced bytes, zero if nothing changed. |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2363 */ |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2364 static int |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2365 check_simplify_modifier(int max_offset) |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2366 { |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2367 int offset; |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2368 char_u *tp; |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2369 |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2370 for (offset = 0; offset < max_offset; ++offset) |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2371 { |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2372 if (offset + 3 >= typebuf.tb_len) |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2373 break; |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2374 tp = typebuf.tb_buf + typebuf.tb_off + offset; |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2375 if (tp[0] == K_SPECIAL && tp[1] == KS_MODIFIER) |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2376 { |
20733
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2377 // A modifier was not used for a mapping, apply it to ASCII keys. |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2378 // Shift would already have been applied. |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2379 int modifier = tp[2]; |
20733
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2380 int c = tp[3]; |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2381 int new_c = merge_modifyOtherKeys(c, &modifier); |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2382 |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2383 if (new_c != c) |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2384 { |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2385 char_u new_string[MB_MAXBYTES]; |
20733
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2386 int len; |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2387 |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2388 if (offset == 0) |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2389 { |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2390 // At the start: remember the character and mod_mask before |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2391 // merging, in some cases, e.g. at the hit-return prompt, |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2392 // they are put back in the typeahead buffer. |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2393 vgetc_char = c; |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2394 vgetc_mod_mask = tp[2]; |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2395 } |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2396 len = mb_char2bytes(new_c, new_string); |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2397 if (modifier == 0) |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2398 { |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2399 if (put_string_in_typebuf(offset, 4, new_string, len, |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2400 NULL, 0, 0) == FAIL) |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2401 return -1; |
20733
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2402 } |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2403 else |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2404 { |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2405 tp[2] = modifier; |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2406 if (put_string_in_typebuf(offset + 3, 1, new_string, len, |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2407 NULL, 0, 0) == FAIL) |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2408 return -1; |
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2409 } |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2410 return len; |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2411 } |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2412 } |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2413 } |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2414 return 0; |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2415 } |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2416 |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2417 /* |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2418 * 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
|
2419 * - 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
|
2420 * - 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
|
2421 * - 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
|
2422 * typeahead. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2423 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2424 static int |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2425 handle_mapping( |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2426 int *keylenp, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2427 int *timedout, |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2428 int *mapdepth) |
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 mapblock_T *mp = NULL; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2431 mapblock_T *mp2; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2432 mapblock_T *mp_match; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2433 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
|
2434 int max_mlen = 0; |
28127
b9e8f3674090
patch 8.2.4588: mapping with key after other matching mapping does not work
Bram Moolenaar <Bram@vim.org>
parents:
28053
diff
changeset
|
2435 int want_termcode = 0; // 1 if termcode expected after max_mlen |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2436 int tb_c1; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2437 int mlen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2438 #ifdef FEAT_LANGMAP |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2439 int nolmaplen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2440 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2441 int keylen = *keylenp; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2442 int i; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2443 int local_State = get_real_state(); |
27946
5147f3d3ed30
patch 8.2.4498: using <Plug> with "noremap" does not work
Bram Moolenaar <Bram@vim.org>
parents:
27802
diff
changeset
|
2444 int is_plug_map = FALSE; |
5147f3d3ed30
patch 8.2.4498: using <Plug> with "noremap" does not work
Bram Moolenaar <Bram@vim.org>
parents:
27802
diff
changeset
|
2445 |
5147f3d3ed30
patch 8.2.4498: using <Plug> with "noremap" does not work
Bram Moolenaar <Bram@vim.org>
parents:
27802
diff
changeset
|
2446 // If typehead starts with <Plug> then remap, even for a "noremap" mapping. |
5147f3d3ed30
patch 8.2.4498: using <Plug> with "noremap" does not work
Bram Moolenaar <Bram@vim.org>
parents:
27802
diff
changeset
|
2447 if (typebuf.tb_buf[typebuf.tb_off] == K_SPECIAL |
5147f3d3ed30
patch 8.2.4498: using <Plug> with "noremap" does not work
Bram Moolenaar <Bram@vim.org>
parents:
27802
diff
changeset
|
2448 && typebuf.tb_buf[typebuf.tb_off + 1] == KS_EXTRA |
5147f3d3ed30
patch 8.2.4498: using <Plug> with "noremap" does not work
Bram Moolenaar <Bram@vim.org>
parents:
27802
diff
changeset
|
2449 && typebuf.tb_buf[typebuf.tb_off + 2] == KE_PLUG) |
5147f3d3ed30
patch 8.2.4498: using <Plug> with "noremap" does not work
Bram Moolenaar <Bram@vim.org>
parents:
27802
diff
changeset
|
2450 is_plug_map = TRUE; |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2451 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2452 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2453 * 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
|
2454 * 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
|
2455 * |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2456 * 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
|
2457 * - 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
|
2458 * - 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
|
2459 * - 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
|
2460 * - 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
|
2461 * - 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
|
2462 * - 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
|
2463 * - 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
|
2464 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2465 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
|
2466 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
|
2467 && (no_zero_mapping == 0 || tb_c1 != '0') |
27946
5147f3d3ed30
patch 8.2.4498: using <Plug> with "noremap" does not work
Bram Moolenaar <Bram@vim.org>
parents:
27802
diff
changeset
|
2468 && (typebuf.tb_maplen == 0 || is_plug_map |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2469 || (p_remap |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2470 && (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
|
2471 & (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
|
2472 && !(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
|
2473 && !(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
|
2474 && State != ASKMORE |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2475 && 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
|
2476 && !((ctrl_x_mode_not_default() && at_ctrl_x_key()) |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26929
diff
changeset
|
2477 || (compl_status_local() |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2478 && (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
|
2479 { |
20563
a5a24d688e11
patch 8.2.0835: Motif: mapping <C-bslash> still doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2480 #ifdef FEAT_GUI |
a5a24d688e11
patch 8.2.0835: Motif: mapping <C-bslash> still doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2481 if (gui.in_use && tb_c1 == CSI && typebuf.tb_len >= 2 |
a5a24d688e11
patch 8.2.0835: Motif: mapping <C-bslash> still doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2482 && typebuf.tb_buf[typebuf.tb_off + 1] == KS_MODIFIER) |
a5a24d688e11
patch 8.2.0835: Motif: mapping <C-bslash> still doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2483 { |
a5a24d688e11
patch 8.2.0835: Motif: mapping <C-bslash> still doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2484 // The GUI code sends CSI KS_MODIFIER {flags}, but mappings expect |
a5a24d688e11
patch 8.2.0835: Motif: mapping <C-bslash> still doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2485 // K_SPECIAL KS_MODIFIER {flags}. |
a5a24d688e11
patch 8.2.0835: Motif: mapping <C-bslash> still doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2486 tb_c1 = K_SPECIAL; |
a5a24d688e11
patch 8.2.0835: Motif: mapping <C-bslash> still doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2487 } |
a5a24d688e11
patch 8.2.0835: Motif: mapping <C-bslash> still doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2488 #endif |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2489 #ifdef FEAT_LANGMAP |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2490 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
|
2491 nolmaplen = 2; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2492 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2493 { |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2494 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
|
2495 && 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
|
2496 nolmaplen = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2497 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2498 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2499 // 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
|
2500 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
|
2501 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
|
2502 if (mp == NULL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2503 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2504 // 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
|
2505 mp = mp2; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2506 mp2 = NULL; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2507 } |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2508 |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2509 /* |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2510 * 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
|
2511 * 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
|
2512 * 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
|
2513 * 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
|
2514 * 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
|
2515 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2516 mp_match = NULL; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2517 mp_match_len = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2518 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
|
2519 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
|
2520 { |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2521 // 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
|
2522 // 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
|
2523 // 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
|
2524 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
|
2525 && (mp->m_mode & local_State) |
20701
fbee68c6aab1
patch 8.2.0904: assuming modifyOtherKeys for rhs of mapping
Bram Moolenaar <Bram@vim.org>
parents:
20595
diff
changeset
|
2526 && !(mp->m_simplified && seenModifyOtherKeys |
fbee68c6aab1
patch 8.2.0904: assuming modifyOtherKeys for rhs of mapping
Bram Moolenaar <Bram@vim.org>
parents:
20595
diff
changeset
|
2527 && typebuf.tb_maplen == 0) |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2528 && ((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
|
2529 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2530 #ifdef FEAT_LANGMAP |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2531 int nomap = nolmaplen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2532 int c2; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2533 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2534 // 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
|
2535 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
|
2536 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2537 #ifdef FEAT_LANGMAP |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2538 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
|
2539 if (nomap > 0) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2540 --nomap; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2541 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
|
2542 nomap = 2; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2543 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2544 LANGMAP_ADJUST(c2, TRUE); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2545 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
|
2546 #else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2547 if (mp->m_keys[mlen] != |
20563
a5a24d688e11
patch 8.2.0835: Motif: mapping <C-bslash> still doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2548 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
|
2549 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2550 break; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2551 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2552 |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2553 // 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
|
2554 // 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
|
2555 // 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
|
2556 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2557 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
|
2558 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
|
2559 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2560 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
|
2561 && 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
|
2562 mlen = 0; |
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 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2565 // 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
|
2566 // - Full match: mlen == keylen |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2567 // - 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
|
2568 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
|
2569 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
|
2570 && 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
|
2571 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2572 char_u *s; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2573 int n; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2574 |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2575 // 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
|
2576 // 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
|
2577 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
|
2578 if (*s == RM_SCRIPT |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2579 && (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
|
2580 || mp->m_keys[1] != KS_EXTRA |
25852
336e2d9924e6
patch 8.2.3460: some type casts are not needed
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
2581 || mp->m_keys[2] != KE_SNR)) |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2582 continue; |
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 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
|
2585 // entry. |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2586 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
|
2587 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
|
2588 break; |
27946
5147f3d3ed30
patch 8.2.4498: using <Plug> with "noremap" does not work
Bram Moolenaar <Bram@vim.org>
parents:
27802
diff
changeset
|
2589 if (!is_plug_map && n >= 0) |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2590 continue; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2591 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2592 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
|
2593 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2594 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
|
2595 && 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
|
2596 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2597 // 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
|
2598 keylen = KEYLEN_PART_MAP; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2599 break; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2600 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2601 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2602 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
|
2603 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2604 // found a longer match |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2605 mp_match = mp; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2606 mp_match_len = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2607 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2608 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2609 else |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2610 // No match; may have to check for termcode at next |
28127
b9e8f3674090
patch 8.2.4588: mapping with key after other matching mapping does not work
Bram Moolenaar <Bram@vim.org>
parents:
28053
diff
changeset
|
2611 // character. If the first character that didn't match is |
b9e8f3674090
patch 8.2.4588: mapping with key after other matching mapping does not work
Bram Moolenaar <Bram@vim.org>
parents:
28053
diff
changeset
|
2612 // K_SPECIAL then check for a termcode. This isn't perfect |
b9e8f3674090
patch 8.2.4588: mapping with key after other matching mapping does not work
Bram Moolenaar <Bram@vim.org>
parents:
28053
diff
changeset
|
2613 // but should work in most cases. |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2614 if (max_mlen < mlen) |
28127
b9e8f3674090
patch 8.2.4588: mapping with key after other matching mapping does not work
Bram Moolenaar <Bram@vim.org>
parents:
28053
diff
changeset
|
2615 { |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2616 max_mlen = mlen; |
28127
b9e8f3674090
patch 8.2.4588: mapping with key after other matching mapping does not work
Bram Moolenaar <Bram@vim.org>
parents:
28053
diff
changeset
|
2617 want_termcode = mp->m_keys[mlen] == K_SPECIAL; |
b9e8f3674090
patch 8.2.4588: mapping with key after other matching mapping does not work
Bram Moolenaar <Bram@vim.org>
parents:
28053
diff
changeset
|
2618 } |
b9e8f3674090
patch 8.2.4588: mapping with key after other matching mapping does not work
Bram Moolenaar <Bram@vim.org>
parents:
28053
diff
changeset
|
2619 else if (max_mlen == mlen && mp->m_keys[mlen] == K_SPECIAL) |
b9e8f3674090
patch 8.2.4588: mapping with key after other matching mapping does not work
Bram Moolenaar <Bram@vim.org>
parents:
28053
diff
changeset
|
2620 want_termcode = 1; |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2621 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2622 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2623 |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2624 // If no partly match found, use the longest full match. |
27958
ac7db4437368
patch 8.2.4504: when there is a partially matching map full map may not work
Bram Moolenaar <Bram@vim.org>
parents:
27954
diff
changeset
|
2625 if (keylen != KEYLEN_PART_MAP && mp_match != NULL) |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2626 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2627 mp = mp_match; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2628 keylen = mp_match_len; |
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 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2632 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2633 * 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
|
2634 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2635 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
|
2636 { |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2637 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
|
2638 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
|
2639 break; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2640 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
|
2641 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2642 // 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
|
2643 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
|
2644 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
|
2645 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
|
2646 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2647 del_typebuf(mlen, 0); // remove the chars |
28457
4dcccb2673fe
patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
28395
diff
changeset
|
2648 set_option_value_give_err((char_u *)"paste", |
4dcccb2673fe
patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
28395
diff
changeset
|
2649 (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
|
2650 if (!(State & INSERT)) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2651 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2652 msg_col = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2653 msg_row = Rows - 1; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2654 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
|
2655 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2656 status_redraw_all(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2657 redraw_statuslines(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2658 showmode(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2659 setcursor(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2660 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2661 return map_result_retry; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2662 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2663 // 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
|
2664 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
|
2665 keylen = KEYLEN_PART_KEY; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2666 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
|
2667 // 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
|
2668 max_mlen = mlen + 1; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2669 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2670 |
28053
f615d89a5351
patch 8.2.4551: when mapping <Esc> terminal codes are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
27958
diff
changeset
|
2671 // May check for a terminal code when there is no mapping or only a partial |
f615d89a5351
patch 8.2.4551: when mapping <Esc> terminal codes are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
27958
diff
changeset
|
2672 // mapping. Also check if there is a full mapping with <Esc>, unless timed |
f615d89a5351
patch 8.2.4551: when mapping <Esc> terminal codes are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
27958
diff
changeset
|
2673 // out, since that is nearly always a partial match with a terminal code. |
28127
b9e8f3674090
patch 8.2.4588: mapping with key after other matching mapping does not work
Bram Moolenaar <Bram@vim.org>
parents:
28053
diff
changeset
|
2674 if ((mp == NULL || max_mlen + want_termcode > mp_match_len |
28053
f615d89a5351
patch 8.2.4551: when mapping <Esc> terminal codes are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
27958
diff
changeset
|
2675 || (mp_match_len == 1 && *mp->m_keys == ESC && !*timedout)) |
f615d89a5351
patch 8.2.4551: when mapping <Esc> terminal codes are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
27958
diff
changeset
|
2676 && 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
|
2677 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2678 int save_keylen = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2679 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2680 /* |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2681 * 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
|
2682 * 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
|
2683 * 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
|
2684 * - mapping is allowed, |
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2685 * - 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
|
2686 * - 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
|
2687 * - 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
|
2688 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2689 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
|
2690 && (typebuf.tb_maplen == 0 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2691 || (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
|
2692 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
|
2693 && !*timedout) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2694 { |
23076
5fbac68bda23
patch 8.2.2084: CTRL-V U doesn't work to enter a Unicode character
Bram Moolenaar <Bram@vim.org>
parents:
23031
diff
changeset
|
2695 keylen = check_termcode(max_mlen + 1, NULL, 0, NULL); |
5fbac68bda23
patch 8.2.2084: CTRL-V U doesn't work to enter a Unicode character
Bram Moolenaar <Bram@vim.org>
parents:
23031
diff
changeset
|
2696 |
5fbac68bda23
patch 8.2.2084: CTRL-V U doesn't work to enter a Unicode character
Bram Moolenaar <Bram@vim.org>
parents:
23031
diff
changeset
|
2697 // If no termcode matched but 'pastetoggle' matched partially |
5fbac68bda23
patch 8.2.2084: CTRL-V U doesn't work to enter a Unicode character
Bram Moolenaar <Bram@vim.org>
parents:
23031
diff
changeset
|
2698 // it's 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
|
2699 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
|
2700 keylen = KEYLEN_PART_KEY; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2701 |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2702 // If no termcode matched, try to include the modifier into the |
26224
7d66d585bffa
patch 8.2.3643: header for source file is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26125
diff
changeset
|
2703 // key. This is for when modifyOtherKeys is working. |
20733
e3078150144d
patch 8.2.0919: merging modifier for modifyOtherKeys is done twice
Bram Moolenaar <Bram@vim.org>
parents:
20727
diff
changeset
|
2704 if (keylen == 0 && !no_reduce_keys) |
20727
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2705 keylen = check_simplify_modifier(max_mlen + 1); |
5ffe112b1afd
patch 8.2.0916: mapping with partly modifyOtherKeys code does not work
Bram Moolenaar <Bram@vim.org>
parents:
20701
diff
changeset
|
2706 |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2707 // 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
|
2708 // 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
|
2709 // 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
|
2710 // ESC. |
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2711 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
|
2712 keylen = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2713 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2714 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2715 keylen = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2716 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
|
2717 { |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2718 #ifdef AMIGA |
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2719 // 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
|
2720 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
|
2721 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
|
2722 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2723 char_u *s; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2724 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2725 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
|
2726 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
|
2727 && (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
|
2728 ++s) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2729 ; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2730 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
|
2731 { |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2732 del_typebuf( |
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2733 (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
|
2734 // 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
|
2735 shell_resized(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2736 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2737 return map_result_retry; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2738 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2739 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
|
2740 keylen = KEYLEN_PART_KEY; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2741 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2742 if (keylen >= 0) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2743 #endif |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2744 // 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
|
2745 // 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
|
2746 // 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
|
2747 // 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
|
2748 if (mp == NULL) |
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2749 { |
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2750 *keylenp = keylen; |
26592
9f445e07f766
patch 8.2.3825: various comments could be improved
Bram Moolenaar <Bram@vim.org>
parents:
26436
diff
changeset
|
2751 return map_result_get; // get character from typeahead |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2752 } |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2753 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2754 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2755 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
|
2756 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2757 #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
|
2758 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
|
2759 && 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
|
2760 && 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
|
2761 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2762 int idx; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2763 |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2764 // 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
|
2765 // 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
|
2766 // file. |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2767 may_sync_undo(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2768 del_typebuf(3, 0); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2769 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
|
2770 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
|
2771 { |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2772 // 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
|
2773 // 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
|
2774 // back to Select mode. |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2775 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
|
2776 && (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
|
2777 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2778 VIsual_select = FALSE; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2779 (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
|
2780 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
|
2781 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2782 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
|
2783 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
|
2784 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
|
2785 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2786 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2787 #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
|
2788 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2789 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
|
2790 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2791 |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2792 // 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
|
2793 // 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
|
2794 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
|
2795 keylen = KEYLEN_PART_KEY; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2796 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2797 keylen = mp_match_len; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2798 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2799 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2800 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2801 * complete match |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2802 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2803 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
|
2804 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2805 char_u *map_str; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2806 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2807 #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
|
2808 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
|
2809 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
|
2810 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
|
2811 char_u *save_m_keys; |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2812 #else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2813 # 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
|
2814 # 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
|
2815 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2816 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2817 // 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
|
2818 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
|
2819 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
|
2820 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
|
2821 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2822 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
|
2823 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
|
2824 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2825 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2826 * 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
|
2827 * 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
|
2828 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2829 if (++*mapdepth >= p_mmd) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2830 { |
26861
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
2831 emsg(_(e_recursive_mapping)); |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2832 if (State & CMDLINE) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2833 redrawcmdline(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2834 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2835 setcursor(); |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2836 flush_buffers(FLUSH_MINIMAL); |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2837 *mapdepth = 0; // for next one |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2838 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2839 return map_result_fail; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2840 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2841 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2842 /* |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2843 * 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
|
2844 * 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
|
2845 */ |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2846 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
|
2847 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2848 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
|
2849 (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
|
2850 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2851 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2852 #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
|
2853 // 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
|
2854 // 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
|
2855 // making *mp invalid. |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2856 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
|
2857 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
|
2858 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
|
2859 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
|
2860 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2861 /* |
17602
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
2862 * 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
|
2863 * 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
|
2864 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2865 if (mp->m_expr) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2866 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2867 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
|
2868 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
|
2869 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
|
2870 int was_screen_row = screen_cur_row; |
27624
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2871 int prev_did_emsg = did_emsg; |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2872 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2873 vgetc_busy = 0; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2874 may_garbage_collect = FALSE; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2875 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2876 save_m_keys = vim_strsave(mp->m_keys); |
27061
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26946
diff
changeset
|
2877 map_str = eval_map_expr(mp, NUL); |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2878 |
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
|
2879 // 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
|
2880 // 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
|
2881 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
|
2882 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
|
2883 |
27624
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2884 // If an error was displayed and the expression returns an empty |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2885 // string, generate a <Nop> to allow for a redraw. |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2886 if (prev_did_emsg != did_emsg |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2887 && (map_str == NULL || *map_str == NUL)) |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2888 { |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2889 char_u buf[4]; |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2890 |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2891 vim_free(map_str); |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2892 buf[0] = K_SPECIAL; |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2893 buf[1] = KS_EXTRA; |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2894 buf[2] = KE_IGNORE; |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2895 buf[3] = NUL; |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2896 map_str = vim_strsave(buf); |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2897 if (State & CMDLINE) |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2898 { |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2899 // redraw the command below the error |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2900 msg_didout = TRUE; |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2901 if (msg_row < cmdline_row) |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2902 msg_row = cmdline_row; |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2903 redrawcmd(); |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2904 } |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2905 } |
ec52847967d8
patch 8.2.4338: an error from an expression mapping messes up the display
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
2906 |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2907 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
|
2908 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
|
2909 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2910 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2911 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2912 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
|
2913 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2914 /* |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2915 * 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
|
2916 * 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
|
2917 * 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
|
2918 * 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
|
2919 */ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2920 if (map_str == NULL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2921 i = FAIL; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2922 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2923 { |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2924 int noremap; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2925 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2926 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
|
2927 noremap = save_m_noremap; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2928 else if ( |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2929 #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
|
2930 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
|
2931 (size_t)keylen) |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2932 #else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2933 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
|
2934 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2935 != 0) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2936 noremap = REMAP_YES; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2937 else |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2938 noremap = REMAP_SKIP; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2939 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
|
2940 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
|
2941 #ifdef FEAT_EVAL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2942 if (save_m_expr) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2943 vim_free(map_str); |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
2944 last_used_map = mp; |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2945 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2946 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2947 #ifdef FEAT_EVAL |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2948 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
|
2949 #endif |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2950 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2951 if (i == FAIL) |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2952 return map_result_fail; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2953 return map_result_retry; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2954 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2955 |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2956 *keylenp = keylen; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2957 return map_result_nomatch; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2958 } |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
2959 |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2960 /* |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2961 * unget one character (can only be done once!) |
28359
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2962 * If the character was stuffed, vgetc() will get it next time it is called. |
28333
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
2963 * Otherwise vgetc() will only get it when the stuff buffer is empty. |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2964 */ |
7 | 2965 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2966 vungetc(int c) |
7 | 2967 { |
2968 old_char = c; | |
2969 old_mod_mask = mod_mask; | |
4227 | 2970 old_mouse_row = mouse_row; |
2971 old_mouse_col = mouse_col; | |
28333
04310f81143d
patch 8.2.4692: no test for what 8.2.4691 fixes
Bram Moolenaar <Bram@vim.org>
parents:
28331
diff
changeset
|
2972 old_KeyStuffed = KeyStuffed; |
7 | 2973 } |
2974 | |
2975 /* | |
28359
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2976 * When peeking and not getting a character, reg_executing cannot be cleared |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2977 * yet, so set a flag to clear it later. |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2978 */ |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2979 static void |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2980 check_end_reg_executing(int advance) |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2981 { |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2982 if (reg_executing != 0 && (typebuf.tb_maplen == 0 |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2983 || pending_end_reg_executing)) |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2984 { |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2985 if (advance) |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2986 { |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2987 reg_executing = 0; |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2988 pending_end_reg_executing = FALSE; |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2989 } |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2990 else |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2991 pending_end_reg_executing = TRUE; |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2992 } |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2993 |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2994 } |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2995 |
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
2996 /* |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
2997 * Get a byte: |
7 | 2998 * 1. from the stuffbuffer |
2999 * This is used for abbreviated commands like "D" -> "d$". | |
3000 * Also used to redo a command for ".". | |
3001 * 2. from the typeahead buffer | |
3002 * Stores text obtained previously but not used yet. | |
3003 * Also stores the result of mappings. | |
3004 * Also used for the ":normal" command. | |
3005 * 3. from the user | |
3006 * This may do a blocking wait if "advance" is TRUE. | |
3007 * | |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
3008 * if "advance" is TRUE (vgetc()): |
9980
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9898
diff
changeset
|
3009 * Really get the character. |
7 | 3010 * KeyTyped is set to TRUE in the case the user typed the key. |
3011 * KeyStuffed is TRUE if the character comes from the stuff buffer. | |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
3012 * if "advance" is FALSE (vpeekc()): |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3013 * 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
|
3014 * Return NUL if not. |
7 | 3015 * |
3016 * When "no_mapping" is zero, checks for mappings in the current mode. | |
3017 * Only returns one byte (of a multi-byte character). | |
3018 * K_SPECIAL and CSI may be escaped, need to get two more bytes then. | |
3019 */ | |
3020 static int | |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
3021 vgetorpeek(int advance) |
7 | 3022 { |
3023 int c, c1; | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3024 int timedout = FALSE; // waited for more than 1 second |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3025 // for mapping to complete |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3026 int mapdepth = 0; // check for recursive mapping |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3027 int mode_deleted = FALSE; // set when mode has been deleted |
7 | 3028 #ifdef FEAT_CMDL_INFO |
3029 int new_wcol, new_wrow; | |
3030 #endif | |
3031 #ifdef FEAT_GUI | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3032 int shape_changed = FALSE; // adjusted cursor shape |
7 | 3033 #endif |
3034 int n; | |
3035 int old_wcol, old_wrow; | |
202 | 3036 int wait_tb_len; |
7 | 3037 |
3038 /* | |
3039 * This function doesn't work very well when called recursively. This may | |
3040 * happen though, because of: | |
3041 * 1. The call to add_to_showcmd(). char_avail() is then used to check if | |
3042 * there is a character available, which calls this function. In that | |
3043 * case we must return NUL, to indicate no character is available. | |
3044 * 2. A GUI callback function writes to the screen, causing a | |
3045 * wait_return(). | |
3046 * Using ":normal" can also do this, but it saves the typeahead buffer, | |
3047 * thus it should be OK. But don't get a key from the user then. | |
3048 */ | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
3049 if (vgetc_busy > 0 && ex_normal_busy == 0) |
7 | 3050 return NUL; |
3051 | |
822 | 3052 ++vgetc_busy; |
7 | 3053 |
3054 if (advance) | |
3055 KeyStuffed = FALSE; | |
3056 | |
3057 init_typebuf(); | |
3058 start_stuff(); | |
28359
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
3059 check_end_reg_executing(advance); |
7 | 3060 do |
3061 { | |
3062 /* | |
3063 * get a character: 1. from the stuffbuffer | |
3064 */ | |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
3065 if (typeahead_char != 0) |
7 | 3066 { |
3067 c = typeahead_char; | |
3068 if (advance) | |
3069 typeahead_char = 0; | |
3070 } | |
3071 else | |
5649 | 3072 c = read_readbuffers(advance); |
7 | 3073 if (c != NUL && !got_int) |
3074 { | |
3075 if (advance) | |
3076 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3077 // KeyTyped = FALSE; When the command that stuffed something |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3078 // was typed, behave like the stuffed command was typed. |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3079 // needed for CTRL-W CTRL-] to open a fold, for example. |
7 | 3080 KeyStuffed = TRUE; |
3081 } | |
3082 if (typebuf.tb_no_abbr_cnt == 0) | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3083 typebuf.tb_no_abbr_cnt = 1; // no abbreviations now |
7 | 3084 } |
3085 else | |
3086 { | |
3087 /* | |
3088 * Loop until we either find a matching mapped key, or we | |
3089 * are sure that it is not a mapped key. | |
3090 * If a mapped key sequence is found we go back to the start to | |
3091 * try re-mapping. | |
3092 */ | |
3093 for (;;) | |
3094 { | |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3095 long wait_time; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3096 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
|
3097 #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
|
3098 int showcmd_idx; |
653ab352b019
patch 8.1.1798: warning for unused variable in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17600
diff
changeset
|
3099 #endif |
28359
390dfc3e409b
patch 8.2.4705: jump list marker disappears
Bram Moolenaar <Bram@vim.org>
parents:
28333
diff
changeset
|
3100 check_end_reg_executing(advance); |
7 | 3101 /* |
3102 * ui_breakcheck() is slow, don't use it too often when | |
3103 * inside a mapping. But call it each time for typed | |
3104 * characters. | |
3105 */ | |
3106 if (typebuf.tb_maplen) | |
3107 line_breakcheck(); | |
3108 else | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3109 ui_breakcheck(); // check for CTRL-C |
7 | 3110 if (got_int) |
3111 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3112 // 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
|
3113 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
|
3114 |
7 | 3115 /* |
3116 * 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
|
3117 * are inside a mapping, get out of Insert mode. |
7 | 3118 * Otherwise we behave like having gotten a CTRL-C. |
3119 * As a result typing CTRL-C in insert mode will | |
3120 * really insert a CTRL-C. | |
3121 */ | |
3122 if ((c || typebuf.tb_maplen) | |
3123 && (State & (INSERT + CMDLINE))) | |
3124 c = ESC; | |
3125 else | |
3126 c = Ctrl_C; | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3127 flush_buffers(FLUSH_INPUT); // flush all typeahead |
7 | 3128 |
988 | 3129 if (advance) |
3130 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3131 // Also record this character, it might be needed to |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3132 // get out of Insert mode. |
988 | 3133 *typebuf.tb_buf = c; |
3134 gotchars(typebuf.tb_buf, 1); | |
3135 } | |
7 | 3136 cmd_silent = FALSE; |
3137 | |
3138 break; | |
3139 } | |
3140 else if (typebuf.tb_len > 0) | |
3141 { | |
3142 /* | |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3143 * Check for a mapping in "typebuf". |
7 | 3144 */ |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3145 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
|
3146 &keylen, &timedout, &mapdepth); |
7 | 3147 |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3148 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
|
3149 // try mapping again |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3150 continue; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3151 if (result == map_result_fail) |
7 | 3152 { |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3153 // 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
|
3154 c = -1; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3155 break; |
7 | 3156 } |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3157 if (result == map_result_get) |
7 | 3158 { |
3159 /* | |
3160 * get a character: 2. from the typeahead buffer | |
3161 */ | |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18717
diff
changeset
|
3162 c = typebuf.tb_buf[typebuf.tb_off]; |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3163 if (advance) // remove chars from tb_buf |
7 | 3164 { |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3165 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
|
3166 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
|
3167 KeyTyped = FALSE; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3168 else |
7 | 3169 { |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3170 KeyTyped = TRUE; |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3171 // write char to script file(s) |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3172 gotchars(typebuf.tb_buf |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3173 + typebuf.tb_off, 1); |
7 | 3174 } |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3175 KeyNoremap = typebuf.tb_noremap[ |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3176 typebuf.tb_off]; |
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3177 del_typebuf(1, 0); |
7 | 3178 } |
26592
9f445e07f766
patch 8.2.3825: various comments could be improved
Bram Moolenaar <Bram@vim.org>
parents:
26436
diff
changeset
|
3179 break; // got character, break the for loop |
7 | 3180 } |
3181 | |
17600
ca42eb789472
patch 8.1.1797: the vgetorpeek() function is too long
Bram Moolenaar <Bram@vim.org>
parents:
17594
diff
changeset
|
3182 // not enough characters, get more |
7 | 3183 } |
3184 | |
3185 /* | |
3186 * get a character: 3. from the user - handle <Esc> in Insert mode | |
3187 */ | |
3188 /* | |
11490
6a06738f8948
patch 8.0.0628: cursor disappears after silent mapping
Christian Brabandt <cb@256bit.org>
parents:
11486
diff
changeset
|
3189 * Special case: if we get an <ESC> in insert mode and there |
7 | 3190 * are no more characters at once, we pretend to go out of |
3191 * insert mode. This prevents the one second delay after | |
3192 * typing an <ESC>. If we get something after all, we may | |
3193 * have to redisplay the mode. That the cursor is in the wrong | |
3194 * place does not matter. | |
3195 */ | |
3196 c = 0; | |
3197 #ifdef FEAT_CMDL_INFO | |
3198 new_wcol = curwin->w_wcol; | |
3199 new_wrow = curwin->w_wrow; | |
3200 #endif | |
3201 if ( advance | |
3202 && typebuf.tb_len == 1 | |
3203 && typebuf.tb_buf[typebuf.tb_off] == ESC | |
3204 && !no_mapping | |
3205 && ex_normal_busy == 0 | |
3206 && typebuf.tb_maplen == 0 | |
3207 && (State & INSERT) | |
2672 | 3208 && (p_timeout |
3209 || (keylen == KEYLEN_PART_KEY && p_ttimeout)) | |
7 | 3210 && (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
|
3211 + typebuf.tb_len, 3, 25L)) == 0) |
7 | 3212 { |
3213 colnr_T col = 0, vcol; | |
3214 char_u *ptr; | |
3215 | |
643 | 3216 if (mode_displayed) |
7 | 3217 { |
3218 unshowmode(TRUE); | |
3219 mode_deleted = TRUE; | |
3220 } | |
3221 #ifdef FEAT_GUI | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3222 // may show a different cursor shape |
11490
6a06738f8948
patch 8.0.0628: cursor disappears after silent mapping
Christian Brabandt <cb@256bit.org>
parents:
11486
diff
changeset
|
3223 if (gui.in_use && State != NORMAL && !cmd_silent) |
7 | 3224 { |
3225 int save_State; | |
3226 | |
3227 save_State = State; | |
3228 State = NORMAL; | |
3229 gui_update_cursor(TRUE, FALSE); | |
3230 State = save_State; | |
3231 shape_changed = TRUE; | |
3232 } | |
3233 #endif | |
3234 validate_cursor(); | |
3235 old_wcol = curwin->w_wcol; | |
3236 old_wrow = curwin->w_wrow; | |
3237 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3238 // move cursor left, if possible |
7 | 3239 if (curwin->w_cursor.col != 0) |
3240 { | |
3241 if (curwin->w_wcol > 0) | |
3242 { | |
3243 if (did_ai) | |
3244 { | |
3245 /* | |
3246 * We are expecting to truncate the trailing | |
3247 * white-space, so find the last non-white | |
3248 * character -- webb | |
3249 */ | |
3250 col = vcol = curwin->w_wcol = 0; | |
3251 ptr = ml_get_curline(); | |
3252 while (col < curwin->w_cursor.col) | |
3253 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11026
diff
changeset
|
3254 if (!VIM_ISWHITE(ptr[col])) |
7 | 3255 curwin->w_wcol = vcol; |
5995 | 3256 vcol += lbr_chartabsize(ptr, ptr + col, |
25852
336e2d9924e6
patch 8.2.3460: some type casts are not needed
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
3257 vcol); |
7 | 3258 if (has_mbyte) |
474 | 3259 col += (*mb_ptr2len)(ptr + col); |
7 | 3260 else |
3261 ++col; | |
3262 } | |
3263 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
|
3264 + 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
|
3265 curwin->w_wcol %= curwin->w_width; |
7 | 3266 curwin->w_wcol += curwin_col_off(); |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3267 col = 0; // no correction needed |
7 | 3268 } |
3269 else | |
3270 { | |
3271 --curwin->w_wcol; | |
3272 col = curwin->w_cursor.col - 1; | |
3273 } | |
3274 } | |
3275 else if (curwin->w_p_wrap && curwin->w_wrow) | |
3276 { | |
3277 --curwin->w_wrow; | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3278 curwin->w_wcol = curwin->w_width - 1; |
7 | 3279 col = curwin->w_cursor.col - 1; |
3280 } | |
3281 if (has_mbyte && col > 0 && curwin->w_wcol > 0) | |
3282 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3283 // Correct when the cursor is on the right halve |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3284 // of a double-wide character. |
7 | 3285 ptr = ml_get_curline(); |
3286 col -= (*mb_head_off)(ptr, ptr + col); | |
3287 if ((*mb_ptr2cells)(ptr + col) > 1) | |
3288 --curwin->w_wcol; | |
3289 } | |
3290 } | |
3291 setcursor(); | |
3292 out_flush(); | |
3293 #ifdef FEAT_CMDL_INFO | |
3294 new_wcol = curwin->w_wcol; | |
3295 new_wrow = curwin->w_wrow; | |
3296 #endif | |
3297 curwin->w_wcol = old_wcol; | |
3298 curwin->w_wrow = old_wrow; | |
3299 } | |
3300 if (c < 0) | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3301 continue; // end of input script reached |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3302 |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3303 // Allow mapping for just typed characters. When we get here c |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3304 // is the number of extra bytes and typebuf.tb_len is 1. |
6087 | 3305 for (n = 1; n <= c; ++n) |
3306 typebuf.tb_noremap[typebuf.tb_off + n] = RM_YES; | |
7 | 3307 typebuf.tb_len += c; |
3308 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3309 // buffer full, don't map |
7 | 3310 if (typebuf.tb_len >= typebuf.tb_maplen + MAXMAPLEN) |
3311 { | |
3312 timedout = TRUE; | |
3313 continue; | |
3314 } | |
3315 | |
3316 if (ex_normal_busy > 0) | |
3317 { | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
3318 #ifdef FEAT_CMDWIN |
7 | 3319 static int tc = 0; |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
3320 #endif |
7 | 3321 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3322 // No typeahead left and inside ":normal". Must return |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3323 // something to avoid getting stuck. When an incomplete |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3324 // mapping is present, behave like it timed out. |
7 | 3325 if (typebuf.tb_len > 0) |
3326 { | |
3327 timedout = TRUE; | |
3328 continue; | |
3329 } | |
22361
00f2eebe74d9
patch 8.2.1729: endless loop when ":normal" feeds popup window filter
Bram Moolenaar <Bram@vim.org>
parents:
22117
diff
changeset
|
3330 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3331 // When 'insertmode' is set, ESC just beeps in Insert |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3332 // mode. Use CTRL-L to make edit() return. |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3333 // For the command line only CTRL-C always breaks it. |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3334 // For the cmdline window: Alternate between ESC and |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3335 // CTRL-C: ESC for most situations and CTRL-C to close the |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3336 // cmdline window. |
7 | 3337 if (p_im && (State & INSERT)) |
3338 c = Ctrl_L; | |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
3339 #ifdef FEAT_TERMINAL |
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
3340 else if (terminal_is_active()) |
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
3341 c = K_CANCEL; |
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
3342 #endif |
7 | 3343 else if ((State & CMDLINE) |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
3344 #ifdef FEAT_CMDWIN |
7 | 3345 || (cmdwin_type > 0 && tc == ESC) |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
3346 #endif |
7 | 3347 ) |
3348 c = Ctrl_C; | |
3349 else | |
3350 c = ESC; | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
3351 #ifdef FEAT_CMDWIN |
7 | 3352 tc = c; |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
3353 #endif |
19433
af9d5585cfbf
patch 8.2.0274: hang with combination of feedkeys(), Ex mode and :global
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3354 // return from main_loop() |
af9d5585cfbf
patch 8.2.0274: hang with combination of feedkeys(), Ex mode and :global
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3355 if (pending_exmode_active) |
af9d5585cfbf
patch 8.2.0274: hang with combination of feedkeys(), Ex mode and :global
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3356 exmode_active = EXMODE_NORMAL; |
af9d5585cfbf
patch 8.2.0274: hang with combination of feedkeys(), Ex mode and :global
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3357 |
26875
e06cbcf4b94b
patch 8.2.3966: when using feedkeys() abbreviations may be blocked
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
3358 // no chars to block abbreviation for |
e06cbcf4b94b
patch 8.2.3966: when using feedkeys() abbreviations may be blocked
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
3359 typebuf.tb_no_abbr_cnt = 0; |
e06cbcf4b94b
patch 8.2.3966: when using feedkeys() abbreviations may be blocked
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
3360 |
7 | 3361 break; |
3362 } | |
3363 | |
3364 /* | |
3365 * get a character: 3. from the user - update display | |
3366 */ | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3367 // In insert mode a screen update is skipped when characters |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3368 // are still available. But when those available characters |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3369 // are part of a mapping, and we are going to do a blocking |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3370 // wait here. Need to update the screen to display the |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3371 // changed text so far. Also for when 'lazyredraw' is set and |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3372 // redrawing was postponed because there was something in the |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3373 // input buffer (e.g., termresponse). |
2723 | 3374 if (((State & INSERT) != 0 || p_lz) && (State & CMDLINE) == 0 |
3375 && advance && must_redraw != 0 && !need_wait_return) | |
7 | 3376 { |
3377 update_screen(0); | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3378 setcursor(); // put cursor back where it belongs |
7 | 3379 } |
3380 | |
3381 /* | |
3382 * If we have a partial match (and are going to wait for more | |
3383 * input from the user), show the partially matched characters | |
3384 * to the user with showcmd. | |
3385 */ | |
3386 #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
|
3387 showcmd_idx = 0; |
7 | 3388 #endif |
3389 c1 = 0; | |
3390 if (typebuf.tb_len > 0 && advance && !exmode_active) | |
3391 { | |
3392 if (((State & (NORMAL | INSERT)) || State == LANGMAP) | |
3393 && State != HITRETURN) | |
3394 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3395 // this looks nice when typing a dead character map |
7 | 3396 if (State & INSERT |
3397 && ptr2cells(typebuf.tb_buf + typebuf.tb_off | |
3398 + typebuf.tb_len - 1) == 1) | |
3399 { | |
3400 edit_putchar(typebuf.tb_buf[typebuf.tb_off | |
3401 + typebuf.tb_len - 1], FALSE); | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3402 setcursor(); // put cursor back where it belongs |
7 | 3403 c1 = 1; |
3404 } | |
3405 #ifdef FEAT_CMDL_INFO | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3406 // need to use the col and row from above here |
7 | 3407 old_wcol = curwin->w_wcol; |
3408 old_wrow = curwin->w_wrow; | |
3409 curwin->w_wcol = new_wcol; | |
3410 curwin->w_wrow = new_wrow; | |
3411 push_showcmd(); | |
3412 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
|
3413 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
|
3414 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
|
3415 (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
|
3416 typebuf.tb_buf[typebuf.tb_off + showcmd_idx++]); |
7 | 3417 curwin->w_wcol = old_wcol; |
3418 curwin->w_wrow = old_wrow; | |
3419 #endif | |
3420 } | |
3421 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3422 // this looks nice when typing a dead character map |
7 | 3423 if ((State & CMDLINE) |
3424 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3425 && cmdline_star == 0 | |
3426 #endif | |
3427 && ptr2cells(typebuf.tb_buf + typebuf.tb_off | |
3428 + typebuf.tb_len - 1) == 1) | |
3429 { | |
3430 putcmdline(typebuf.tb_buf[typebuf.tb_off | |
3431 + typebuf.tb_len - 1], FALSE); | |
3432 c1 = 1; | |
3433 } | |
3434 } | |
3435 | |
3436 /* | |
3437 * get a character: 3. from the user - get it | |
3438 */ | |
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
|
3439 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
|
3440 // 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
|
3441 // 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
|
3442 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
|
3443 |
16227
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3444 if (advance) |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3445 { |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3446 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
|
3447 || !(p_timeout |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3448 || (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
|
3449 // blocking wait |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3450 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
|
3451 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
|
3452 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
|
3453 else |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3454 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
|
3455 } |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3456 else |
a70f0d6686c4
patch 8.1.1118: a couple of conditions are hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3457 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
|
3458 |
202 | 3459 wait_tb_len = typebuf.tb_len; |
7 | 3460 c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, |
3461 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
|
3462 wait_time); |
7 | 3463 |
3464 #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
|
3465 if (showcmd_idx != 0) |
7 | 3466 pop_showcmd(); |
3467 #endif | |
3468 if (c1 == 1) | |
3469 { | |
3470 if (State & INSERT) | |
3471 edit_unputchar(); | |
3472 if (State & CMDLINE) | |
3473 unputcmdline(); | |
3560 | 3474 else |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3475 setcursor(); // put cursor back where it belongs |
7 | 3476 } |
3477 | |
3478 if (c < 0) | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3479 continue; // end of input script reached |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3480 if (c == NUL) // no character available |
7 | 3481 { |
3482 if (!advance) | |
3483 break; | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3484 if (wait_tb_len > 0) // timed out |
7 | 3485 { |
3486 timedout = TRUE; | |
3487 continue; | |
3488 } | |
3489 } | |
3490 else | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3491 { // allow mapping for just typed characters |
7 | 3492 while (typebuf.tb_buf[typebuf.tb_off |
3493 + typebuf.tb_len] != NUL) | |
3494 typebuf.tb_noremap[typebuf.tb_off | |
3495 + typebuf.tb_len++] = RM_YES; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13344
diff
changeset
|
3496 #ifdef HAVE_INPUT_METHOD |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3497 // Get IM status right after getting keys, not after the |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3498 // timeout for a mapping (focus may be lost by then). |
7 | 3499 vgetc_im_active = im_get_status(); |
3500 #endif | |
3501 } | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3502 } // for (;;) |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3503 } // if (!character from stuffbuf) |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3504 |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3505 // if advance is FALSE don't loop on NULs |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
3506 } while ((c < 0 && c != K_CANCEL) || (advance && c == NUL)); |
7 | 3507 |
3508 /* | |
3509 * The "INSERT" message is taken care of here: | |
3510 * if we return an ESC to exit insert mode, the message is deleted | |
3511 * if we don't return an ESC but deleted the message before, redisplay it | |
3512 */ | |
641 | 3513 if (advance && p_smd && msg_silent == 0 && (State & INSERT)) |
7 | 3514 { |
643 | 3515 if (c == ESC && !mode_deleted && !no_mapping && mode_displayed) |
7 | 3516 { |
3517 if (typebuf.tb_len && !KeyTyped) | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3518 redraw_cmdline = TRUE; // delete mode later |
7 | 3519 else |
3520 unshowmode(FALSE); | |
3521 } | |
3522 else if (c != ESC && mode_deleted) | |
3523 { | |
3524 if (typebuf.tb_len && !KeyTyped) | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3525 redraw_cmdline = TRUE; // show mode later |
7 | 3526 else |
3527 showmode(); | |
3528 } | |
3529 } | |
3530 #ifdef FEAT_GUI | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3531 // 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
|
3532 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
|
3533 gui_update_cursor(TRUE, FALSE); |
7 | 3534 #endif |
15995
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
3535 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
|
3536 { |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
3537 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
|
3538 |
e7030c0c79cd
patch 8.1.1003: playing back recorded key sequence mistakes key code
Bram Moolenaar <Bram@vim.org>
parents:
15989
diff
changeset
|
3539 // 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
|
3540 // 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
|
3541 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
|
3542 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
|
3543 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
|
3544 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
|
3545 } |
7 | 3546 |
822 | 3547 --vgetc_busy; |
7 | 3548 |
3549 return c; | |
3550 } | |
3551 | |
3552 /* | |
3553 * inchar() - get one character from | |
3554 * 1. a scriptfile | |
3555 * 2. the keyboard | |
3556 * | |
19195
2ef19eed524a
patch 8.2.0156: various typos in source files and tests
Bram Moolenaar <Bram@vim.org>
parents:
18781
diff
changeset
|
3557 * As many characters as we can get (up to 'maxlen') are put in "buf" and |
7 | 3558 * NUL terminated (buffer length must be 'maxlen' + 1). |
3559 * Minimum for "maxlen" is 3!!!! | |
3560 * | |
3561 * "tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into | |
3562 * it. When typebuf.tb_change_cnt changes (e.g., when a message is received | |
3563 * from a remote client) "buf" can no longer be used. "tb_change_cnt" is 0 | |
3564 * otherwise. | |
3565 * | |
3566 * If we got an interrupt all input is read until none is available. | |
3567 * | |
3568 * If wait_time == 0 there is no waiting for the char. | |
3569 * If wait_time == n we wait for n msec for a character to arrive. | |
3570 * If wait_time == -1 we wait forever for a character to arrive. | |
3571 * | |
3572 * Return the number of obtained characters. | |
3573 * Return -1 when end of input script reached. | |
3574 */ | |
9205
c19eb05b19df
commit https://github.com/vim/vim/commit/cda7764d8e65325d4524e5d6c3174121eeb12cad
Christian Brabandt <cb@256bit.org>
parents:
9121
diff
changeset
|
3575 static int |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3576 inchar( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3577 char_u *buf, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3578 int maxlen, |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26592
diff
changeset
|
3579 long wait_time) // milliseconds |
7 | 3580 { |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3581 int len = 0; // init for GCC |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3582 int retesc = FALSE; // return ESC with gotint |
7 | 3583 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
|
3584 int tb_change_cnt = typebuf.tb_change_cnt; |
7 | 3585 |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3586 if (wait_time == -1L || wait_time > 100L) // flush output before waiting |
7 | 3587 { |
3588 cursor_on(); | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
3589 out_flush_cursor(FALSE, FALSE); |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
3590 #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
|
3591 if (gui.in_use && postponed_mouseshape) |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
3592 update_mouseshape(-1); |
7 | 3593 #endif |
3594 } | |
3595 | |
3596 /* | |
3597 * Don't reset these when at the hit-return prompt, otherwise a endless | |
3598 * recursive loop may result (write error in swapfile, hit-return, timeout | |
3599 * on char wait, flush swapfile, write error....). | |
3600 */ | |
3601 if (State != HITRETURN) | |
3602 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3603 did_outofmem_msg = FALSE; // display out of memory message (again) |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3604 did_swapwrite_msg = FALSE; // display swap file write error again |
7 | 3605 } |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3606 undo_off = FALSE; // restart undo now |
7 | 3607 |
3608 /* | |
1462 | 3609 * Get a character from a script file if there is one. |
3610 * If interrupted: Stop reading script files, close them all. | |
7 | 3611 */ |
3612 script_char = -1; | |
1462 | 3613 while (scriptin[curscript] != NULL && script_char < 0 |
3614 #ifdef FEAT_EVAL | |
3615 && !ignore_script | |
3616 #endif | |
3617 ) | |
7 | 3618 { |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
6907
diff
changeset
|
3619 #ifdef MESSAGE_QUEUE |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
6907
diff
changeset
|
3620 parse_queued_messages(); |
1618 | 3621 #endif |
3622 | |
7 | 3623 if (got_int || (script_char = getc(scriptin[curscript])) < 0) |
3624 { | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3625 // Reached EOF. |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3626 // Careful: closescript() frees typebuf.tb_buf[] and buf[] may |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3627 // point inside typebuf.tb_buf[]. Don't use buf[] after this! |
7 | 3628 closescript(); |
3629 /* | |
3630 * When reading script file is interrupted, return an ESC to get | |
3631 * back to normal mode. | |
3632 * Otherwise return -1, because typebuf.tb_buf[] has changed. | |
3633 */ | |
3634 if (got_int) | |
3635 retesc = TRUE; | |
3636 else | |
3637 return -1; | |
3638 } | |
3639 else | |
3640 { | |
3641 buf[0] = script_char; | |
3642 len = 1; | |
3643 } | |
3644 } | |
3645 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3646 if (script_char < 0) // did not get a character from script |
7 | 3647 { |
3648 /* | |
3649 * If we got an interrupt, skip all previously typed characters and | |
3650 * return TRUE if quit reading script file. | |
3651 * Stop reading typeahead when a single CTRL-C was read, | |
3652 * fill_input_buf() returns this when not able to read from stdin. | |
3653 * Don't use buf[] here, closescript() may have freed typebuf.tb_buf[] | |
3654 * and buf may be pointing inside typebuf.tb_buf[]. | |
3655 */ | |
3656 if (got_int) | |
3657 { | |
27752
c1d1639b52dd
patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents:
27748
diff
changeset
|
3658 #define DUM_LEN (MAXMAPLEN * 3 + 3) |
7 | 3659 char_u dum[DUM_LEN + 1]; |
3660 | |
3661 for (;;) | |
3662 { | |
3663 len = ui_inchar(dum, DUM_LEN, 0L, 0); | |
3664 if (len == 0 || (len == 1 && dum[0] == 3)) | |
3665 break; | |
3666 } | |
3667 return retesc; | |
3668 } | |
3669 | |
3670 /* | |
3671 * 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
|
3672 * from the user and not just peeking. |
7 | 3673 */ |
15629
dd2e0b83a660
patch 8.1.0822: peeking and flushing output slows down execution
Bram Moolenaar <Bram@vim.org>
parents:
15605
diff
changeset
|
3674 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
|
3675 out_flush(); |
7 | 3676 |
3677 /* | |
3678 * Fill up to a third of the buffer, because each character may be | |
3679 * tripled below. | |
3680 */ | |
3681 len = ui_inchar(buf, maxlen / 3, wait_time, tb_change_cnt); | |
3682 } | |
3683 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3684 // If the typebuf was changed further down, it is like nothing was added by |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3685 // this call. |
7 | 3686 if (typebuf_changed(tb_change_cnt)) |
3687 return 0; | |
3688 | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3689 // Note the change in the typeahead buffer, this matters for when |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3690 // vgetorpeek() is called recursively, e.g. using getchar(1) in a timer |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3691 // function. |
12281
2738b0cc5f64
patch 8.0.1020: when a timer calls getchar(1) input is overwritten
Christian Brabandt <cb@256bit.org>
parents:
11577
diff
changeset
|
3692 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
|
3693 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
|
3694 |
9896
7b39615c0db1
commit https://github.com/vim/vim/commit/6bff02eb530aa29aafa2cb5627399837be7a5dd5
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3695 return fix_input_buffer(buf, len); |
7 | 3696 } |
3697 | |
3698 /* | |
3699 * 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
|
3700 * "buf[]" must have room to triple the number of bytes! |
7 | 3701 * Returns the new length. |
3702 */ | |
3703 int | |
9896
7b39615c0db1
commit https://github.com/vim/vim/commit/6bff02eb530aa29aafa2cb5627399837be7a5dd5
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3704 fix_input_buffer(char_u *buf, int len) |
7 | 3705 { |
3706 int i; | |
3707 char_u *p = buf; | |
3708 | |
3709 /* | |
3710 * Two characters are special: NUL and K_SPECIAL. | |
3711 * When compiled With the GUI CSI is also special. | |
3712 * Replace NUL by K_SPECIAL KS_ZERO KE_FILLER | |
3713 * Replace K_SPECIAL by K_SPECIAL KS_SPECIAL KE_FILLER | |
3714 * Replace CSI by K_SPECIAL KS_EXTRA KE_CSI | |
3715 */ | |
3716 for (i = len; --i >= 0; ++p) | |
3717 { | |
3718 #ifdef FEAT_GUI | |
18781
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3719 // When the GUI is used any character can come after a CSI, don't |
79e10adc821d
patch 8.1.2380: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3720 // escape it. |
7 | 3721 if (gui.in_use && p[0] == CSI && i >= 2) |
3722 { | |
3723 p += 2; | |
3724 i -= 2; | |
3725 } | |
27748
49b667252942
patch 8.2.4400: MS-Windows: cannot use the mouse in the console with VIMDLL
Bram Moolenaar <Bram@vim.org>
parents:
27736
diff
changeset
|
3726 # ifndef MSWIN |
49b667252942
patch 8.2.4400: MS-Windows: cannot use the mouse in the console with VIMDLL
Bram Moolenaar <Bram@vim.org>
parents:
27736
diff
changeset
|
3727 // When not on MS-Windows and the GUI is not used CSI needs to be |
49b667252942
patch 8.2.4400: MS-Windows: cannot use the mouse in the console with VIMDLL
Bram Moolenaar <Bram@vim.org>
parents:
27736
diff
changeset
|
3728 // escaped. |
7 | 3729 else if (!gui.in_use && p[0] == CSI) |
3730 { | |
3731 mch_memmove(p + 3, p + 1, (size_t)i); | |
3732 *p++ = K_SPECIAL; | |
3733 *p++ = KS_EXTRA; | |
3734 *p = (int)KE_CSI; | |
3735 len += 2; | |
3736 } | |
27748
49b667252942
patch 8.2.4400: MS-Windows: cannot use the mouse in the console with VIMDLL
Bram Moolenaar <Bram@vim.org>
parents:
27736
diff
changeset
|
3737 # endif |
7 | 3738 else |
3739 #endif | |
9896
7b39615c0db1
commit https://github.com/vim/vim/commit/6bff02eb530aa29aafa2cb5627399837be7a5dd5
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3740 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
|
3741 // timeout may generate K_CURSORHOLD |
202 | 3742 && (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
|
3743 #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
|
3744 // 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
|
3745 && ( |
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
|
3746 # 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
|
3747 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
|
3748 # 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
|
3749 (i < 2 || p[1] != KS_MODIFIER)) |
7 | 3750 #endif |
3751 )) | |
3752 { | |
3753 mch_memmove(p + 3, p + 1, (size_t)i); | |
3754 p[2] = K_THIRD(p[0]); | |
3755 p[1] = K_SECOND(p[0]); | |
3756 p[0] = K_SPECIAL; | |
3757 p += 2; | |
3758 len += 2; | |
3759 } | |
3760 } | |
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
|
3761 *p = NUL; // add trailing NUL |
7 | 3762 return len; |
3763 } | |
3764 | |
3765 #if defined(USE_INPUT_BUF) || defined(PROTO) | |
3766 /* | |
3767 * Return TRUE when bytes are in the input buffer or in the typeahead buffer. | |
3768 * Normally the input buffer would be sufficient, but the server_to_input_buf() | |
842 | 3769 * or feedkeys() may insert characters in the typeahead buffer while we are |
841 | 3770 * waiting for input to arrive. |
7 | 3771 */ |
3772 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3773 input_available(void) |
7 | 3774 { |
3775 return (!vim_is_input_buf_empty() | |
841 | 3776 # if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
3777 || typebuf_was_filled | |
7 | 3778 # endif |
3779 ); | |
3780 } | |
3781 #endif | |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3782 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3783 /* |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3784 * Function passed to do_cmdline() to get the command after a <Cmd> key from |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3785 * typeahead. |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3786 */ |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3787 static char_u * |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3788 getcmdkeycmd( |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3789 int promptc UNUSED, |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3790 void *cookie UNUSED, |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3791 int indent UNUSED, |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3792 getline_opt_T do_concat UNUSED) |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3793 { |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3794 garray_T line_ga; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3795 int c1 = -1; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3796 int c2; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3797 int cmod = 0; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3798 int aborted = FALSE; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3799 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3800 ga_init2(&line_ga, 1, 32); |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3801 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3802 // no mapping for these characters |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3803 no_mapping++; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3804 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3805 got_int = FALSE; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3806 while (c1 != NUL && !aborted) |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3807 { |
22888
7ac9dea21baa
patch 8.2.1991: Coverity warns for not using the ga_grow() return value
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3808 if (ga_grow(&line_ga, 32) != OK) |
7ac9dea21baa
patch 8.2.1991: Coverity warns for not using the ga_grow() return value
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3809 { |
7ac9dea21baa
patch 8.2.1991: Coverity warns for not using the ga_grow() return value
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3810 aborted = TRUE; |
7ac9dea21baa
patch 8.2.1991: Coverity warns for not using the ga_grow() return value
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3811 break; |
7ac9dea21baa
patch 8.2.1991: Coverity warns for not using the ga_grow() return value
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3812 } |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3813 |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
3814 if (vgetorpeek(FALSE) == NUL) |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3815 { |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3816 // incomplete <Cmd> is an error, because there is not much the user |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3817 // could do in this state. |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3818 emsg(_(e_cmd_mapping_must_end_with_cr)); |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3819 aborted = TRUE; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3820 break; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3821 } |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3822 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3823 // Get one character at a time. |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
3824 c1 = vgetorpeek(TRUE); |
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
3825 |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3826 // Get two extra bytes for special keys |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3827 if (c1 == K_SPECIAL) |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3828 { |
28331
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
3829 c1 = vgetorpeek(TRUE); |
3e707d35d05d
patch 8.2.4691: solution for <Cmd> in a mapping causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
28327
diff
changeset
|
3830 c2 = vgetorpeek(TRUE); |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3831 if (c1 == KS_MODIFIER) |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3832 { |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3833 cmod = c2; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3834 continue; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3835 } |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3836 c1 = TO_SPECIAL(c1, c2); |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3837 } |
23031
b68313ee7002
patch 8.2.2062: <Cmd> does not handle CTRL-V
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3838 if (c1 == Ctrl_V) |
b68313ee7002
patch 8.2.2062: <Cmd> does not handle CTRL-V
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3839 { |
b68313ee7002
patch 8.2.2062: <Cmd> does not handle CTRL-V
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3840 // CTRL-V is followed by octal, hex or other characters, reverses |
b68313ee7002
patch 8.2.2062: <Cmd> does not handle CTRL-V
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3841 // what AppendToRedobuffLit() does. |
b68313ee7002
patch 8.2.2062: <Cmd> does not handle CTRL-V
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3842 no_reduce_keys = TRUE; // don't merge modifyOtherKeys |
23076
5fbac68bda23
patch 8.2.2084: CTRL-V U doesn't work to enter a Unicode character
Bram Moolenaar <Bram@vim.org>
parents:
23031
diff
changeset
|
3843 c1 = get_literal(TRUE); |
23031
b68313ee7002
patch 8.2.2062: <Cmd> does not handle CTRL-V
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3844 no_reduce_keys = FALSE; |
b68313ee7002
patch 8.2.2062: <Cmd> does not handle CTRL-V
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3845 } |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3846 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3847 if (got_int) |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3848 aborted = TRUE; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3849 else if (c1 == '\r' || c1 == '\n') |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3850 c1 = NUL; // end the line |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3851 else if (c1 == ESC) |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3852 aborted = TRUE; |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3853 else if (c1 == K_COMMAND || c1 == K_SCRIPT_COMMAND) |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3854 { |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3855 // give a nicer error message for this special case |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3856 emsg(_(e_cmd_mapping_must_end_with_cr_before_second_cmd)); |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3857 aborted = TRUE; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3858 } |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3859 else if (IS_SPECIAL(c1)) |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3860 { |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3861 if (c1 == K_SNR) |
22916
1fe53aae3ba0
patch 8.2.2005: redoing a mapping with <Cmd> doesn't work properly
Bram Moolenaar <Bram@vim.org>
parents:
22888
diff
changeset
|
3862 ga_concat(&line_ga, (char_u *)"<SNR>"); |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3863 else |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3864 { |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3865 semsg(e_cmd_maping_must_not_include_str_key, |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3866 get_special_key_name(c1, cmod)); |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3867 aborted = TRUE; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3868 } |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3869 } |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3870 else |
27156
67194006cad8
patch 8.2.4107: script context not restored after using <ScriptCmd>
Bram Moolenaar <Bram@vim.org>
parents:
27144
diff
changeset
|
3871 ga_append(&line_ga, c1); |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3872 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3873 cmod = 0; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3874 } |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3875 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3876 no_mapping--; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3877 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3878 if (aborted) |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3879 ga_clear(&line_ga); |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3880 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3881 return (char_u *)line_ga.ga_data; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22800
diff
changeset
|
3882 } |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3883 |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3884 int |
27144
54f0a6a9db2d
patch 8.2.4101: warning for unused argument in tiny version
Bram Moolenaar <Bram@vim.org>
parents:
27140
diff
changeset
|
3885 do_cmdkey_command(int key UNUSED, int flags) |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3886 { |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3887 int res; |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3888 #ifdef FEAT_EVAL |
27156
67194006cad8
patch 8.2.4107: script context not restored after using <ScriptCmd>
Bram Moolenaar <Bram@vim.org>
parents:
27144
diff
changeset
|
3889 sctx_T save_current_sctx = {-1, 0, 0, 0}; |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3890 |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3891 if (key == K_SCRIPT_COMMAND && last_used_map != NULL) |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3892 { |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3893 save_current_sctx = current_sctx; |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3894 current_sctx = last_used_map->m_script_ctx; |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3895 } |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3896 #endif |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3897 |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3898 res = do_cmdline(NULL, getcmdkeycmd, NULL, flags); |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3899 |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3900 #ifdef FEAT_EVAL |
27156
67194006cad8
patch 8.2.4107: script context not restored after using <ScriptCmd>
Bram Moolenaar <Bram@vim.org>
parents:
27144
diff
changeset
|
3901 if (save_current_sctx.sc_sid >= 0) |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3902 current_sctx = save_current_sctx; |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3903 #endif |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3904 |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3905 return res; |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3906 } |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3907 |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3908 #if defined(FEAT_EVAL) || defined(PROTO) |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3909 void |
27239
bd072d44eb2c
patch 8.2.4148: deleting any mapping may cause <ScritpCmd> to fail
Bram Moolenaar <Bram@vim.org>
parents:
27156
diff
changeset
|
3910 reset_last_used_map(mapblock_T *mp) |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3911 { |
27239
bd072d44eb2c
patch 8.2.4148: deleting any mapping may cause <ScritpCmd> to fail
Bram Moolenaar <Bram@vim.org>
parents:
27156
diff
changeset
|
3912 if (last_used_map == mp) |
bd072d44eb2c
patch 8.2.4148: deleting any mapping may cause <ScritpCmd> to fail
Bram Moolenaar <Bram@vim.org>
parents:
27156
diff
changeset
|
3913 last_used_map = NULL; |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3914 } |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
3915 #endif |