Mercurial > vim
annotate src/map.c @ 31081:c12069d28719 v9.0.0875
patch 9.0.0875: using freed memory when executing delfunc at more prompt
Commit: https://github.com/vim/vim/commit/398a26f7fcd58fbc6e2329f892edbb7479a971bb
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Nov 13 22:13:33 2022 +0000
patch 9.0.0875: using freed memory when executing delfunc at more prompt
Problem: Using freed memory when executing delfunc at the more prompt.
Solution: Check function list not changed in another place. (closes https://github.com/vim/vim/issues/11437)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 13 Nov 2022 23:15:03 +0100 |
parents | 6a2b04cd0213 |
children | dcde141f2d1e |
rev | line source |
---|---|
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
26224
7d66d585bffa
patch 8.2.3643: header for source file is outdated
Bram Moolenaar <Bram@vim.org>
parents:
25431
diff
changeset
|
11 * map.c: Code for mappings and abbreviations. |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 * List used for abbreviations. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 static mapblock_T *first_abbr = NULL; // first entry in abbrlist |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 * Each mapping is put in one of the 256 hash lists, to speed up finding it. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 static mapblock_T *(maphash[256]); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 static int maphash_valid = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 |
31077
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
27 // When non-zero then no mappings can be added or removed. Prevents mappings |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
28 // to change while listing them. |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
29 static int map_locked = 0; |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
30 |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 * Make a hash value for a mapping. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 * "mode" is the lower 4 bits of the State for the mapping. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 * "c1" is the first character of the "lhs". |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 * Returns a value between 0 and 255, index in maphash. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 * Put Normal/Visual mode mappings mostly separately from Insert/Cmdline mode. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 */ |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
38 #define MAP_HASH(mode, c1) (((mode) & (MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING | MODE_TERMINAL)) ? (c1) : ((c1) ^ 0x80)) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 * Get the start of the hashed map list for "state" and first character "c". |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 mapblock_T * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 get_maphash_list(int state, int c) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 return maphash[MAP_HASH(state, c)]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 * Get the buffer-local hashed map list for "state" and first character "c". |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 mapblock_T * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 get_buf_maphash_list(int state, int c) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 return curbuf->b_maphash[MAP_HASH(state, c)]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 int |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 is_maphash_valid(void) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 return maphash_valid; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 * Initialize maphash[] for first use. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 static void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 validate_maphash(void) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 if (!maphash_valid) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 { |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19870
diff
changeset
|
72 CLEAR_FIELD(maphash); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 maphash_valid = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 * Delete one entry from the abbrlist or maphash[]. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 * "mpp" is a pointer to the m_next field of the PREVIOUS entry! |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 static void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 map_free(mapblock_T **mpp) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 mapblock_T *mp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 mp = *mpp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 vim_free(mp->m_keys); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 vim_free(mp->m_str); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 vim_free(mp->m_orig_str); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 *mpp = mp->m_next; |
27165
0bb71ef751bb
patch 8.2.4111: potential proglem when map is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
91 #ifdef FEAT_EVAL |
27239
bd072d44eb2c
patch 8.2.4148: deleting any mapping may cause <ScritpCmd> to fail
Bram Moolenaar <Bram@vim.org>
parents:
27223
diff
changeset
|
92 reset_last_used_map(mp); |
27165
0bb71ef751bb
patch 8.2.4111: potential proglem when map is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
27061
diff
changeset
|
93 #endif |
27243
c072eed37deb
patch 8.2.4150: Coverity warns for using pointer after free
Bram Moolenaar <Bram@vim.org>
parents:
27239
diff
changeset
|
94 vim_free(mp); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 * Return characters to represent the map mode in an allocated string. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 * Returns NULL when out of memory. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 static char_u * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 map_mode_to_chars(int mode) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 garray_T mapmode; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 ga_init2(&mapmode, 1, 7); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
108 if ((mode & (MODE_INSERT | MODE_CMDLINE)) == (MODE_INSERT | MODE_CMDLINE)) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 ga_append(&mapmode, '!'); // :map! |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
110 else if (mode & MODE_INSERT) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 ga_append(&mapmode, 'i'); // :imap |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
112 else if (mode & MODE_LANGMAP) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 ga_append(&mapmode, 'l'); // :lmap |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
114 else if (mode & MODE_CMDLINE) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 ga_append(&mapmode, 'c'); // :cmap |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
116 else if ((mode |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
117 & (MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING)) |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
118 == (MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING)) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 ga_append(&mapmode, ' '); // :map |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
122 if (mode & MODE_NORMAL) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 ga_append(&mapmode, 'n'); // :nmap |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
124 if (mode & MODE_OP_PENDING) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 ga_append(&mapmode, 'o'); // :omap |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
126 if (mode & MODE_TERMINAL) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 ga_append(&mapmode, 't'); // :tmap |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
128 if ((mode & (MODE_VISUAL | MODE_SELECT)) == (MODE_VISUAL | MODE_SELECT)) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 ga_append(&mapmode, 'v'); // :vmap |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
132 if (mode & MODE_VISUAL) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 ga_append(&mapmode, 'x'); // :xmap |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
134 if (mode & MODE_SELECT) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 ga_append(&mapmode, 's'); // :smap |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 ga_append(&mapmode, NUL); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 return (char_u *)mapmode.ga_data; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 |
30920
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
143 /* |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
144 * Output a line for one mapping. |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
145 */ |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 static void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 showmap( |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 mapblock_T *mp, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 int local) // TRUE for buffer-local map |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 int len = 1; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 char_u *mapchars; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 if (message_filtered(mp->m_keys) && message_filtered(mp->m_str)) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 return; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 |
31077
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
157 // Prevent mappings to be cleared while at the more prompt. |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
158 // Must jump to "theend" instead of returning. |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
159 ++map_locked; |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
160 |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 if (msg_didout || msg_silent != 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 msg_putchar('\n'); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 if (got_int) // 'q' typed at MORE prompt |
31077
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
165 goto theend; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 mapchars = map_mode_to_chars(mp->m_mode); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 if (mapchars != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 msg_puts((char *)mapchars); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 len = (int)STRLEN(mapchars); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 vim_free(mapchars); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 while (++len <= 3) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 msg_putchar(' '); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 // Display the LHS. Get length of what we write. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 len = msg_outtrans_special(mp->m_keys, TRUE, 0); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 do |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 msg_putchar(' '); // padd with blanks |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 ++len; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 } while (len < 12); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 if (mp->m_noremap == REMAP_NONE) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 msg_puts_attr("*", HL_ATTR(HLF_8)); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 else if (mp->m_noremap == REMAP_SCRIPT) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 msg_puts_attr("&", HL_ATTR(HLF_8)); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 msg_putchar(' '); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 if (local) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 msg_putchar('@'); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 msg_putchar(' '); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 // Use FALSE below if we only want things like <Up> to show up as such on |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 // the rhs, and not M-x etc, TRUE gets both -- webb |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 if (*mp->m_str == NUL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 msg_puts_attr("<Nop>", HL_ATTR(HLF_8)); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 else |
28686
141fb1d233ba
patch 8.2.4867: listing of mapping with K_SPECIAL is wrong
Bram Moolenaar <Bram@vim.org>
parents:
28674
diff
changeset
|
204 msg_outtrans_special(mp->m_str, FALSE, 0); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 #ifdef FEAT_EVAL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 if (p_verbose > 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 last_set_msg(mp->m_script_ctx); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 #endif |
27750
fc0a37304590
patch 8.2.4401: map listing does not clear the rest of the command line
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
209 msg_clr_eos(); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 out_flush(); // show one line at a time |
31077
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
211 |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
212 theend: |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
213 --map_locked; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
216 static int |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
217 map_add( |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
218 mapblock_T **map_table, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
219 mapblock_T **abbr_table, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
220 char_u *keys, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
221 char_u *rhs, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
222 char_u *orig_rhs, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
223 int noremap, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
224 int nowait, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
225 int silent, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
226 int mode, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
227 int is_abbr, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
228 #ifdef FEAT_EVAL |
20510
3d9a2c8d4f95
patch 8.2.0809: build failure with small features
Bram Moolenaar <Bram@vim.org>
parents:
20506
diff
changeset
|
229 int expr, |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
230 scid_T sid, // -1 to use current_sctx |
27223
ea2b4cb4515b
patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents:
27221
diff
changeset
|
231 int scriptversion, |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
232 linenr_T lnum, |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
233 #endif |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
234 int simplified) |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
235 { |
27221
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
236 mapblock_T *mp = ALLOC_CLEAR_ONE(mapblock_T); |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
237 |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
238 if (mp == NULL) |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
239 return FAIL; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
240 |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
241 // If CTRL-C has been mapped, don't always use it for Interrupting. |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
242 if (*keys == Ctrl_C) |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
243 { |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
244 if (map_table == curbuf->b_maphash) |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
245 curbuf->b_mapped_ctrl_c |= mode; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
246 else |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
247 mapped_ctrl_c |= mode; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
248 } |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
249 |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
250 mp->m_keys = vim_strsave(keys); |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
251 mp->m_str = vim_strsave(rhs); |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
252 mp->m_orig_str = vim_strsave(orig_rhs); |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
253 if (mp->m_keys == NULL || mp->m_str == NULL) |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
254 { |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
255 vim_free(mp->m_keys); |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
256 vim_free(mp->m_str); |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
257 vim_free(mp->m_orig_str); |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
258 vim_free(mp); |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
259 return FAIL; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
260 } |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
261 mp->m_keylen = (int)STRLEN(mp->m_keys); |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
262 mp->m_noremap = noremap; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
263 mp->m_nowait = nowait; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
264 mp->m_silent = silent; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
265 mp->m_mode = mode; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
266 mp->m_simplified = simplified; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
267 #ifdef FEAT_EVAL |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
268 mp->m_expr = expr; |
27223
ea2b4cb4515b
patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents:
27221
diff
changeset
|
269 if (sid > 0) |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
270 { |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
271 mp->m_script_ctx.sc_sid = sid; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
272 mp->m_script_ctx.sc_lnum = lnum; |
27223
ea2b4cb4515b
patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents:
27221
diff
changeset
|
273 mp->m_script_ctx.sc_version = scriptversion; |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
274 } |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
275 else |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
276 { |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
277 mp->m_script_ctx = current_sctx; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
278 mp->m_script_ctx.sc_lnum += SOURCING_LNUM; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
279 } |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
280 #endif |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
281 |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
282 // add the new entry in front of the abbrlist or maphash[] list |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
283 if (is_abbr) |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
284 { |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
285 mp->m_next = *abbr_table; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
286 *abbr_table = mp; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
287 } |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
288 else |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
289 { |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
290 int n = MAP_HASH(mp->m_mode, mp->m_keys[0]); |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
291 |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
292 mp->m_next = map_table[n]; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
293 map_table[n] = mp; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
294 } |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
295 return OK; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
296 } |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
297 |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 /* |
30920
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
299 * List mappings. When "haskey" is FALSE all mappings, otherwise mappings that |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
300 * match "keys[keys_len]". |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
301 */ |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
302 static void |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
303 list_mappings( |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
304 int keyround, |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
305 int abbrev, |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
306 int haskey, |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
307 char_u *keys, |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
308 int keys_len, |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
309 int mode, |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
310 int *did_local) |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
311 { |
31077
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
312 // Prevent mappings to be cleared while at the more prompt. |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
313 ++map_locked; |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
314 |
30920
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
315 if (p_verbose > 0 && keyround == 1 && seenModifyOtherKeys) |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
316 msg_puts(_("Seen modifyOtherKeys: true")); |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
317 |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
318 // need to loop over all global hash lists |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
319 for (int hash = 0; hash < 256 && !got_int; ++hash) |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
320 { |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
321 mapblock_T *mp; |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
322 |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
323 if (abbrev) |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
324 { |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
325 if (hash != 0) // there is only one abbreviation list |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
326 break; |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
327 mp = curbuf->b_first_abbr; |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
328 } |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
329 else |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
330 mp = curbuf->b_maphash[hash]; |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
331 for ( ; mp != NULL && !got_int; mp = mp->m_next) |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
332 { |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
333 // check entries with the same mode |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
334 if (!mp->m_simplified && (mp->m_mode & mode) != 0) |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
335 { |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
336 if (!haskey) // show all entries |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
337 { |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
338 showmap(mp, TRUE); |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
339 *did_local = TRUE; |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
340 } |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
341 else |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
342 { |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
343 int n = mp->m_keylen; |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
344 if (STRNCMP(mp->m_keys, keys, |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
345 (size_t)(n < keys_len ? n : keys_len)) == 0) |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
346 { |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
347 showmap(mp, TRUE); |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
348 *did_local = TRUE; |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
349 } |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
350 } |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
351 } |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
352 } |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
353 } |
31077
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
354 |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
355 --map_locked; |
30920
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
356 } |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
357 |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
358 /* |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 * map[!] : show all key mappings |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 * map[!] {lhs} : show key mapping for {lhs} |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 * map[!] {lhs} {rhs} : set key mapping for {lhs} to {rhs} |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 * noremap[!] {lhs} {rhs} : same, but no remapping for {rhs} |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 * unmap[!] {lhs} : remove key mapping for {lhs} |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 * abbr : show all abbreviations |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 * abbr {lhs} : show abbreviations for {lhs} |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 * abbr {lhs} {rhs} : set abbreviation for {lhs} to {rhs} |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 * noreabbr {lhs} {rhs} : same, but no remapping for {rhs} |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 * unabbr {lhs} : remove abbreviation for {lhs} |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 * |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
370 * maptype: MAPTYPE_MAP for :map |
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
371 * MAPTYPE_UNMAP for :unmap |
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
372 * MAPTYPE_NOREMAP for noremap |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 * arg is pointer to any arguments. Note: arg cannot be a read-only string, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 * it will be modified. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 * |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
377 * for :map mode is MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
378 * for :map! mode is MODE_INSERT | MODE_CMDLINE |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
379 * for :cmap mode is MODE_CMDLINE |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
380 * for :imap mode is MODE_INSERT |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
381 * for :lmap mode is MODE_LANGMAP |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
382 * for :nmap mode is MODE_NORMAL |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
383 * for :vmap mode is MODE_VISUAL | MODE_SELECT |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
384 * for :xmap mode is MODE_VISUAL |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
385 * for :smap mode is MODE_SELECT |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
386 * for :omap mode is MODE_OP_PENDING |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
387 * for :tmap mode is MODE_TERMINAL |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 * |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
389 * for :abbr mode is MODE_INSERT | MODE_CMDLINE |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
390 * for :iabbr mode is MODE_INSERT |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
391 * for :cabbr mode is MODE_CMDLINE |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 * Return 0 for success |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 * 1 for invalid arguments |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 * 2 for no match |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 * 4 for out of mem |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 * 5 for entry not unique |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 int |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 do_map( |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 int maptype, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 char_u *arg, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 int mode, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 int abbrev) // not a mapping but an abbreviation |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 char_u *keys; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 mapblock_T *mp, **mpp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 char_u *rhs; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 char_u *p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 int n; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 int len = 0; // init for GCC |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 int hasarg; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 int haskey; |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
414 int do_print; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
415 int keyround; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 char_u *keys_buf = NULL; |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
417 char_u *alt_keys_buf = NULL; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 char_u *arg_buf = NULL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 int retval = 0; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 int do_backslash; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 mapblock_T **abbr_table; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 mapblock_T **map_table; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 int unique = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 int nowait = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 int silent = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 int special = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 #ifdef FEAT_EVAL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 int expr = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 #endif |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
430 int did_simplify = FALSE; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 int noremap; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 char_u *orig_rhs; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 keys = arg; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 map_table = maphash; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 abbr_table = &first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 // For ":noremap" don't remap, otherwise do remap. |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
439 if (maptype == MAPTYPE_NOREMAP) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 noremap = REMAP_NONE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 noremap = REMAP_YES; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 // Accept <buffer>, <nowait>, <silent>, <expr> <script> and <unique> in |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 // any order. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 for (;;) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 // Check for "<buffer>": mapping local to buffer. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 if (STRNCMP(keys, "<buffer>", 8) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 keys = skipwhite(keys + 8); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 map_table = curbuf->b_maphash; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 abbr_table = &curbuf->b_first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 // Check for "<nowait>": don't wait for more characters. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 if (STRNCMP(keys, "<nowait>", 8) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 keys = skipwhite(keys + 8); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 nowait = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 // Check for "<silent>": don't echo commands. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 if (STRNCMP(keys, "<silent>", 8) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 keys = skipwhite(keys + 8); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 silent = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 // Check for "<special>": accept special keys in <> |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 if (STRNCMP(keys, "<special>", 9) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 keys = skipwhite(keys + 9); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 special = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 #ifdef FEAT_EVAL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 // Check for "<script>": remap script-local mappings only |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 if (STRNCMP(keys, "<script>", 8) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 keys = skipwhite(keys + 8); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 noremap = REMAP_SCRIPT; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 // Check for "<expr>": {rhs} is an expression. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 if (STRNCMP(keys, "<expr>", 6) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 keys = skipwhite(keys + 6); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 expr = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 #endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 // Check for "<unique>": don't overwrite an existing mapping. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 if (STRNCMP(keys, "<unique>", 8) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 keys = skipwhite(keys + 8); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 unique = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 validate_maphash(); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 // Find end of keys and skip CTRL-Vs (and backslashes) in it. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 // Accept backslash like CTRL-V when 'cpoptions' does not contain 'B'. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 // with :unmap white space is included in the keys, no argument possible. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 p = keys; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL); |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
515 while (*p && (maptype == MAPTYPE_UNMAP || !VIM_ISWHITE(*p))) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 if ((p[0] == Ctrl_V || (do_backslash && p[0] == '\\')) && |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 p[1] != NUL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 ++p; // skip CTRL-V or backslash |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 ++p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 if (*p != NUL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 *p++ = NUL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 p = skipwhite(p); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 rhs = p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 hasarg = (*rhs != NUL); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 haskey = (*keys != NUL); |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
529 do_print = !haskey || (maptype != MAPTYPE_UNMAP && !hasarg); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 // check for :unmap without argument |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
532 if (maptype == MAPTYPE_UNMAP && !haskey) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 retval = 1; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 goto theend; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 // If mapping has been given as ^V<C_UP> say, then replace the term codes |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 // with the appropriate two bytes. If it is a shifted special key, unshift |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 // it too, giving another two bytes. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 // replace_termcodes() may move the result to allocated memory, which |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 // needs to be freed later (*keys_buf and *arg_buf). |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 // replace_termcodes() also removes CTRL-Vs and sometimes backslashes. |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
544 // If something like <C-H> is simplified to 0x08 then mark it as simplified |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
545 // and also add a n entry with a modifier, which will work when |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
546 // modifyOtherKeys is working. |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 if (haskey) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
548 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
549 char_u *new_keys; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
550 int flags = REPTERM_FROM_PART | REPTERM_DO_LT; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
551 |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
552 if (special) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
553 flags |= REPTERM_SPECIAL; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
554 new_keys = replace_termcodes(keys, &keys_buf, flags, &did_simplify); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
555 if (did_simplify) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
556 (void)replace_termcodes(keys, &alt_keys_buf, |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
557 flags | REPTERM_NO_SIMPLIFY, NULL); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
558 keys = new_keys; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
559 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 orig_rhs = rhs; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 if (hasarg) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 if (STRICMP(rhs, "<nop>") == 0) // "<Nop>" means nothing |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 rhs = (char_u *)""; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 else |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
566 rhs = replace_termcodes(rhs, &arg_buf, |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
567 REPTERM_DO_LT | (special ? REPTERM_SPECIAL : 0), NULL); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
570 /* |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
571 * The following is done twice if we have two versions of keys: |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
572 * "alt_keys_buf" is not NULL. |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
573 */ |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
574 for (keyround = 1; keyround <= 2; ++keyround) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
576 int did_it = FALSE; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
577 int did_local = FALSE; |
28606
893af4a8fc08
patch 8.2.4827: typo in variable name
Bram Moolenaar <Bram@vim.org>
parents:
28602
diff
changeset
|
578 int keyround1_simplified = keyround == 1 && did_simplify; |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
579 int round; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
580 |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
581 if (keyround == 2) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
583 if (alt_keys_buf == NULL) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
584 break; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
585 keys = alt_keys_buf; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 } |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
587 else if (alt_keys_buf != NULL && do_print) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
588 // when printing always use the not-simplified map |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
589 keys = alt_keys_buf; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
591 // check arguments and translate function keys |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
592 if (haskey) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
594 len = (int)STRLEN(keys); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
595 if (len > MAXMAPLEN) // maximum length of MAXMAPLEN chars |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
597 retval = 1; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
598 goto theend; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
599 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
601 if (abbrev && maptype != MAPTYPE_UNMAP) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
602 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
603 // If an abbreviation ends in a keyword character, the |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
604 // rest must be all keyword-char or all non-keyword-char. |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
605 // Otherwise we won't be able to find the start of it in a |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
606 // vi-compatible way. |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
607 if (has_mbyte) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
609 int first, last; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
610 int same = -1; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
611 |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
612 first = vim_iswordp(keys); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
613 last = first; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
614 p = keys + (*mb_ptr2len)(keys); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
615 n = 1; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
616 while (p < keys + len) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
617 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
618 ++n; // nr of (multi-byte) chars |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
619 last = vim_iswordp(p); // type of last char |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
620 if (same == -1 && last != first) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
621 same = n - 1; // count of same char type |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
622 p += (*mb_ptr2len)(p); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
623 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
624 if (last && n > 2 && same >= 0 && same < n - 1) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
625 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
626 retval = 1; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
627 goto theend; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
628 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 } |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
630 else if (vim_iswordc(keys[len - 1])) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
631 // ends in keyword char |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 for (n = 0; n < len - 2; ++n) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 if (vim_iswordc(keys[n]) != vim_iswordc(keys[len - 2])) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 retval = 1; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 goto theend; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 } |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
638 // An abbreviation cannot contain white space. |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
639 for (n = 0; n < len; ++n) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
640 if (VIM_ISWHITE(keys[n])) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
641 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
642 retval = 1; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
643 goto theend; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
644 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
645 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
648 if (haskey && hasarg && abbrev) // if we will add an abbreviation |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
649 no_abbr = FALSE; // reset flag that indicates there are |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 // no abbreviations |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
652 if (do_print) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
653 msg_start(); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
655 // Check if a new local mapping wasn't already defined globally. |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
656 if (unique && map_table == curbuf->b_maphash |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
657 && haskey && hasarg && maptype != MAPTYPE_UNMAP) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
659 // need to loop over all global hash lists |
30920
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
660 for (int hash = 0; hash < 256 && !got_int; ++hash) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
662 if (abbrev) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
663 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
664 if (hash != 0) // there is only one abbreviation list |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
665 break; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
666 mp = first_abbr; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
667 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
668 else |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
669 mp = maphash[hash]; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
670 for ( ; mp != NULL && !got_int; mp = mp->m_next) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
672 // check entries with the same mode |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
673 if ((mp->m_mode & mode) != 0 |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
674 && mp->m_keylen == len |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
675 && STRNCMP(mp->m_keys, keys, (size_t)len) == 0) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
676 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
677 if (abbrev) |
26861
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26224
diff
changeset
|
678 semsg( |
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26224
diff
changeset
|
679 _(e_global_abbreviation_already_exists_for_str), |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
680 mp->m_keys); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
681 else |
26861
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26224
diff
changeset
|
682 semsg(_(e_global_mapping_already_exists_for_str), |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
683 mp->m_keys); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
684 retval = 5; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
685 goto theend; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
686 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
691 // When listing global mappings, also list buffer-local ones here. |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
692 if (map_table != curbuf->b_maphash && !hasarg |
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
693 && maptype != MAPTYPE_UNMAP) |
30920
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
694 list_mappings(keyround, abbrev, haskey, keys, len, |
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
695 mode, &did_local); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
697 // Find an entry in the maphash[] list that matches. |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
698 // For :unmap we may loop two times: once to try to unmap an entry with |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
699 // a matching 'from' part, a second time, if the first fails, to unmap |
26224
7d66d585bffa
patch 8.2.3643: header for source file is outdated
Bram Moolenaar <Bram@vim.org>
parents:
25431
diff
changeset
|
700 // an entry with a matching 'to' part. This was done to allow |
7d66d585bffa
patch 8.2.3643: header for source file is outdated
Bram Moolenaar <Bram@vim.org>
parents:
25431
diff
changeset
|
701 // ":ab foo bar" to be unmapped by typing ":unab foo", where "foo" will |
7d66d585bffa
patch 8.2.3643: header for source file is outdated
Bram Moolenaar <Bram@vim.org>
parents:
25431
diff
changeset
|
702 // be replaced by "bar" because of the abbreviation. |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
703 for (round = 0; (round == 0 || maptype == MAPTYPE_UNMAP) && round <= 1 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
704 && !did_it && !got_int; ++round) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
706 // need to loop over all hash lists |
30920
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
707 for (int hash = 0; hash < 256 && !got_int; ++hash) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
709 if (abbrev) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
710 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
711 if (hash > 0) // there is only one abbreviation list |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
712 break; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
713 mpp = abbr_table; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
714 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
715 else |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
716 mpp = &(map_table[hash]); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
717 for (mp = *mpp; mp != NULL && !got_int; mp = *mpp) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
719 |
18329
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
720 if ((mp->m_mode & mode) == 0) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 { |
18329
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
722 // skip entries with wrong mode |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
723 mpp = &(mp->m_next); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
724 continue; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
725 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
726 if (!haskey) // show all entries |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
727 { |
18329
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
728 if (!mp->m_simplified) |
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
729 { |
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
730 showmap(mp, map_table != maphash); |
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
731 did_it = TRUE; |
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
732 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 } |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
734 else // do we have a match? |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
736 if (round) // second round: Try unmap "rhs" string |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
737 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
738 n = (int)STRLEN(mp->m_str); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
739 p = mp->m_str; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
740 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
741 else |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
742 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
743 n = mp->m_keylen; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
744 p = mp->m_keys; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
745 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
746 if (STRNCMP(p, keys, (size_t)(n < len ? n : len)) == 0) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 { |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
748 if (maptype == MAPTYPE_UNMAP) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
749 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
750 // Delete entry. |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
751 // Only accept a full match. For abbreviations |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
752 // we ignore trailing space when matching with |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
753 // the "lhs", since an abbreviation can't have |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
754 // trailing space. |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
755 if (n != len && (!abbrev || round || n > len |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 || *skipwhite(keys + n) != NUL)) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
757 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
758 mpp = &(mp->m_next); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
759 continue; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
760 } |
28608
9ae7ccd90041
patch 8.2.4828: fix for unmapping simplified key not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
28606
diff
changeset
|
761 // In keyround for simplified keys, don't unmap |
9ae7ccd90041
patch 8.2.4828: fix for unmapping simplified key not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
28606
diff
changeset
|
762 // a mapping without m_simplified flag. |
28606
893af4a8fc08
patch 8.2.4827: typo in variable name
Bram Moolenaar <Bram@vim.org>
parents:
28602
diff
changeset
|
763 if (keyround1_simplified && !mp->m_simplified) |
28590
86bf2dabc93a
patch 8.2.4819: unmapping simplified keys also deletes other mapping
Bram Moolenaar <Bram@vim.org>
parents:
27916
diff
changeset
|
764 break; |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
765 // We reset the indicated mode bits. If nothing |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
766 // is left the entry is deleted below. |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
767 mp->m_mode &= ~mode; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
768 did_it = TRUE; // remember we did something |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
769 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
770 else if (!hasarg) // show matching entry |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
771 { |
18329
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
772 if (!mp->m_simplified) |
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
773 { |
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
774 showmap(mp, map_table != maphash); |
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
775 did_it = TRUE; |
1784afa654c8
patch 8.1.2159: some mappings are listed twice
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
776 } |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
777 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
778 else if (n != len) // new entry is ambiguous |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 mpp = &(mp->m_next); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 } |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
783 else if (unique) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
784 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
785 if (abbrev) |
26861
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26224
diff
changeset
|
786 semsg( |
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26224
diff
changeset
|
787 _(e_abbreviation_already_exists_for_str), |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
788 p); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
789 else |
26861
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26224
diff
changeset
|
790 semsg(_(e_mapping_already_exists_for_str), |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
791 p); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
792 retval = 5; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
793 goto theend; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
794 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
797 // new rhs for existing entry |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
798 mp->m_mode &= ~mode; // remove mode bits |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
799 if (mp->m_mode == 0 && !did_it) // reuse entry |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
800 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
801 char_u *newstr = vim_strsave(rhs); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
802 |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
803 if (newstr == NULL) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
804 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
805 retval = 4; // no mem |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
806 goto theend; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
807 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
808 vim_free(mp->m_str); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
809 mp->m_str = newstr; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
810 vim_free(mp->m_orig_str); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
811 mp->m_orig_str = vim_strsave(orig_rhs); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
812 mp->m_noremap = noremap; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
813 mp->m_nowait = nowait; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
814 mp->m_silent = silent; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
815 mp->m_mode = mode; |
28606
893af4a8fc08
patch 8.2.4827: typo in variable name
Bram Moolenaar <Bram@vim.org>
parents:
28602
diff
changeset
|
816 mp->m_simplified = keyround1_simplified; |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
817 #ifdef FEAT_EVAL |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
818 mp->m_expr = expr; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
819 mp->m_script_ctx = current_sctx; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
820 mp->m_script_ctx.sc_lnum += SOURCING_LNUM; |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
821 #endif |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
822 did_it = TRUE; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 } |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
824 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
825 if (mp->m_mode == 0) // entry can be deleted |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
826 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
827 map_free(mpp); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
828 continue; // continue with *mpp |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
829 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
830 |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
831 // May need to put this entry into another hash |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
832 // list. |
30920
93b603c24d23
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen
Bram Moolenaar <Bram@vim.org>
parents:
30651
diff
changeset
|
833 int new_hash = MAP_HASH(mp->m_mode, mp->m_keys[0]); |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
834 if (!abbrev && new_hash != hash) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
835 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
836 *mpp = mp->m_next; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
837 mp->m_next = map_table[new_hash]; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
838 map_table[new_hash] = mp; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
839 |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
840 continue; // continue with *mpp |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 } |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
844 mpp = &(mp->m_next); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
849 if (maptype == MAPTYPE_UNMAP) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
851 // delete entry |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
852 if (!did_it) |
28590
86bf2dabc93a
patch 8.2.4819: unmapping simplified keys also deletes other mapping
Bram Moolenaar <Bram@vim.org>
parents:
27916
diff
changeset
|
853 { |
28606
893af4a8fc08
patch 8.2.4827: typo in variable name
Bram Moolenaar <Bram@vim.org>
parents:
28602
diff
changeset
|
854 if (!keyround1_simplified) |
28590
86bf2dabc93a
patch 8.2.4819: unmapping simplified keys also deletes other mapping
Bram Moolenaar <Bram@vim.org>
parents:
27916
diff
changeset
|
855 retval = 2; // no match |
86bf2dabc93a
patch 8.2.4819: unmapping simplified keys also deletes other mapping
Bram Moolenaar <Bram@vim.org>
parents:
27916
diff
changeset
|
856 } |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
857 else if (*keys == Ctrl_C) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
858 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
859 // If CTRL-C has been unmapped, reuse it for Interrupting. |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
860 if (map_table == curbuf->b_maphash) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
861 curbuf->b_mapped_ctrl_c &= ~mode; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
862 else |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
863 mapped_ctrl_c &= ~mode; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
864 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
865 continue; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
868 if (!haskey || !hasarg) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 { |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
870 // print entries |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
871 if (!did_it && !did_local) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
872 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
873 if (abbrev) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
874 msg(_("No abbreviation found")); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
875 else |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
876 msg(_("No mapping found")); |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
877 } |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
878 goto theend; // listing finished |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
881 if (did_it) |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
882 continue; // have added the new entry already |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
884 // Get here when adding a new entry to the maphash[] list or abbrlist. |
20510
3d9a2c8d4f95
patch 8.2.0809: build failure with small features
Bram Moolenaar <Bram@vim.org>
parents:
20506
diff
changeset
|
885 if (map_add(map_table, abbr_table, keys, rhs, orig_rhs, |
3d9a2c8d4f95
patch 8.2.0809: build failure with small features
Bram Moolenaar <Bram@vim.org>
parents:
20506
diff
changeset
|
886 noremap, nowait, silent, mode, abbrev, |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
887 #ifdef FEAT_EVAL |
27223
ea2b4cb4515b
patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents:
27221
diff
changeset
|
888 expr, /* sid */ -1, /* scriptversion */ 0, /* lnum */ 0, |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
889 #endif |
28606
893af4a8fc08
patch 8.2.4827: typo in variable name
Bram Moolenaar <Bram@vim.org>
parents:
28602
diff
changeset
|
890 keyround1_simplified) == FAIL) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
891 { |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
892 retval = 4; // no mem |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
893 goto theend; |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
894 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 theend: |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 vim_free(keys_buf); |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
899 vim_free(alt_keys_buf); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 vim_free(arg_buf); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 return retval; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
902 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 * Get the mapping mode from the command name. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 static int |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 get_map_mode(char_u **cmdp, int forceit) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 char_u *p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 int modec; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 int mode; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 p = *cmdp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 modec = *p++; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
916 if (modec == 'i') |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
917 mode = MODE_INSERT; // :imap |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
918 else if (modec == 'l') |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
919 mode = MODE_LANGMAP; // :lmap |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
920 else if (modec == 'c') |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
921 mode = MODE_CMDLINE; // :cmap |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 else if (modec == 'n' && *p != 'o') // avoid :noremap |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
923 mode = MODE_NORMAL; // :nmap |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 else if (modec == 'v') |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
925 mode = MODE_VISUAL | MODE_SELECT; // :vmap |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 else if (modec == 'x') |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
927 mode = MODE_VISUAL; // :xmap |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 else if (modec == 's') |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
929 mode = MODE_SELECT; // :smap |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 else if (modec == 'o') |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
931 mode = MODE_OP_PENDING; // :omap |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 else if (modec == 't') |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
933 mode = MODE_TERMINAL; // :tmap |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 --p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 if (forceit) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
938 mode = MODE_INSERT | MODE_CMDLINE; // :map ! |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 else |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
940 mode = MODE_VISUAL | MODE_SELECT | MODE_NORMAL | MODE_OP_PENDING; |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
941 // :map |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 *cmdp = p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 return mode; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 /* |
29318
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
949 * Clear all mappings (":mapclear") or abbreviations (":abclear"). |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
950 * "abbr" should be FALSE for mappings, TRUE for abbreviations. |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 static void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 map_clear( |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 char_u *cmdp, |
29318
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
955 char_u *arg, |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 int forceit, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
957 int abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 int mode; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 int local; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 local = (STRCMP(arg, "<buffer>") == 0); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 if (!local && *arg != NUL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
965 emsg(_(e_invalid_argument)); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 return; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 mode = get_map_mode(&cmdp, forceit); |
29318
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
970 map_clear_mode(curbuf, mode, local, abbr); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 /* |
31077
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
974 * If "map_locked" is set then give an error and return TRUE. |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
975 * Otherwise return FALSE. |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
976 */ |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
977 static int |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
978 is_map_locked(void) |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
979 { |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
980 if (map_locked > 0) |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
981 { |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
982 emsg(_(e_cannot_change_mappings_while_listing)); |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
983 return TRUE; |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
984 } |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
985 return FALSE; |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
986 } |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
987 |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
988 /* |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 * Clear all mappings in "mode". |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 void |
29318
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
992 map_clear_mode( |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 buf_T *buf, // buffer for local mappings |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 int mode, // mode in which to delete |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 int local, // TRUE for buffer-local mappings |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 int abbr) // TRUE for abbreviations |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 mapblock_T *mp, **mpp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 int hash; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 int new_hash; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 |
31077
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
1002 if (is_map_locked()) |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
1003 return; |
6a2b04cd0213
patch 9.0.0873: using freed memory when executing mapclear at more prompt
Bram Moolenaar <Bram@vim.org>
parents:
30920
diff
changeset
|
1004 |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 validate_maphash(); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 for (hash = 0; hash < 256; ++hash) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 if (abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 if (hash > 0) // there is only one abbrlist |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 if (local) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 mpp = &buf->b_first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 mpp = &first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 if (local) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 mpp = &buf->b_maphash[hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 mpp = &maphash[hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 while (*mpp != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 mp = *mpp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 if (mp->m_mode & mode) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 mp->m_mode &= ~mode; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 if (mp->m_mode == 0) // entry can be deleted |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 map_free(mpp); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 // May need to put this entry into another hash list. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 new_hash = MAP_HASH(mp->m_mode, mp->m_keys[0]); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 if (!abbr && new_hash != hash) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 *mpp = mp->m_next; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 if (local) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 mp->m_next = buf->b_maphash[new_hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 buf->b_maphash[new_hash] = mp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 mp->m_next = maphash[new_hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 maphash[new_hash] = mp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 continue; // continue with *mpp |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 mpp = &(mp->m_next); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 #if defined(FEAT_EVAL) || defined(PROTO) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 int |
17946
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1061 mode_str2flags(char_u *modechars) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 int mode = 0; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 if (vim_strchr(modechars, 'n') != NULL) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1066 mode |= MODE_NORMAL; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 if (vim_strchr(modechars, 'v') != NULL) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1068 mode |= MODE_VISUAL | MODE_SELECT; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 if (vim_strchr(modechars, 'x') != NULL) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1070 mode |= MODE_VISUAL; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 if (vim_strchr(modechars, 's') != NULL) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1072 mode |= MODE_SELECT; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 if (vim_strchr(modechars, 'o') != NULL) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1074 mode |= MODE_OP_PENDING; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 if (vim_strchr(modechars, 'i') != NULL) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1076 mode |= MODE_INSERT; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 if (vim_strchr(modechars, 'l') != NULL) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1078 mode |= MODE_LANGMAP; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 if (vim_strchr(modechars, 'c') != NULL) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1080 mode |= MODE_CMDLINE; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 |
17946
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1082 return mode; |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1083 } |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1084 |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1085 /* |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1086 * Return TRUE if a map exists that has "str" in the rhs for mode "modechars". |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1087 * Recognize termcap codes in "str". |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1088 * Also checks mappings local to the current buffer. |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1089 */ |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1090 int |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1091 map_to_exists(char_u *str, char_u *modechars, int abbr) |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1092 { |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1093 char_u *rhs; |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1094 char_u *buf; |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1095 int retval; |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1096 |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17946
diff
changeset
|
1097 rhs = replace_termcodes(str, &buf, REPTERM_DO_LT, NULL); |
17946
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1098 |
ec4248c4b92c
patch 8.1.1969: popup window filter is used in all modes
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1099 retval = map_to_exists_mode(rhs, mode_str2flags(modechars), abbr); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 vim_free(buf); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 return retval; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 #endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 * Return TRUE if a map exists that has "str" in the rhs for mode "mode". |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 * Also checks mappings local to the current buffer. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 int |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 map_to_exists_mode(char_u *rhs, int mode, int abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 mapblock_T *mp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 int hash; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 int exp_buffer = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 validate_maphash(); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 // Do it twice: once for global maps and once for local maps. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 for (;;) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 for (hash = 0; hash < 256; ++hash) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 if (abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 if (hash > 0) // there is only one abbr list |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 if (exp_buffer) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 mp = curbuf->b_first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 mp = first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 else if (exp_buffer) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 mp = curbuf->b_maphash[hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 mp = maphash[hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 for (; mp; mp = mp->m_next) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 if ((mp->m_mode & mode) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 && strstr((char *)mp->m_str, (char *)rhs) != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 return TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1144 if (exp_buffer) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 exp_buffer = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 return FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 * Used below when expanding mapping/abbreviation names. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 static int expand_mapmodes = 0; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 static int expand_isabbrev = 0; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 static int expand_buffer = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 /* |
19178
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1160 * Translate an internal mapping/abbreviation representation into the |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1161 * corresponding external one recognized by :map/:abbrev commands. |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1162 * Respects the current B/k/< settings of 'cpoption'. |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1163 * |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1164 * This function is called when expanding mappings/abbreviations on the |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1165 * command-line. |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1166 * |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1167 * It uses a growarray to build the translation string since the latter can be |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1168 * wider than the original description. The caller has to free the string |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1169 * afterwards. |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1170 * |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1171 * Returns NULL when there is a problem. |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1172 */ |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1173 static char_u * |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1174 translate_mapping(char_u *str) |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1175 { |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1176 garray_T ga; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1177 int c; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1178 int modifiers; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1179 int cpo_bslash; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1180 int cpo_special; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1181 |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1182 ga_init(&ga); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1183 ga.ga_itemsize = 1; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1184 ga.ga_growsize = 40; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1185 |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1186 cpo_bslash = (vim_strchr(p_cpo, CPO_BSLASH) != NULL); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1187 cpo_special = (vim_strchr(p_cpo, CPO_SPECI) != NULL); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1188 |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1189 for (; *str; ++str) |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1190 { |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1191 c = *str; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1192 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL) |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1193 { |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1194 modifiers = 0; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1195 if (str[1] == KS_MODIFIER) |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1196 { |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1197 str++; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1198 modifiers = *++str; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1199 c = *++str; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1200 } |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1201 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL) |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1202 { |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1203 if (cpo_special) |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1204 { |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1205 ga_clear(&ga); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1206 return NULL; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1207 } |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1208 c = TO_SPECIAL(str[1], str[2]); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1209 if (c == K_ZERO) // display <Nul> as ^@ |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1210 c = NUL; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1211 str += 2; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1212 } |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1213 if (IS_SPECIAL(c) || modifiers) // special key |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1214 { |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1215 if (cpo_special) |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1216 { |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1217 ga_clear(&ga); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1218 return NULL; |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1219 } |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1220 ga_concat(&ga, get_special_key_name(c, modifiers)); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1221 continue; // for (str) |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1222 } |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1223 } |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1224 if (c == ' ' || c == '\t' || c == Ctrl_J || c == Ctrl_V |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1225 || (c == '<' && !cpo_special) || (c == '\\' && !cpo_bslash)) |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1226 ga_append(&ga, cpo_bslash ? Ctrl_V : '\\'); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1227 if (c) |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1228 ga_append(&ga, c); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1229 } |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1230 ga_append(&ga, NUL); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1231 return (char_u *)(ga.ga_data); |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1232 } |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1233 |
f7081bd2680e
patch 8.2.0148: mapping related function in wrong source file
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1234 /* |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 * Work out what to complete when doing command line completion of mapping |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 * or abbreviation names. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 char_u * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 set_context_in_map_cmd( |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 expand_T *xp, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 char_u *cmd, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 char_u *arg, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 int forceit, // TRUE if '!' given |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 int isabbrev, // TRUE if abbreviation |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1245 int isunmap, // TRUE if unmap/unabbrev command |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 cmdidx_T cmdidx) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 if (forceit && cmdidx != CMD_map && cmdidx != CMD_unmap) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 xp->xp_context = EXPAND_NOTHING; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 if (isunmap) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 expand_mapmodes = get_map_mode(&cmd, forceit || isabbrev); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1256 expand_mapmodes = MODE_INSERT | MODE_CMDLINE; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 if (!isabbrev) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1258 expand_mapmodes += MODE_VISUAL | MODE_SELECT | MODE_NORMAL |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1259 | MODE_OP_PENDING; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 expand_isabbrev = isabbrev; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 xp->xp_context = EXPAND_MAPPINGS; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 expand_buffer = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 for (;;) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 if (STRNCMP(arg, "<buffer>", 8) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 expand_buffer = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 arg = skipwhite(arg + 8); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 if (STRNCMP(arg, "<unique>", 8) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 arg = skipwhite(arg + 8); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 if (STRNCMP(arg, "<nowait>", 8) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 arg = skipwhite(arg + 8); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1282 if (STRNCMP(arg, "<silent>", 8) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 arg = skipwhite(arg + 8); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1286 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 if (STRNCMP(arg, "<special>", 9) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 arg = skipwhite(arg + 9); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1291 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 #ifdef FEAT_EVAL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 if (STRNCMP(arg, "<script>", 8) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 arg = skipwhite(arg + 8); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1297 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 if (STRNCMP(arg, "<expr>", 6) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1300 arg = skipwhite(arg + 6); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1303 #endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1304 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1306 xp->xp_pattern = arg; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 return NULL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 * Find all mapping/abbreviation names that match regexp "regmatch"'. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 * For command line expansion of ":[un]map" and ":[un]abbrev" in all modes. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 * Return OK if matches found, FAIL otherwise. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 int |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 ExpandMappings( |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1319 char_u *pat, |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 regmatch_T *regmatch, |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1321 int *numMatches, |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1322 char_u ***matches) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 mapblock_T *mp; |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1325 garray_T ga; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 int hash; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 int count; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 char_u *p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 int i; |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1330 int fuzzy; |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1331 int match; |
29212
35a30cb18005
patch 8.2.5125: MS-Windows: warnings from MinGW compiler
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
1332 int score = 0; |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1333 fuzmatch_str_T *fuzmatch; |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1334 |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1335 fuzzy = cmdline_fuzzy_complete(pat); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1336 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1337 validate_maphash(); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1339 *numMatches = 0; // return values in case of FAIL |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1340 *matches = NULL; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1341 |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1342 if (!fuzzy) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1343 ga_init2(&ga, sizeof(char *), 3); |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1344 else |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1345 ga_init2(&ga, sizeof(fuzmatch_str_T), 3); |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1346 |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1347 // First search in map modifier arguments |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1348 for (i = 0; i < 7; ++i) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 { |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1350 if (i == 0) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1351 p = (char_u *)"<silent>"; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1352 else if (i == 1) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1353 p = (char_u *)"<unique>"; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1354 #ifdef FEAT_EVAL |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1355 else if (i == 2) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1356 p = (char_u *)"<script>"; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1357 else if (i == 3) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1358 p = (char_u *)"<expr>"; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1359 #endif |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1360 else if (i == 4 && !expand_buffer) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1361 p = (char_u *)"<buffer>"; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1362 else if (i == 5) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1363 p = (char_u *)"<nowait>"; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1364 else if (i == 6) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1365 p = (char_u *)"<special>"; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1366 else |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1367 continue; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1369 if (!fuzzy) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1370 match = vim_regexec(regmatch, p, (colnr_T)0); |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1371 else |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 { |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1373 score = fuzzy_match_str(p, pat); |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1374 match = (score != 0); |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1375 } |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1376 |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1377 if (!match) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1378 continue; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1379 |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1380 if (ga_grow(&ga, 1) == FAIL) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1381 break; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1382 |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1383 if (fuzzy) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1384 { |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1385 fuzmatch = &((fuzmatch_str_T *)ga.ga_data)[ga.ga_len]; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1386 fuzmatch->idx = ga.ga_len; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1387 fuzmatch->str = vim_strsave(p); |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1388 fuzmatch->score = score; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1389 } |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1390 else |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1391 ((char_u **)ga.ga_data)[ga.ga_len] = vim_strsave(p); |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1392 ++ga.ga_len; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1393 } |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1394 |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1395 for (hash = 0; hash < 256; ++hash) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1396 { |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1397 if (expand_isabbrev) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1398 { |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1399 if (hash > 0) // only one abbrev list |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1400 break; // for (hash) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1401 mp = first_abbr; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1402 } |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1403 else if (expand_buffer) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1404 mp = curbuf->b_maphash[hash]; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1405 else |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1406 mp = maphash[hash]; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1407 for (; mp; mp = mp->m_next) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1408 { |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1409 if (!(mp->m_mode & expand_mapmodes)) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1410 continue; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1411 |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1412 p = translate_mapping(mp->m_keys); |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1413 if (p == NULL) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1416 if (!fuzzy) |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1417 match = vim_regexec(regmatch, p, (colnr_T)0); |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1418 else |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 { |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1420 score = fuzzy_match_str(p, pat); |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1421 match = (score != 0); |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1422 } |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1423 |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1424 if (!match) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 { |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1426 vim_free(p); |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1427 continue; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1428 } |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1429 |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1430 if (ga_grow(&ga, 1) == FAIL) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1431 { |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1432 vim_free(p); |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1433 break; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1434 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1436 if (fuzzy) |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1437 { |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1438 fuzmatch = &((fuzmatch_str_T *)ga.ga_data)[ga.ga_len]; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1439 fuzmatch->idx = ga.ga_len; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1440 fuzmatch->str = p; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1441 fuzmatch->score = score; |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1442 } |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1443 else |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1444 ((char_u **)ga.ga_data)[ga.ga_len] = p; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1446 ++ga.ga_len; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1447 } // for (mp) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1448 } // for (hash) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1449 |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1450 if (ga.ga_len == 0) |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1451 return FAIL; |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1452 |
27916
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1453 if (!fuzzy) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1454 { |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1455 *matches = ga.ga_data; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1456 *numMatches = ga.ga_len; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1457 } |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1458 else |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1459 { |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1460 if (fuzzymatches_to_strmatches(ga.ga_data, matches, ga.ga_len, |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1461 FALSE) == FAIL) |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1462 return FAIL; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1463 *numMatches = ga.ga_len; |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1464 } |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1465 |
6efa2f193c94
patch 8.2.4483: command completion makes two rounds to collect matches
Bram Moolenaar <Bram@vim.org>
parents:
27908
diff
changeset
|
1466 count = *numMatches; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 if (count > 1) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 char_u **ptr1; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 char_u **ptr2; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 char_u **ptr3; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 // Sort the matches |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1474 // Fuzzy matching already sorts the matches |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1475 if (!fuzzy) |
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1476 sort_strings(*matches, count); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 // Remove multiple entries |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1479 ptr1 = *matches; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 ptr2 = ptr1 + 1; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 ptr3 = ptr1 + count; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1482 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 while (ptr2 < ptr3) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1485 if (STRCMP(*ptr1, *ptr2)) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 *++ptr1 = *ptr2++; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1487 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 vim_free(*ptr2++); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 count--; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 |
27908
099c2e612827
patch 8.2.4479: no fuzzy completieon for maps and abbreviations
Bram Moolenaar <Bram@vim.org>
parents:
27750
diff
changeset
|
1495 *numMatches = count; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 return (count == 0 ? FAIL : OK); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 * Check for an abbreviation. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1501 * Cursor is at ptr[col]. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 * When inserting, mincol is where insert started. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1503 * For the command line, mincol is what is to be skipped over. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 * "c" is the character typed before check_abbr was called. It may have |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1505 * ABBR_OFF added to avoid prepending a CTRL-V to it. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1506 * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 * Historic vi practice: The last character of an abbreviation must be an id |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1508 * character ([a-zA-Z0-9_]). The characters in front of it must be all id |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 * characters or all non-id characters. This allows for abbr. "#i" to |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1510 * "#include". |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1511 * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 * Vim addition: Allow for abbreviations that end in a non-keyword character. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1513 * Then there must be white space before the abbr. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1514 * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 * return TRUE if there is an abbreviation, FALSE if not |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1516 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1517 int |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 check_abbr( |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1519 int c, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1520 char_u *ptr, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 int col, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1522 int mincol) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1523 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1524 int len; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 int scol; // starting column of the abbr. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 int j; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1527 char_u *s; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 char_u tb[MB_MAXBYTES + 4]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 mapblock_T *mp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1530 mapblock_T *mp2; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1531 int clen = 0; // length in characters |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1532 int is_id = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1533 int vim_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1534 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1535 if (typebuf.tb_no_abbr_cnt) // abbrev. are not recursive |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1536 return FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1537 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1538 // no remapping implies no abbreviation, except for CTRL-] |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1539 if (noremap_keys() && c != Ctrl_RSB) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1540 return FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1541 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1542 // Check for word before the cursor: If it ends in a keyword char all |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1543 // chars before it must be keyword chars or non-keyword chars, but not |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1544 // white space. If it ends in a non-keyword char we accept any characters |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1545 // before it except white space. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1546 if (col == 0) // cannot be an abbr. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1547 return FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1548 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 if (has_mbyte) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1550 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1551 char_u *p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1552 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1553 p = mb_prevptr(ptr, ptr + col); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 if (!vim_iswordp(p)) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1555 vim_abbr = TRUE; // Vim added abbr. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1557 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1558 vim_abbr = FALSE; // vi compatible abbr. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1559 if (p > ptr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1560 is_id = vim_iswordp(mb_prevptr(ptr, p)); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1561 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1562 clen = 1; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1563 while (p > ptr + mincol) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1564 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1565 p = mb_prevptr(ptr, p); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1566 if (vim_isspace(*p) || (!vim_abbr && is_id != vim_iswordp(p))) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1567 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1568 p += (*mb_ptr2len)(p); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1569 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1570 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1571 ++clen; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1572 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1573 scol = (int)(p - ptr); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1574 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1575 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1576 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1577 if (!vim_iswordc(ptr[col - 1])) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1578 vim_abbr = TRUE; // Vim added abbr. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1579 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1580 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1581 vim_abbr = FALSE; // vi compatible abbr. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1582 if (col > 1) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1583 is_id = vim_iswordc(ptr[col - 2]); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1584 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1585 for (scol = col - 1; scol > 0 && !vim_isspace(ptr[scol - 1]) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1586 && (vim_abbr || is_id == vim_iswordc(ptr[scol - 1])); --scol) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1587 ; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1588 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1589 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1590 if (scol < mincol) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1591 scol = mincol; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1592 if (scol < col) // there is a word in front of the cursor |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1593 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1594 ptr += scol; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1595 len = col - scol; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1596 mp = curbuf->b_first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1597 mp2 = first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1598 if (mp == NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1599 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1600 mp = mp2; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1601 mp2 = NULL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1602 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 for ( ; mp; mp->m_next == NULL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1604 ? (mp = mp2, mp2 = NULL) : (mp = mp->m_next)) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1605 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1606 int qlen = mp->m_keylen; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1607 char_u *q = mp->m_keys; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1608 int match; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1609 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1610 if (vim_strbyte(mp->m_keys, K_SPECIAL) != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1612 char_u *qe = vim_strsave(mp->m_keys); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1613 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1614 // might have CSI escaped mp->m_keys |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1615 if (qe != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1616 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1617 q = qe; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1618 vim_unescape_csi(q); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 qlen = (int)STRLEN(q); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1620 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1621 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1622 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1623 // find entries with right mode and keys |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 match = (mp->m_mode & State) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 && qlen == len |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 && !STRNCMP(q, ptr, (size_t)len); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 if (q != mp->m_keys) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1628 vim_free(q); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 if (match) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1631 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1632 if (mp != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1633 { |
27221
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1634 int noremap; |
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1635 int silent; |
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1636 #ifdef FEAT_EVAL |
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1637 int expr; |
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1638 #endif |
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1639 |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1640 // Found a match: |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 // Insert the rest of the abbreviation in typebuf.tb_buf[]. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1642 // This goes from end to start. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1643 // |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1644 // Characters 0x000 - 0x100: normal chars, may need CTRL-V, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 // except K_SPECIAL: Becomes K_SPECIAL KS_SPECIAL KE_FILLER |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 // Characters where IS_SPECIAL() == TRUE: key codes, need |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1647 // K_SPECIAL. Other characters (with ABBR_OFF): don't use CTRL-V. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1648 // |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1649 // Character CTRL-] is treated specially - it completes the |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1650 // abbreviation, but is not inserted into the input stream. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 j = 0; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1652 if (c != Ctrl_RSB) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1653 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1654 // special key code, split up |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1655 if (IS_SPECIAL(c) || c == K_SPECIAL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1656 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1657 tb[j++] = K_SPECIAL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1658 tb[j++] = K_SECOND(c); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1659 tb[j++] = K_THIRD(c); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1660 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1661 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1662 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1663 if (c < ABBR_OFF && (c < ' ' || c > '~')) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1664 tb[j++] = Ctrl_V; // special char needs CTRL-V |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1665 if (has_mbyte) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1666 { |
24559
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1667 int newlen; |
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1668 char_u *escaped; |
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1669 |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1670 // if ABBR_OFF has been added, remove it here |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1671 if (c >= ABBR_OFF) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1672 c -= ABBR_OFF; |
24559
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1673 newlen = (*mb_char2bytes)(c, tb + j); |
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1674 tb[j + newlen] = NUL; |
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1675 // Need to escape K_SPECIAL. |
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1676 escaped = vim_strsave_escape_csi(tb + j); |
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1677 if (escaped != NULL) |
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1678 { |
24574
3a3d5ee00574
patch 8.2.2826: compiler warnings for int to size_t conversion
Bram Moolenaar <Bram@vim.org>
parents:
24559
diff
changeset
|
1679 newlen = (int)STRLEN(escaped); |
24559
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1680 mch_memmove(tb + j, escaped, newlen); |
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1681 j += newlen; |
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1682 vim_free(escaped); |
839145e0fdaa
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work
Bram Moolenaar <Bram@vim.org>
parents:
24529
diff
changeset
|
1683 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1684 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1685 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1686 tb[j++] = c; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1687 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1688 tb[j] = NUL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1689 // insert the last typed char |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1690 (void)ins_typebuf(tb, 1, 0, TRUE, mp->m_silent); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 } |
27221
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1692 |
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1693 // copy values here, calling eval_map_expr() may make "mp" invalid! |
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1694 noremap = mp->m_noremap; |
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1695 silent = mp->m_silent; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1696 #ifdef FEAT_EVAL |
27221
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1697 expr = mp->m_expr; |
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1698 |
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1699 if (expr) |
27061
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1700 s = eval_map_expr(mp, c); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1701 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1702 #endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1703 s = mp->m_str; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1704 if (s != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1705 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1706 // insert the to string |
27221
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1707 (void)ins_typebuf(s, noremap, 0, TRUE, silent); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1708 // no abbrev. for these chars |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1709 typebuf.tb_no_abbr_cnt += (int)STRLEN(s) + j + 1; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1710 #ifdef FEAT_EVAL |
27221
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1711 if (expr) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1712 vim_free(s); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1713 #endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1714 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1715 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1716 tb[0] = Ctrl_H; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1717 tb[1] = NUL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1718 if (has_mbyte) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1719 len = clen; // Delete characters instead of bytes |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1720 while (len-- > 0) // delete the from string |
27221
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1721 (void)ins_typebuf(tb, 1, 0, TRUE, silent); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1722 return TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1723 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1724 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1725 return FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1726 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1727 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1728 #ifdef FEAT_EVAL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1729 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1730 * Evaluate the RHS of a mapping or abbreviations and take care of escaping |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1731 * special characters. |
27221
165a799b4129
patch 8.2.4139: using freed memory in expression abbreviation
Bram Moolenaar <Bram@vim.org>
parents:
27165
diff
changeset
|
1732 * Careful: after this "mp" will be invalid if the mapping was deleted. |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1733 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1734 char_u * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1735 eval_map_expr( |
27061
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1736 mapblock_T *mp, |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1737 int c) // NUL or typed character for abbreviation |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1738 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1739 char_u *res; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1740 char_u *p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1741 char_u *expr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1742 pos_T save_cursor; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1743 int save_msg_col; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1744 int save_msg_row; |
27061
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1745 scid_T save_sctx_sid = current_sctx.sc_sid; |
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1746 int save_sctx_version = current_sctx.sc_version; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1747 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1748 // Remove escaping of CSI, because "str" is in a format to be used as |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1749 // typeahead. |
27061
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1750 expr = vim_strsave(mp->m_str); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1751 if (expr == NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1752 return NULL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1753 vim_unescape_csi(expr); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1754 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1755 // Forbid changing text or using ":normal" to avoid most of the bad side |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1756 // effects. Also restore the cursor position. |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
28817
diff
changeset
|
1757 ++textlock; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1758 ++ex_normal_lock; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1759 set_vim_var_char(c); // set v:char to the typed character |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1760 save_cursor = curwin->w_cursor; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1761 save_msg_col = msg_col; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1762 save_msg_row = msg_row; |
27061
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1763 if (mp->m_script_ctx.sc_version == SCRIPT_VERSION_VIM9) |
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1764 { |
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1765 current_sctx.sc_sid = mp->m_script_ctx.sc_sid; |
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1766 current_sctx.sc_version = SCRIPT_VERSION_VIM9; |
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1767 } |
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1768 |
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1769 // Note: the evaluation may make "mp" invalid. |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30226
diff
changeset
|
1770 p = eval_to_string(expr, FALSE, FALSE); |
27061
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1771 |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
28817
diff
changeset
|
1772 --textlock; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1773 --ex_normal_lock; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1774 curwin->w_cursor = save_cursor; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1775 msg_col = save_msg_col; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1776 msg_row = save_msg_row; |
27061
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1777 current_sctx.sc_sid = save_sctx_sid; |
1a56c0252772
patch 8.2.4059: Vim9: an expression of a map cannot access script-local items
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1778 current_sctx.sc_version = save_sctx_version; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1779 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1780 vim_free(expr); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1781 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1782 if (p == NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1783 return NULL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1784 // Escape CSI in the result to be able to use the string as typeahead. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1785 res = vim_strsave_escape_csi(p); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1786 vim_free(p); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1787 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1788 return res; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1789 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1790 #endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1791 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1792 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1793 * Copy "p" to allocated memory, escaping K_SPECIAL and CSI so that the result |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1794 * can be put in the typeahead buffer. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1795 * Returns NULL when out of memory. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1796 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1797 char_u * |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22468
diff
changeset
|
1798 vim_strsave_escape_csi(char_u *p) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1799 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1800 char_u *res; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1801 char_u *s, *d; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1802 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1803 // Need a buffer to hold up to three times as much. Four in case of an |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1804 // illegal utf-8 byte: |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1805 // 0xc0 -> 0xc3 0x80 -> 0xc3 K_SPECIAL KS_SPECIAL KE_FILLER |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1806 res = alloc(STRLEN(p) * 4 + 1); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1807 if (res != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1808 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 d = res; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1810 for (s = p; *s != NUL; ) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1811 { |
30651
c6e85b9a88a0
patch 9.0.0660: mapping with CTRL keys does not work in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1812 if ((s[0] == K_SPECIAL |
c6e85b9a88a0
patch 9.0.0660: mapping with CTRL keys does not work in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1813 #ifdef FEAT_GUI |
c6e85b9a88a0
patch 9.0.0660: mapping with CTRL keys does not work in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1814 || (gui.in_use && s[0] == CSI) |
c6e85b9a88a0
patch 9.0.0660: mapping with CTRL keys does not work in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1815 #endif |
c6e85b9a88a0
patch 9.0.0660: mapping with CTRL keys does not work in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1816 ) && s[1] != NUL && s[2] != NUL) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1818 // Copy special key unmodified. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1819 *d++ = *s++; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1820 *d++ = *s++; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1821 *d++ = *s++; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1822 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1823 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1824 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1825 // Add character, possibly multi-byte to destination, escaping |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1826 // CSI and K_SPECIAL. Be careful, it can be an illegal byte! |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1827 d = add_char2buf(PTR2CHAR(s), d); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1828 s += MB_CPTR2LEN(s); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1830 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 *d = NUL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1832 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1833 return res; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1836 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1837 * Remove escaping from CSI and K_SPECIAL characters. Reverse of |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1838 * vim_strsave_escape_csi(). Works in-place. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1839 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1840 void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1841 vim_unescape_csi(char_u *p) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1842 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1843 char_u *s = p, *d = p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1844 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1845 while (*s != NUL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1846 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1847 if (s[0] == K_SPECIAL && s[1] == KS_SPECIAL && s[2] == KE_FILLER) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1848 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1849 *d++ = K_SPECIAL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1850 s += 3; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1851 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1852 else if ((s[0] == K_SPECIAL || s[0] == CSI) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1853 && s[1] == KS_EXTRA && s[2] == (int)KE_CSI) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1854 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1855 *d++ = CSI; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1856 s += 3; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1857 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1858 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1859 *d++ = *s++; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1860 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1861 *d = NUL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1862 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1863 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1864 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1865 * Write map commands for the current mappings to an .exrc file. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1866 * Return FAIL on error, OK otherwise. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1867 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1868 int |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1869 makemap( |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1870 FILE *fd, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1871 buf_T *buf) // buffer for local mappings or NULL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1873 mapblock_T *mp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1874 char_u c1, c2, c3; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1875 char_u *p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1876 char *cmd; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1877 int abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1878 int hash; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1879 int did_cpo = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1880 int i; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 validate_maphash(); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1883 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1884 // Do the loop twice: Once for mappings, once for abbreviations. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1885 // Then loop over all map hash lists. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 for (abbr = 0; abbr < 2; ++abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 for (hash = 0; hash < 256; ++hash) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1888 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 if (abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1891 if (hash > 0) // there is only one abbr list |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1892 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1893 if (buf != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 mp = buf->b_first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 mp = first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 if (buf != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1901 mp = buf->b_maphash[hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1902 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 mp = maphash[hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1906 for ( ; mp; mp = mp->m_next) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1907 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1908 // skip script-local mappings |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1909 if (mp->m_noremap == REMAP_SCRIPT) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1910 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1911 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1912 // skip mappings that contain a <SNR> (script-local thing), |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1913 // they probably don't work when loaded again |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1914 for (p = mp->m_str; *p != NUL; ++p) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1915 if (p[0] == K_SPECIAL && p[1] == KS_EXTRA |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1916 && p[2] == (int)KE_SNR) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1917 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1918 if (*p != NUL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1919 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1920 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1921 // It's possible to create a mapping and then ":unmap" certain |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1922 // modes. We recreate this here by mapping the individual |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1923 // modes, which requires up to three of them. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1924 c1 = NUL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1925 c2 = NUL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1926 c3 = NUL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 if (abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 cmd = "abbr"; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1929 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 cmd = "map"; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 switch (mp->m_mode) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1932 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1933 case MODE_NORMAL | MODE_VISUAL | MODE_SELECT |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1934 | MODE_OP_PENDING: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1935 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1936 case MODE_NORMAL: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1937 c1 = 'n'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1939 case MODE_VISUAL: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1940 c1 = 'x'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1941 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1942 case MODE_SELECT: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1943 c1 = 's'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1944 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1945 case MODE_OP_PENDING: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1946 c1 = 'o'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1947 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1948 case MODE_NORMAL | MODE_VISUAL: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 c1 = 'n'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1950 c2 = 'x'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1951 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1952 case MODE_NORMAL | MODE_SELECT: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1953 c1 = 'n'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1954 c2 = 's'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1955 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1956 case MODE_NORMAL | MODE_OP_PENDING: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1957 c1 = 'n'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1958 c2 = 'o'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1959 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1960 case MODE_VISUAL | MODE_SELECT: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1961 c1 = 'v'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1962 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1963 case MODE_VISUAL | MODE_OP_PENDING: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1964 c1 = 'x'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1965 c2 = 'o'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1966 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1967 case MODE_SELECT | MODE_OP_PENDING: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1968 c1 = 's'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1969 c2 = 'o'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1970 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1971 case MODE_NORMAL | MODE_VISUAL | MODE_SELECT: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 c1 = 'n'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 c2 = 'v'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1975 case MODE_NORMAL | MODE_VISUAL | MODE_OP_PENDING: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1976 c1 = 'n'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1977 c2 = 'x'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1978 c3 = 'o'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1979 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1980 case MODE_NORMAL | MODE_SELECT | MODE_OP_PENDING: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1981 c1 = 'n'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 c2 = 's'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1983 c3 = 'o'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1984 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1985 case MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1986 c1 = 'v'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1987 c2 = 'o'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1988 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1989 case MODE_CMDLINE | MODE_INSERT: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1990 if (!abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1991 cmd = "map!"; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1992 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1993 case MODE_CMDLINE: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1994 c1 = 'c'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1995 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1996 case MODE_INSERT: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1997 c1 = 'i'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1998 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
1999 case MODE_LANGMAP: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2000 c1 = 'l'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2001 break; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2002 case MODE_TERMINAL: |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2003 c1 = 't'; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2005 default: |
26861
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26224
diff
changeset
|
2006 iemsg(_(e_makemap_illegal_mode)); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2007 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2008 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2009 do // do this twice if c2 is set, 3 times with c3 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2010 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2011 // When outputting <> form, need to make sure that 'cpo' |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2012 // is set to the Vim default. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2013 if (!did_cpo) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2014 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2015 if (*mp->m_str == NUL) // will use <Nop> |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2016 did_cpo = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2017 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2018 for (i = 0; i < 2; ++i) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2019 for (p = (i ? mp->m_str : mp->m_keys); *p; ++p) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2020 if (*p == K_SPECIAL || *p == NL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2021 did_cpo = TRUE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2022 if (did_cpo) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2023 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2024 if (fprintf(fd, "let s:cpo_save=&cpo") < 0 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2025 || put_eol(fd) < 0 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2026 || fprintf(fd, "set cpo&vim") < 0 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2027 || put_eol(fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2028 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2029 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2030 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2031 if (c1 && putc(c1, fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2032 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2033 if (mp->m_noremap != REMAP_YES && fprintf(fd, "nore") < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2034 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2035 if (fputs(cmd, fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2036 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2037 if (buf != NULL && fputs(" <buffer>", fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2038 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2039 if (mp->m_nowait && fputs(" <nowait>", fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2040 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2041 if (mp->m_silent && fputs(" <silent>", fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2042 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2043 #ifdef FEAT_EVAL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2044 if (mp->m_noremap == REMAP_SCRIPT |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2045 && fputs("<script>", fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2046 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2047 if (mp->m_expr && fputs(" <expr>", fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2048 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2049 #endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2050 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2051 if ( putc(' ', fd) < 0 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2052 || put_escstr(fd, mp->m_keys, 0) == FAIL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2053 || putc(' ', fd) < 0 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2054 || put_escstr(fd, mp->m_str, 1) == FAIL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2055 || put_eol(fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2056 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2057 c1 = c2; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2058 c2 = c3; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2059 c3 = NUL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2060 } while (c1 != NUL); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2061 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2062 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2063 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2064 if (did_cpo) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2065 if (fprintf(fd, "let &cpo=s:cpo_save") < 0 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2066 || put_eol(fd) < 0 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2067 || fprintf(fd, "unlet s:cpo_save") < 0 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2068 || put_eol(fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2069 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2070 return OK; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2071 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2072 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2073 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2074 * write escape string to file |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2075 * "what": 0 for :map lhs, 1 for :map rhs, 2 for :set |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2076 * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2077 * return FAIL for failure, OK otherwise |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2078 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2079 int |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2080 put_escstr(FILE *fd, char_u *strstart, int what) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2081 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2082 char_u *str = strstart; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2083 int c; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2084 int modifiers; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2085 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2086 // :map xx <Nop> |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2087 if (*str == NUL && what == 1) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2088 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2089 if (fprintf(fd, "<Nop>") < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2090 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2091 return OK; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2092 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2093 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2094 for ( ; *str != NUL; ++str) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2095 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2096 char_u *p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2097 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2098 // Check for a multi-byte character, which may contain escaped |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2099 // K_SPECIAL and CSI bytes |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2100 p = mb_unescape(&str); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2101 if (p != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2102 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2103 while (*p != NUL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2104 if (fputc(*p++, fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2105 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2106 --str; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2107 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2108 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2109 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2110 c = *str; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2111 // Special key codes have to be translated to be able to make sense |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2112 // when they are read back. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2113 if (c == K_SPECIAL && what != 2) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2114 { |
21996
808edde1e97d
patch 8.2.1547: various comment problems
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2115 modifiers = 0; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2116 if (str[1] == KS_MODIFIER) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2117 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2118 modifiers = str[2]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2119 str += 3; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2120 c = *str; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2121 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2122 if (c == K_SPECIAL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2123 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2124 c = TO_SPECIAL(str[1], str[2]); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2125 str += 2; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2126 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2127 if (IS_SPECIAL(c) || modifiers) // special key |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2128 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2129 if (fputs((char *)get_special_key_name(c, modifiers), fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2130 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2131 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2132 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2133 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2134 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2135 // A '\n' in a map command should be written as <NL>. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2136 // A '\n' in a set command should be written as \^V^J. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2137 if (c == NL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2138 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2139 if (what == 2) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2140 { |
27490
fb4c30606b4a
patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
27243
diff
changeset
|
2141 if (fprintf(fd, "\\\026\n") < 0) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2142 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2143 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2144 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2145 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2146 if (fprintf(fd, "<NL>") < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2147 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2148 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2149 continue; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2150 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2151 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2152 // Some characters have to be escaped with CTRL-V to |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2153 // prevent them from misinterpreted in DoOneCmd(). |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2154 // A space, Tab and '"' has to be escaped with a backslash to |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2155 // prevent it to be misinterpreted in do_set(). |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2156 // A space has to be escaped with a CTRL-V when it's at the start of a |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2157 // ":map" rhs. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2158 // A '<' has to be escaped with a CTRL-V to prevent it being |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2159 // interpreted as the start of a special key name. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2160 // A space in the lhs of a :map needs a CTRL-V. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2161 if (what == 2 && (VIM_ISWHITE(c) || c == '"' || c == '\\')) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2162 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2163 if (putc('\\', fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2164 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2165 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2166 else if (c < ' ' || c > '~' || c == '|' |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2167 || (what == 0 && c == ' ') |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2168 || (what == 1 && str == strstart && c == ' ') |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2169 || (what != 2 && c == '<')) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2170 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2171 if (putc(Ctrl_V, fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2172 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2173 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2174 if (putc(c, fd) < 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2175 return FAIL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2176 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2177 return OK; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2178 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2179 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2180 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2181 * Check all mappings for the presence of special key codes. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2182 * Used after ":set term=xxx". |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2183 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2184 void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2185 check_map_keycodes(void) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2186 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2187 mapblock_T *mp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2188 char_u *p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2189 int i; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2190 char_u buf[3]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2191 int abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2192 int hash; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2193 buf_T *bp; |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
2194 ESTACK_CHECK_DECLARATION |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2195 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2196 validate_maphash(); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2197 // avoids giving error messages |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2198 estack_push(ETYPE_INTERNAL, (char_u *)"mappings", 0); |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
2199 ESTACK_CHECK_SETUP |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2200 |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18329
diff
changeset
|
2201 // Do this once for each buffer, and then once for global |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2202 // mappings/abbreviations with bp == NULL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2203 for (bp = firstbuf; ; bp = bp->b_next) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2204 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2205 // Do the loop twice: Once for mappings, once for abbreviations. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2206 // Then loop over all map hash lists. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2207 for (abbr = 0; abbr <= 1; ++abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2208 for (hash = 0; hash < 256; ++hash) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2209 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2210 if (abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2211 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2212 if (hash) // there is only one abbr list |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2213 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2214 if (bp != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2215 mp = bp->b_first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2216 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2217 mp = first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2218 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2219 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2220 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2221 if (bp != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2222 mp = bp->b_maphash[hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2223 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2224 mp = maphash[hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2225 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2226 for ( ; mp != NULL; mp = mp->m_next) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2227 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2228 for (i = 0; i <= 1; ++i) // do this twice |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2229 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2230 if (i == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2231 p = mp->m_keys; // once for the "from" part |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2232 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2233 p = mp->m_str; // and once for the "to" part |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2234 while (*p) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2235 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2236 if (*p == K_SPECIAL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2237 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2238 ++p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2239 if (*p < 128) // for "normal" tcap entries |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2240 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2241 buf[0] = p[0]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2242 buf[1] = p[1]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2243 buf[2] = NUL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2244 (void)add_termcap_entry(buf, FALSE); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2245 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2246 ++p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2247 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2248 ++p; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2249 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2250 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2251 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2252 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2253 if (bp == NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2254 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2255 } |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
2256 ESTACK_CHECK_NOW |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2257 estack_pop(); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2258 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2259 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2260 #if defined(FEAT_EVAL) || defined(PROTO) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2261 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2262 * Check the string "keys" against the lhs of all mappings. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2263 * Return pointer to rhs of mapping (mapblock->m_str). |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2264 * NULL when no mapping found. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2265 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2266 char_u * |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2267 check_map( |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2268 char_u *keys, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2269 int mode, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2270 int exact, // require exact match |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2271 int ign_mod, // ignore preceding modifier |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2272 int abbr, // do abbreviations |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2273 mapblock_T **mp_ptr, // return: pointer to mapblock or NULL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2274 int *local_ptr) // return: buffer-local mapping or NULL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2275 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2276 int hash; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2277 int len, minlen; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2278 mapblock_T *mp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2279 char_u *s; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2280 int local; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2281 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2282 validate_maphash(); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2283 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2284 len = (int)STRLEN(keys); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2285 for (local = 1; local >= 0; --local) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2286 // loop over all hash lists |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2287 for (hash = 0; hash < 256; ++hash) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2288 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2289 if (abbr) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2290 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2291 if (hash > 0) // there is only one list. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2292 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2293 if (local) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2294 mp = curbuf->b_first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2295 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2296 mp = first_abbr; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2297 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2298 else if (local) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2299 mp = curbuf->b_maphash[hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2300 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2301 mp = maphash[hash]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2302 for ( ; mp != NULL; mp = mp->m_next) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2303 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2304 // skip entries with wrong mode, wrong length and not matching |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2305 // ones |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2306 if ((mp->m_mode & mode) && (!exact || mp->m_keylen == len)) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2307 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2308 if (len > mp->m_keylen) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2309 minlen = mp->m_keylen; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2310 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2311 minlen = len; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2312 s = mp->m_keys; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2313 if (ign_mod && s[0] == K_SPECIAL && s[1] == KS_MODIFIER |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2314 && s[2] != NUL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2315 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2316 s += 3; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2317 if (len > mp->m_keylen - 3) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2318 minlen = mp->m_keylen - 3; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2319 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2320 if (STRNCMP(s, keys, minlen) == 0) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2321 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2322 if (mp_ptr != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2323 *mp_ptr = mp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2324 if (local_ptr != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2325 *local_ptr = local; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2326 return mp->m_str; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2327 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2328 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2329 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2330 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2331 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2332 return NULL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2333 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2334 |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2335 /* |
29318
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2336 * "hasmapto()" function |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2337 */ |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2338 void |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2339 f_hasmapto(typval_T *argvars, typval_T *rettv) |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2340 { |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2341 char_u *name; |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2342 char_u *mode; |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2343 char_u buf[NUMBUFLEN]; |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2344 int abbr = FALSE; |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2345 |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2346 if (in_vim9script() |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2347 && (check_for_string_arg(argvars, 0) == FAIL |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2348 || check_for_opt_string_arg(argvars, 1) == FAIL |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2349 || (argvars[1].v_type != VAR_UNKNOWN |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2350 && check_for_opt_bool_arg(argvars, 2) == FAIL))) |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2351 return; |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2352 |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2353 name = tv_get_string(&argvars[0]); |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2354 if (argvars[1].v_type == VAR_UNKNOWN) |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2355 mode = (char_u *)"nvo"; |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2356 else |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2357 { |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2358 mode = tv_get_string_buf(&argvars[1], buf); |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2359 if (argvars[2].v_type != VAR_UNKNOWN) |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2360 abbr = (int)tv_get_bool(&argvars[2]); |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2361 } |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2362 |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2363 if (map_to_exists(name, mode, abbr)) |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2364 rettv->vval.v_number = TRUE; |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2365 else |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2366 rettv->vval.v_number = FALSE; |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2367 } |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2368 |
fcf524e1e97e
patch 9.0.0002: map functionality outside of map.c
Bram Moolenaar <Bram@vim.org>
parents:
29212
diff
changeset
|
2369 /* |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2370 * Fill in the empty dictionary with items as defined by maparg builtin. |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2371 */ |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2372 static void |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2373 mapblock2dict( |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2374 mapblock_T *mp, |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2375 dict_T *dict, |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2376 char_u *lhsrawalt, // may be NULL |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2377 int buffer_local, // false if not buffer local mapping |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2378 int abbr) // true if abbreviation |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2379 { |
30226
b6b803ed4a53
patch 9.0.0449: there is no easy way to translate a key code into a string
Bram Moolenaar <Bram@vim.org>
parents:
30007
diff
changeset
|
2380 char_u *lhs = str2special_save(mp->m_keys, TRUE, FALSE); |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2381 char_u *mapmode = map_mode_to_chars(mp->m_mode); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2382 |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2383 dict_add_string(dict, "lhs", lhs); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2384 vim_free(lhs); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2385 dict_add_string(dict, "lhsraw", mp->m_keys); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2386 if (lhsrawalt) |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2387 // Also add the value for the simplified entry. |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2388 dict_add_string(dict, "lhsrawalt", lhsrawalt); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2389 dict_add_string(dict, "rhs", mp->m_orig_str); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2390 dict_add_number(dict, "noremap", mp->m_noremap ? 1L : 0L); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2391 dict_add_number(dict, "script", mp->m_noremap == REMAP_SCRIPT |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2392 ? 1L : 0L); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2393 dict_add_number(dict, "expr", mp->m_expr ? 1L : 0L); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2394 dict_add_number(dict, "silent", mp->m_silent ? 1L : 0L); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2395 dict_add_number(dict, "sid", (long)mp->m_script_ctx.sc_sid); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2396 dict_add_number(dict, "scriptversion", |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2397 (long)mp->m_script_ctx.sc_version); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2398 dict_add_number(dict, "lnum", (long)mp->m_script_ctx.sc_lnum); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2399 dict_add_number(dict, "buffer", (long)buffer_local); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2400 dict_add_number(dict, "nowait", mp->m_nowait ? 1L : 0L); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2401 dict_add_string(dict, "mode", mapmode); |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2402 dict_add_number(dict, "abbr", abbr ? 1L : 0L); |
28817
1ad71fcbf546
patch 8.2.4932: not easy to filter the output of maplist()
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
2403 dict_add_number(dict, "mode_bits", mp->m_mode); |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2404 |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2405 vim_free(mapmode); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2406 } |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2407 |
25431
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2408 static void |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2409 get_maparg(typval_T *argvars, typval_T *rettv, int exact) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2410 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2411 char_u *keys; |
20522
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2412 char_u *keys_simplified; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2413 char_u *which; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2414 char_u buf[NUMBUFLEN]; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2415 char_u *keys_buf = NULL; |
20522
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2416 char_u *alt_keys_buf = NULL; |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2417 int did_simplify = FALSE; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2418 char_u *rhs; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2419 int mode; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2420 int abbr = FALSE; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2421 int get_dict = FALSE; |
28614
9ae2c32841fb
patch 8.2.4831: crash when using maparg() and unmapping simplified keys
Bram Moolenaar <Bram@vim.org>
parents:
28608
diff
changeset
|
2422 mapblock_T *mp = NULL; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2423 int buffer_local; |
20522
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2424 int flags = REPTERM_FROM_PART | REPTERM_DO_LT; |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2425 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2426 // return empty string for failure |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2427 rettv->v_type = VAR_STRING; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2428 rettv->vval.v_string = NULL; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2429 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2430 keys = tv_get_string(&argvars[0]); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2431 if (*keys == NUL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2432 return; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2433 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2434 if (argvars[1].v_type != VAR_UNKNOWN) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2435 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2436 which = tv_get_string_buf_chk(&argvars[1], buf); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2437 if (argvars[2].v_type != VAR_UNKNOWN) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2438 { |
22055
88bedbb4ba75
patch 8.2.1577: Vim9: hasmapto()/mapcheck()/maparg() do nottake "true" arg
Bram Moolenaar <Bram@vim.org>
parents:
21996
diff
changeset
|
2439 abbr = (int)tv_get_bool(&argvars[2]); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2440 if (argvars[3].v_type != VAR_UNKNOWN) |
22055
88bedbb4ba75
patch 8.2.1577: Vim9: hasmapto()/mapcheck()/maparg() do nottake "true" arg
Bram Moolenaar <Bram@vim.org>
parents:
21996
diff
changeset
|
2441 get_dict = (int)tv_get_bool(&argvars[3]); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2442 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2443 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2444 else |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2445 which = (char_u *)""; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2446 if (which == NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2447 return; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2448 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2449 mode = get_map_mode(&which, 0); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2450 |
20522
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2451 keys_simplified = replace_termcodes(keys, &keys_buf, flags, &did_simplify); |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2452 rhs = check_map(keys_simplified, mode, exact, FALSE, abbr, |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2453 &mp, &buffer_local); |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2454 if (did_simplify) |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2455 { |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2456 // When the lhs is being simplified the not-simplified keys are |
23229
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
2457 // preferred for printing, like in do_map(). |
20522
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2458 (void)replace_termcodes(keys, &alt_keys_buf, |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2459 flags | REPTERM_NO_SIMPLIFY, NULL); |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2460 rhs = check_map(alt_keys_buf, mode, exact, FALSE, abbr, &mp, |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2461 &buffer_local); |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2462 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2463 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2464 if (!get_dict) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2465 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2466 // Return a string. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2467 if (rhs != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2468 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2469 if (*rhs == NUL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2470 rettv->vval.v_string = vim_strsave((char_u *)"<Nop>"); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2471 else |
30226
b6b803ed4a53
patch 9.0.0449: there is no easy way to translate a key code into a string
Bram Moolenaar <Bram@vim.org>
parents:
30007
diff
changeset
|
2472 rettv->vval.v_string = str2special_save(rhs, FALSE, FALSE); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2473 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2474 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2475 } |
29175
755ab148288b
patch 8.2.5107: some callers of rettv_list_alloc() check for not OK
Bram Moolenaar <Bram@vim.org>
parents:
29173
diff
changeset
|
2476 else if (rettv_dict_alloc(rettv) == OK && rhs != NULL) |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2477 mapblock2dict(mp, rettv->vval.v_dict, |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2478 did_simplify ? keys_simplified : NULL, |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2479 buffer_local, abbr); |
20522
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2480 |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2481 vim_free(keys_buf); |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2482 vim_free(alt_keys_buf); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2483 } |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2484 |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2485 /* |
28602
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2486 * "maplist()" function |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2487 */ |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2488 void |
28602
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2489 f_maplist(typval_T *argvars UNUSED, typval_T *rettv) |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2490 { |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2491 dict_T *d; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2492 mapblock_T *mp; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2493 int buffer_local; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2494 char_u *keys_buf; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2495 int did_simplify; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2496 int hash; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2497 char_u *lhs; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2498 const int flags = REPTERM_FROM_PART | REPTERM_DO_LT; |
28602
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2499 int abbr = FALSE; |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2500 |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2501 if (in_vim9script() && check_for_opt_bool_arg(argvars, 0) == FAIL) |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2502 return; |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2503 if (argvars[0].v_type != VAR_UNKNOWN) |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2504 abbr = tv_get_bool(&argvars[0]); |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2505 |
29175
755ab148288b
patch 8.2.5107: some callers of rettv_list_alloc() check for not OK
Bram Moolenaar <Bram@vim.org>
parents:
29173
diff
changeset
|
2506 if (rettv_list_alloc(rettv) == FAIL) |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2507 return; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2508 |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2509 validate_maphash(); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2510 |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2511 // Do it twice: once for global maps and once for local maps. |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2512 for (buffer_local = 0; buffer_local <= 1; ++buffer_local) |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2513 { |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2514 for (hash = 0; hash < 256; ++hash) |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2515 { |
28602
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2516 if (abbr) |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2517 { |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2518 if (hash > 0) // there is only one abbr list |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2519 break; |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2520 if (buffer_local) |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2521 mp = curbuf->b_first_abbr; |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2522 else |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2523 mp = first_abbr; |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2524 } |
398c5b3211f9
patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents:
28600
diff
changeset
|
2525 else if (buffer_local) |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2526 mp = curbuf->b_maphash[hash]; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2527 else |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2528 mp = maphash[hash]; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2529 for (; mp; mp = mp->m_next) |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2530 { |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2531 if (mp->m_simplified) |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2532 continue; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2533 if ((d = dict_alloc()) == NULL) |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2534 return; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2535 if (list_append_dict(rettv->vval.v_list, d) == FAIL) |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2536 return; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2537 |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2538 keys_buf = NULL; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2539 did_simplify = FALSE; |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2540 |
30226
b6b803ed4a53
patch 9.0.0449: there is no easy way to translate a key code into a string
Bram Moolenaar <Bram@vim.org>
parents:
30007
diff
changeset
|
2541 lhs = str2special_save(mp->m_keys, TRUE, FALSE); |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2542 (void)replace_termcodes(lhs, &keys_buf, flags, &did_simplify); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2543 vim_free(lhs); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2544 |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2545 mapblock2dict(mp, d, |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2546 did_simplify ? keys_buf : NULL, |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2547 buffer_local, abbr); |
28592
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2548 vim_free(keys_buf); |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2549 } |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2550 } |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2551 } |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2552 } |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2553 |
d3c966c0cdf7
patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents:
28590
diff
changeset
|
2554 /* |
25431
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2555 * "maparg()" function |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2556 */ |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2557 void |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2558 f_maparg(typval_T *argvars, typval_T *rettv) |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2559 { |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2560 if (in_vim9script() |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2561 && (check_for_string_arg(argvars, 0) == FAIL |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2562 || check_for_opt_string_arg(argvars, 1) == FAIL |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2563 || (argvars[1].v_type != VAR_UNKNOWN |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2564 && (check_for_opt_bool_arg(argvars, 2) == FAIL |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2565 || (argvars[2].v_type != VAR_UNKNOWN |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2566 && check_for_opt_bool_arg(argvars, 3) == FAIL))))) |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2567 return; |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2568 |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2569 get_maparg(argvars, rettv, TRUE); |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2570 } |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2571 |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2572 /* |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2573 * "mapcheck()" function |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2574 */ |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2575 void |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2576 f_mapcheck(typval_T *argvars, typval_T *rettv) |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2577 { |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2578 if (in_vim9script() |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2579 && (check_for_string_arg(argvars, 0) == FAIL |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2580 || check_for_opt_string_arg(argvars, 1) == FAIL |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2581 || (argvars[1].v_type != VAR_UNKNOWN |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2582 && check_for_opt_bool_arg(argvars, 2) == FAIL))) |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2583 return; |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2584 |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2585 get_maparg(argvars, rettv, FALSE); |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2586 } |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2587 |
634aed775408
patch 8.2.3252: duplicated code for adding buffer lines
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
2588 /* |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2589 * Get the mapping mode from the mode string. |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2590 * It may contain multiple characters, eg "nox", or "!", or ' ' |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2591 * Return 0 if there is an error. |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2592 */ |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2593 static int |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2594 get_map_mode_string(char_u *mode_string, int abbr) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2595 { |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2596 char_u *p = mode_string; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2597 int mode = 0; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2598 int tmode; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2599 int modec; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2600 const int MASK_V = MODE_VISUAL | MODE_SELECT; |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2601 const int MASK_MAP = MODE_VISUAL | MODE_SELECT | MODE_NORMAL |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2602 | MODE_OP_PENDING; |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2603 const int MASK_BANG = MODE_INSERT | MODE_CMDLINE; |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2604 |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2605 if (*p == NUL) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2606 p = (char_u *)" "; // compatibility |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2607 while ((modec = *p++)) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2608 { |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2609 switch (modec) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2610 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2611 case 'i': tmode = MODE_INSERT; break; |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2612 case 'l': tmode = MODE_LANGMAP; break; |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2613 case 'c': tmode = MODE_CMDLINE; break; |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2614 case 'n': tmode = MODE_NORMAL; break; |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2615 case 'x': tmode = MODE_VISUAL; break; |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2616 case 's': tmode = MODE_SELECT; break; |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2617 case 'o': tmode = MODE_OP_PENDING; break; |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2618 case 't': tmode = MODE_TERMINAL; break; |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2619 case 'v': tmode = MASK_V; break; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2620 case '!': tmode = MASK_BANG; break; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2621 case ' ': tmode = MASK_MAP; break; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2622 default: |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2623 return 0; // error, unknown mode character |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2624 } |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2625 mode |= tmode; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2626 } |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2627 if ((abbr && (mode & ~MASK_BANG) != 0) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2628 || (!abbr && (mode & (mode-1)) != 0 // more than one bit set |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2629 && ( |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2630 // false if multiple bits set in mode and mode is fully |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2631 // contained in one mask |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2632 !(((mode & MASK_BANG) != 0 && (mode & ~MASK_BANG) == 0) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2633 || ((mode & MASK_MAP) != 0 && (mode & ~MASK_MAP) == 0))))) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2634 return 0; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2635 |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2636 return mode; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2637 } |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2638 |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2639 /* |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2640 * "mapset()" function |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2641 */ |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2642 void |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2643 f_mapset(typval_T *argvars, typval_T *rettv UNUSED) |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2644 { |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2645 char_u *which; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2646 int mode; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2647 char_u buf[NUMBUFLEN]; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2648 int is_abbr; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2649 dict_T *d; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2650 char_u *lhs; |
20522
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2651 char_u *lhsraw; |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2652 char_u *lhsrawalt; |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2653 char_u *rhs; |
20516
d9e3fdf26cb9
patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents:
20510
diff
changeset
|
2654 char_u *orig_rhs; |
d9e3fdf26cb9
patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents:
20510
diff
changeset
|
2655 char_u *arg_buf = NULL; |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2656 int noremap; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2657 int expr; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2658 int silent; |
24529
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2659 int buffer; |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2660 scid_T sid; |
27223
ea2b4cb4515b
patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents:
27221
diff
changeset
|
2661 int scriptversion; |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2662 linenr_T lnum; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2663 mapblock_T **map_table = maphash; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2664 mapblock_T **abbr_table = &first_abbr; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2665 int nowait; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2666 char_u *arg; |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2667 int dict_only; |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2668 |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2669 // If first arg is a dict, then that's the only arg permitted. |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2670 dict_only = argvars[0].v_type == VAR_DICT; |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
2671 if (in_vim9script() |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2672 && (check_for_string_or_dict_arg(argvars, 0) == FAIL |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2673 || (dict_only && check_for_unknown_arg(argvars, 1) == FAIL) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2674 || (!dict_only |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2675 && (check_for_string_arg(argvars, 0) == FAIL |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2676 || check_for_bool_arg(argvars, 1) == FAIL |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2677 || check_for_dict_arg(argvars, 2) == FAIL)))) |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
2678 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
2679 |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2680 if (dict_only) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2681 { |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2682 d = argvars[0].vval.v_dict; |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2683 which = dict_get_string(d, "mode", FALSE); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2684 is_abbr = dict_get_bool(d, "abbr", -1); |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2685 if (which == NULL || is_abbr < 0) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2686 { |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2687 emsg(_(e_entries_missing_in_mapset_dict_argument)); |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2688 return; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2689 } |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2690 } |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2691 else |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2692 { |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2693 which = tv_get_string_buf_chk(&argvars[0], buf); |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2694 if (which == NULL) |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2695 return; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2696 is_abbr = (int)tv_get_bool(&argvars[1]); |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2697 |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29572
diff
changeset
|
2698 if (check_for_dict_arg(argvars, 2) == FAIL) |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2699 return; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2700 d = argvars[2].vval.v_dict; |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2701 } |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2702 mode = get_map_mode_string(which, is_abbr); |
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2703 if (mode == 0) |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2704 { |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2705 semsg(_(e_illegal_map_mode_string_str), which); |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2706 return; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2707 } |
28674
38f7a132bba3
patch 8.2.4861: it is not easy to restore saved mappings
Bram Moolenaar <Bram@vim.org>
parents:
28614
diff
changeset
|
2708 |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2709 |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2710 // Get the values in the same order as above in get_maparg(). |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2711 lhs = dict_get_string(d, "lhs", FALSE); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2712 lhsraw = dict_get_string(d, "lhsraw", FALSE); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2713 lhsrawalt = dict_get_string(d, "lhsrawalt", FALSE); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2714 rhs = dict_get_string(d, "rhs", FALSE); |
20522
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2715 if (lhs == NULL || lhsraw == NULL || rhs == NULL) |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2716 { |
26915
3631d2deb36c
patch 8.2.3986: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26913
diff
changeset
|
2717 emsg(_(e_entries_missing_in_mapset_dict_argument)); |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2718 return; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2719 } |
20516
d9e3fdf26cb9
patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents:
20510
diff
changeset
|
2720 orig_rhs = rhs; |
30007
4123e4bd1708
patch 9.0.0341: mapset() does not restore <Nop> mapping properly
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
2721 if (STRICMP(rhs, "<nop>") == 0) // "<Nop>" means nothing |
4123e4bd1708
patch 9.0.0341: mapset() does not restore <Nop> mapping properly
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
2722 rhs = (char_u *)""; |
4123e4bd1708
patch 9.0.0341: mapset() does not restore <Nop> mapping properly
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
2723 else |
4123e4bd1708
patch 9.0.0341: mapset() does not restore <Nop> mapping properly
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
2724 rhs = replace_termcodes(rhs, &arg_buf, |
20516
d9e3fdf26cb9
patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents:
20510
diff
changeset
|
2725 REPTERM_DO_LT | REPTERM_SPECIAL, NULL); |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2726 |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2727 noremap = dict_get_number(d, "noremap") ? REMAP_NONE: 0; |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2728 if (dict_get_number(d, "script") != 0) |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2729 noremap = REMAP_SCRIPT; |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2730 expr = dict_get_number(d, "expr") != 0; |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2731 silent = dict_get_number(d, "silent") != 0; |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2732 sid = dict_get_number(d, "sid"); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2733 scriptversion = dict_get_number(d, "scriptversion"); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2734 lnum = dict_get_number(d, "lnum"); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2735 buffer = dict_get_number(d, "buffer"); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29318
diff
changeset
|
2736 nowait = dict_get_number(d, "nowait") != 0; |
24529
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2737 // mode from the dict is not used |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2738 |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2739 if (buffer) |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2740 { |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2741 map_table = curbuf->b_maphash; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2742 abbr_table = &curbuf->b_first_abbr; |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2743 } |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2744 |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2745 // Delete any existing mapping for this lhs and mode. |
24529
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2746 if (buffer) |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2747 { |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2748 arg = alloc(STRLEN(lhs) + STRLEN("<buffer>") + 1); |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2749 if (arg == NULL) |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2750 return; |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2751 STRCPY(arg, "<buffer>"); |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2752 STRCPY(arg + 8, lhs); |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2753 } |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2754 else |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2755 { |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2756 arg = vim_strsave(lhs); |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2757 if (arg == NULL) |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2758 return; |
db2b4e867d06
patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
2759 } |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
2760 do_map(MAPTYPE_UNMAP, arg, mode, is_abbr); |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2761 vim_free(arg); |
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2762 |
20522
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2763 (void)map_add(map_table, abbr_table, lhsraw, rhs, orig_rhs, noremap, |
27223
ea2b4cb4515b
patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents:
27221
diff
changeset
|
2764 nowait, silent, mode, is_abbr, expr, sid, scriptversion, lnum, 0); |
20522
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2765 if (lhsrawalt != NULL) |
729853a754ea
patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents:
20516
diff
changeset
|
2766 (void)map_add(map_table, abbr_table, lhsrawalt, rhs, orig_rhs, noremap, |
27223
ea2b4cb4515b
patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents:
27221
diff
changeset
|
2767 nowait, silent, mode, is_abbr, expr, sid, scriptversion, |
ea2b4cb4515b
patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents:
27221
diff
changeset
|
2768 lnum, 1); |
20516
d9e3fdf26cb9
patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents:
20510
diff
changeset
|
2769 vim_free(arg_buf); |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2770 } |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2771 #endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2772 |
20506
aee0b72ca6d6
patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2773 |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2774 #if defined(MSWIN) || defined(MACOS_X) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2775 |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2776 # define VIS_SEL (MODE_VISUAL | MODE_SELECT) // abbreviation |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2777 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2778 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2779 * Default mappings for some often used keys. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2780 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2781 struct initmap |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2782 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2783 char_u *arg; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2784 int mode; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2785 }; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2786 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2787 # ifdef FEAT_GUI_MSWIN |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2788 // Use the Windows (CUA) keybindings. (GUI) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2789 static struct initmap initmappings[] = |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2790 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2791 // paste, copy and cut |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2792 {(char_u *)"<S-Insert> \"*P", MODE_NORMAL}, |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2793 {(char_u *)"<S-Insert> \"-d\"*P", VIS_SEL}, |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2794 {(char_u *)"<S-Insert> <C-R><C-O>*", MODE_INSERT | MODE_CMDLINE}, |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2795 {(char_u *)"<C-Insert> \"*y", VIS_SEL}, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2796 {(char_u *)"<S-Del> \"*d", VIS_SEL}, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2797 {(char_u *)"<C-Del> \"*d", VIS_SEL}, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2798 {(char_u *)"<C-X> \"*d", VIS_SEL}, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2799 // Missing: CTRL-C (cancel) and CTRL-V (block selection) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2800 }; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2801 # endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2802 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2803 # if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL)) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2804 // Use the Windows (CUA) keybindings. (Console) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2805 static struct initmap cinitmappings[] = |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2806 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2807 {(char_u *)"\316w <C-Home>", MODE_NORMAL | VIS_SEL}, |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2808 {(char_u *)"\316w <C-Home>", MODE_INSERT | MODE_CMDLINE}, |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2809 {(char_u *)"\316u <C-End>", MODE_NORMAL | VIS_SEL}, |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2810 {(char_u *)"\316u <C-End>", MODE_INSERT | MODE_CMDLINE}, |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2811 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2812 // paste, copy and cut |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2813 # ifdef FEAT_CLIPBOARD |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2814 {(char_u *)"\316\324 \"*P", MODE_NORMAL}, // SHIFT-Insert is "*P |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2815 {(char_u *)"\316\324 \"-d\"*P", VIS_SEL}, // SHIFT-Insert is "-d"*P |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2816 {(char_u *)"\316\324 \022\017*", MODE_INSERT}, // SHIFT-Insert is ^R^O* |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2817 {(char_u *)"\316\325 \"*y", VIS_SEL}, // CTRL-Insert is "*y |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2818 {(char_u *)"\316\327 \"*d", VIS_SEL}, // SHIFT-Del is "*d |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2819 {(char_u *)"\316\330 \"*d", VIS_SEL}, // CTRL-Del is "*d |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2820 {(char_u *)"\030 \"*d", VIS_SEL}, // CTRL-X is "*d |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2821 # else |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2822 {(char_u *)"\316\324 P", MODE_NORMAL}, // SHIFT-Insert is P |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2823 {(char_u *)"\316\324 \"-dP", VIS_SEL}, // SHIFT-Insert is "-dP |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2824 {(char_u *)"\316\324 \022\017\"", MODE_INSERT}, // SHIFT-Insert is ^R^O" |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2825 {(char_u *)"\316\325 y", VIS_SEL}, // CTRL-Insert is y |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2826 {(char_u *)"\316\327 d", VIS_SEL}, // SHIFT-Del is d |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2827 {(char_u *)"\316\330 d", VIS_SEL}, // CTRL-Del is d |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2828 # endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2829 }; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2830 # endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2831 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2832 # if defined(MACOS_X) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2833 static struct initmap initmappings[] = |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2834 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2835 // Use the Standard MacOS binding. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2836 // paste, copy and cut |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2837 {(char_u *)"<D-v> \"*P", MODE_NORMAL}, |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2838 {(char_u *)"<D-v> \"-d\"*P", VIS_SEL}, |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28686
diff
changeset
|
2839 {(char_u *)"<D-v> <C-R>*", MODE_INSERT | MODE_CMDLINE}, |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2840 {(char_u *)"<D-c> \"*y", VIS_SEL}, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2841 {(char_u *)"<D-x> \"*d", VIS_SEL}, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2842 {(char_u *)"<Backspace> \"-d", VIS_SEL}, |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2843 }; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2844 # endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2845 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2846 # undef VIS_SEL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2847 #endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2848 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2849 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2850 * Set up default mappings. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2851 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2852 void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2853 init_mappings(void) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2854 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2855 #if defined(MSWIN) || defined(MACOS_X) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2856 int i; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2857 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2858 # if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2859 # ifdef VIMDLL |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2860 if (!gui.starting) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2861 # endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2862 { |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24574
diff
changeset
|
2863 for (i = 0; i < (int)ARRAY_LENGTH(cinitmappings); ++i) |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
2864 add_map(cinitmappings[i].arg, cinitmappings[i].mode, FALSE); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2865 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2866 # endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2867 # if defined(FEAT_GUI_MSWIN) || defined(MACOS_X) |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24574
diff
changeset
|
2868 for (i = 0; i < (int)ARRAY_LENGTH(initmappings); ++i) |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
2869 add_map(initmappings[i].arg, initmappings[i].mode, FALSE); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2870 # endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2871 #endif |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2872 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2873 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2874 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2875 * Add a mapping "map" for mode "mode". |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
2876 * When "nore" is TRUE use MAPTYPE_NOREMAP. |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2877 * Need to put string in allocated memory, because do_map() will modify it. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2878 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2879 void |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
2880 add_map(char_u *map, int mode, int nore) |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2881 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2882 char_u *s; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2883 char_u *cpo_save = p_cpo; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2884 |
23493
f8382c4e6551
patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
2885 p_cpo = empty_option; // Allow <> notation |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2886 s = vim_strsave(map); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2887 if (s != NULL) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2888 { |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
2889 (void)do_map(nore ? MAPTYPE_NOREMAP : MAPTYPE_MAP, s, mode, FALSE); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2890 vim_free(s); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2891 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2892 p_cpo = cpo_save; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2893 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2894 |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2895 #if defined(FEAT_LANGMAP) || defined(PROTO) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2896 /* |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2897 * Any character has an equivalent 'langmap' character. This is used for |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2898 * keyboards that have a special language mode that sends characters above |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2899 * 128 (although other characters can be translated too). The "to" field is a |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2900 * Vim command character. This avoids having to switch the keyboard back to |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2901 * ASCII mode when leaving Insert mode. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2902 * |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2903 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2904 * commands. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2905 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2906 * same as langmap_mapchar[] for characters >= 256. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2907 * |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2908 * Use growarray for 'langmap' chars >= 256 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2909 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2910 typedef struct |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2911 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2912 int from; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2913 int to; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2914 } langmap_entry_T; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2915 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2916 static garray_T langmap_mapga; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2917 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2918 /* |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2919 * Search for an entry in "langmap_mapga" for "from". If found set the "to" |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2920 * field. If not found insert a new entry at the appropriate location. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2921 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2922 static void |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2923 langmap_set_entry(int from, int to) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2924 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2925 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2926 int a = 0; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2927 int b = langmap_mapga.ga_len; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2928 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2929 // Do a binary search for an existing entry. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2930 while (a != b) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2931 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2932 int i = (a + b) / 2; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2933 int d = entries[i].from - from; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2934 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2935 if (d == 0) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2936 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2937 entries[i].to = to; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2938 return; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2939 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2940 if (d < 0) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2941 a = i + 1; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2942 else |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2943 b = i; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2944 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2945 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2946 if (ga_grow(&langmap_mapga, 1) != OK) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2947 return; // out of memory |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2948 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2949 // insert new entry at position "a" |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2950 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2951 mch_memmove(entries + 1, entries, |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2952 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T)); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2953 ++langmap_mapga.ga_len; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2954 entries[0].from = from; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2955 entries[0].to = to; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2956 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2957 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2958 /* |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2959 * Apply 'langmap' to multi-byte character "c" and return the result. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2960 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2961 int |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2962 langmap_adjust_mb(int c) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2963 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2964 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2965 int a = 0; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2966 int b = langmap_mapga.ga_len; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2967 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2968 while (a != b) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2969 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2970 int i = (a + b) / 2; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2971 int d = entries[i].from - c; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2972 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2973 if (d == 0) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2974 return entries[i].to; // found matching entry |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2975 if (d < 0) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2976 a = i + 1; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2977 else |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2978 b = i; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2979 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2980 return c; // no entry found, return "c" unmodified |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2981 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2982 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2983 void |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2984 langmap_init(void) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2985 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2986 int i; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2987 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2988 for (i = 0; i < 256; i++) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2989 langmap_mapchar[i] = i; // we init with a one-to-one map |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2990 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2991 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2992 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2993 /* |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2994 * Called when langmap option is set; the language map can be |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2995 * changed at any time! |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2996 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2997 void |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2998 langmap_set(void) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2999 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3000 char_u *p; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3001 char_u *p2; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3002 int from, to; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3003 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3004 ga_clear(&langmap_mapga); // clear the previous map first |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3005 langmap_init(); // back to one-to-one map |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3006 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3007 for (p = p_langmap; p[0] != NUL; ) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3008 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3009 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';'; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3010 MB_PTR_ADV(p2)) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3011 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3012 if (p2[0] == '\\' && p2[1] != NUL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3013 ++p2; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3014 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3015 if (p2[0] == ';') |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3016 ++p2; // abcd;ABCD form, p2 points to A |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3017 else |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3018 p2 = NULL; // aAbBcCdD form, p2 is NULL |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3019 while (p[0]) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3020 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3021 if (p[0] == ',') |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3022 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3023 ++p; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3024 break; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3025 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3026 if (p[0] == '\\' && p[1] != NUL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3027 ++p; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3028 from = (*mb_ptr2char)(p); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3029 to = NUL; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3030 if (p2 == NULL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3031 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3032 MB_PTR_ADV(p); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3033 if (p[0] != ',') |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3034 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3035 if (p[0] == '\\') |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3036 ++p; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3037 to = (*mb_ptr2char)(p); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3038 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3039 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3040 else |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3041 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3042 if (p2[0] != ',') |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3043 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3044 if (p2[0] == '\\') |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3045 ++p2; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3046 to = (*mb_ptr2char)(p2); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3047 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3048 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3049 if (to == NUL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3050 { |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
3051 semsg(_(e_langmap_matching_character_missing_for_str), |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3052 transchar(from)); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3053 return; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3054 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3055 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3056 if (from >= 256) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3057 langmap_set_entry(from, to); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3058 else |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3059 langmap_mapchar[from & 255] = to; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3060 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3061 // Advance to next pair |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3062 MB_PTR_ADV(p); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3063 if (p2 != NULL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3064 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3065 MB_PTR_ADV(p2); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3066 if (*p == ';') |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3067 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3068 p = p2; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3069 if (p[0] != NUL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3070 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3071 if (p[0] != ',') |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3072 { |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
3073 semsg(_(e_langmap_extra_characters_after_semicolon_str), p); |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3074 return; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3075 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3076 ++p; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3077 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3078 break; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3079 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3080 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3081 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3082 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3083 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3084 #endif |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
3085 |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3086 static void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3087 do_exmap(exarg_T *eap, int isabbrev) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3088 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3089 int mode; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3090 char_u *cmdp; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3091 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3092 cmdp = eap->cmd; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3093 mode = get_map_mode(&cmdp, eap->forceit || isabbrev); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3094 |
29173
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
3095 switch (do_map(*cmdp == 'n' ? MAPTYPE_NOREMAP |
1ec1ba7e7728
patch 8.2.5106: default cmdwin mappings are re-mappable
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
3096 : *cmdp == 'u' ? MAPTYPE_UNMAP : MAPTYPE_MAP, |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3097 eap->arg, mode, isabbrev)) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3098 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
3099 case 1: emsg(_(e_invalid_argument)); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3100 break; |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
3101 case 2: emsg((isabbrev ? _(e_no_such_abbreviation) |
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
3102 : _(e_no_such_mapping))); |
17576
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3103 break; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3104 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3105 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3106 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3107 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3108 * ":abbreviate" and friends. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3109 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3110 void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3111 ex_abbreviate(exarg_T *eap) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3112 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3113 do_exmap(eap, TRUE); // almost the same as mapping |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3114 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3115 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3116 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3117 * ":map" and friends. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3118 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3119 void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3120 ex_map(exarg_T *eap) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3121 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3122 // If we are sourcing .exrc or .vimrc in current directory we |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3123 // print the mappings for security reasons. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3124 if (secure) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3125 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3126 secure = 2; |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3127 msg_outtrans(eap->cmd); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3128 msg_putchar('\n'); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3129 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3130 do_exmap(eap, FALSE); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3131 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3132 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3133 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3134 * ":unmap" and friends. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3135 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3136 void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3137 ex_unmap(exarg_T *eap) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3138 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3139 do_exmap(eap, FALSE); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3140 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3141 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3142 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3143 * ":mapclear" and friends. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3144 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3145 void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3146 ex_mapclear(exarg_T *eap) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3147 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3148 map_clear(eap->cmd, eap->arg, eap->forceit, FALSE); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3149 } |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3150 |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3151 /* |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3152 * ":abclear" and friends. |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3153 */ |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3154 void |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3155 ex_abclear(exarg_T *eap) |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3156 { |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3157 map_clear(eap->cmd, eap->arg, TRUE, TRUE); |
97a750e8707f
patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3158 } |