annotate src/getchar.c @ 32369:ffbae151e462 v9.0.1516

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