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