annotate src/map.c @ 17781:04245f071792 v8.1.1887

patch 8.1.1887: the +cmdline_compl feature is not in the tiny version commit https://github.com/vim/vim/commit/0a52df50a0e8fce6f5e0eb5f5373dcd0fa24d83a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 18 22:26:31 2019 +0200 patch 8.1.1887: the +cmdline_compl feature is not in the tiny version Problem: The +cmdline_compl feature is not in the tiny version. Solution: Graduate the +cmdline_compl feature.
author Bram Moolenaar <Bram@vim.org>
date Sun, 18 Aug 2019 22:30:04 +0200
parents 97a750e8707f
children 079e10a49ea1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * map.c: functions for maps and abbreviations
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
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 * 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
29 * "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
30 * "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
31 * 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
32 * 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
33 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 #define MAP_HASH(mode, c1) (((mode) & (NORMAL + VISUAL + SELECTMODE + OP_PENDING + TERMINAL)) ? (c1) : ((c1) ^ 0x80))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 * 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
38 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 mapblock_T *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 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
41 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 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
43 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44
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 * 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
47 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 mapblock_T *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 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
50 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 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
52 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 int
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 is_maphash_valid(void)
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 return maphash_valid;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59
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 * Initialize maphash[] for first use.
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 static void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 validate_maphash(void)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 if (!maphash_valid)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 vim_memset(maphash, 0, sizeof(maphash));
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 maphash_valid = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 * 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
75 * "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
76 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 static void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 map_free(mapblock_T **mpp)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 mapblock_T *mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 mp = *mpp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 vim_free(mp->m_keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 vim_free(mp->m_str);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 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
86 *mpp = mp->m_next;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 vim_free(mp);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 * 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
92 * 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
93 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 static char_u *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 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
96 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 garray_T mapmode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 ga_init2(&mapmode, 1, 7);
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 if ((mode & (INSERT + CMDLINE)) == INSERT + CMDLINE)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 ga_append(&mapmode, '!'); // :map!
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 else if (mode & INSERT)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 ga_append(&mapmode, 'i'); // :imap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 else if (mode & LANGMAP)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 ga_append(&mapmode, 'l'); // :lmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 else if (mode & CMDLINE)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 ga_append(&mapmode, 'c'); // :cmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 else if ((mode & (NORMAL + VISUAL + SELECTMODE + OP_PENDING))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 == NORMAL + VISUAL + SELECTMODE + OP_PENDING)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 ga_append(&mapmode, ' '); // :map
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 if (mode & NORMAL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 ga_append(&mapmode, 'n'); // :nmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 if (mode & OP_PENDING)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 ga_append(&mapmode, 'o'); // :omap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 if (mode & TERMINAL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 ga_append(&mapmode, 't'); // :tmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 if ((mode & (VISUAL + SELECTMODE)) == VISUAL + SELECTMODE)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 ga_append(&mapmode, 'v'); // :vmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 if (mode & VISUAL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 ga_append(&mapmode, 'x'); // :xmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 if (mode & SELECTMODE)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 ga_append(&mapmode, 's'); // :smap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 ga_append(&mapmode, NUL);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 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
133 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 static void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 showmap(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 mapblock_T *mp,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 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
139 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 int len = 1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 char_u *mapchars;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 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
144 return;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 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
147 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 msg_putchar('\n');
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 if (got_int) // 'q' typed at MORE prompt
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 return;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 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
154 if (mapchars != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 msg_puts((char *)mapchars);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 len = (int)STRLEN(mapchars);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 vim_free(mapchars);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 while (++len <= 3)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 msg_putchar(' ');
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 // 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
165 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
166 do
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 msg_putchar(' '); // padd with blanks
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 ++len;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 } while (len < 12);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 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
173 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
174 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
175 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
176 else
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 if (local)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 msg_putchar('@');
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 msg_putchar(' ');
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 // 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
185 // 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
186 if (*mp->m_str == NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 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
188 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 // Remove escaping of CSI, because "m_str" is in a format to be used
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 // as typeahead.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 char_u *s = vim_strsave(mp->m_str);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 if (s != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 vim_unescape_csi(s);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 msg_outtrans_special(s, FALSE, 0);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 vim_free(s);
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 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 if (p_verbose > 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 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
203 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 out_flush(); // show one line at a time
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 * map[!] : show all key mappings
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 * 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
210 * 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
211 * 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
212 * 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
213 * abbr : show all abbreviations
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 * 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
215 * 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
216 * 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
217 * 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
218 *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 * maptype: 0 for :map, 1 for :unmap, 2 for noremap.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 * 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
222 * it will be modified.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 * for :map mode is NORMAL + VISUAL + SELECTMODE + OP_PENDING
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 * for :map! mode is INSERT + CMDLINE
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 * for :cmap mode is CMDLINE
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 * for :imap mode is INSERT
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 * for :lmap mode is LANGMAP
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 * for :nmap mode is NORMAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 * for :vmap mode is VISUAL + SELECTMODE
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 * for :xmap mode is VISUAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 * for :smap mode is SELECTMODE
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 * for :omap mode is OP_PENDING
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 * for :tmap mode is TERMINAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 * for :abbr mode is INSERT + CMDLINE
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 * for :iabbr mode is INSERT
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 * for :cabbr mode is CMDLINE
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 * Return 0 for success
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 * 1 for invalid arguments
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 * 2 for no match
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 * 4 for out of mem
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 * 5 for entry not unique
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 int
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 do_map(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 int maptype,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 char_u *arg,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 int mode,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 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
252 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 char_u *keys;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 mapblock_T *mp, **mpp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 char_u *rhs;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 char_u *p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 int n;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 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
259 char_u *newstr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 int hasarg;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 int haskey;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 int did_it = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 int did_local = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 int round;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 char_u *keys_buf = NULL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 char_u *arg_buf = NULL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 int retval = 0;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 int do_backslash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 int hash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 int new_hash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 mapblock_T **abbr_table;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 mapblock_T **map_table;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 int unique = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 int nowait = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 int silent = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 int special = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 int expr = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 int noremap;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 char_u *orig_rhs;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 keys = arg;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 map_table = maphash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 abbr_table = &first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 // For ":noremap" don't remap, otherwise do remap.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 if (maptype == 2)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 noremap = REMAP_NONE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 noremap = REMAP_YES;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 // 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
294 // any order.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 for (;;)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 // 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
298 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
299 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 keys = skipwhite(keys + 8);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 map_table = curbuf->b_maphash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 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
303 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 // 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
307 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
308 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 keys = skipwhite(keys + 8);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 nowait = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 // 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
315 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
316 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 keys = skipwhite(keys + 8);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 silent = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 // 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
323 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
324 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 keys = skipwhite(keys + 9);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 special = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 // 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
332 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
333 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 keys = skipwhite(keys + 8);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 noremap = REMAP_SCRIPT;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 // 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
340 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
341 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 keys = skipwhite(keys + 6);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 expr = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 // 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
348 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
349 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 keys = skipwhite(keys + 8);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 unique = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 validate_maphash();
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 // 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
360 // 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
361 // 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
362 p = keys;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 while (*p && (maptype == 1 || !VIM_ISWHITE(*p)))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 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
367 p[1] != NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 ++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
369 ++p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 if (*p != NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 *p++ = NUL;
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 p = skipwhite(p);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 rhs = p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 hasarg = (*rhs != NUL);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 haskey = (*keys != NUL);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 // check for :unmap without argument
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 if (maptype == 1 && !haskey)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 retval = 1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 goto theend;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 // 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
387 // 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
388 // 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
389 // 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
390 // 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
391 // replace_termcodes() also removes CTRL-Vs and sometimes backslashes.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 if (haskey)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 keys = replace_termcodes(keys, &keys_buf, TRUE, TRUE, special);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 orig_rhs = rhs;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 if (hasarg)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 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
398 rhs = (char_u *)"";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 rhs = replace_termcodes(rhs, &arg_buf, FALSE, TRUE, special);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 // check arguments and translate function keys
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 if (haskey)
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 len = (int)STRLEN(keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 if (len > MAXMAPLEN) // maximum length of MAXMAPLEN chars
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 retval = 1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 goto theend;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 if (abbrev && maptype != 1)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 // If an abbreviation ends in a keyword character, the
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 // rest must be all keyword-char or all non-keyword-char.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 // Otherwise we won't be able to find the start of it in a
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 // vi-compatible way.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 if (has_mbyte)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 int first, last;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 int same = -1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 first = vim_iswordp(keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 last = first;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 p = keys + (*mb_ptr2len)(keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 n = 1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 while (p < keys + len)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 ++n; // nr of (multi-byte) chars
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 last = vim_iswordp(p); // type of last char
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 if (same == -1 && last != first)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 same = n - 1; // count of same char type
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 p += (*mb_ptr2len)(p);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 if (last && n > 2 && same >= 0 && same < n - 1)
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 retval = 1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 goto theend;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 else if (vim_iswordc(keys[len - 1])) // ends in keyword char
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 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
444 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
445 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 retval = 1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 goto theend;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 // An abbreviation cannot contain white space.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 for (n = 0; n < len; ++n)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 if (VIM_ISWHITE(keys[n]))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 retval = 1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 goto theend;
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 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 if (haskey && hasarg && abbrev) // if we will add an abbreviation
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 no_abbr = FALSE; // reset flag that indicates there are
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 // no abbreviations
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 if (!haskey || (maptype != 1 && !hasarg))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 msg_start();
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 // Check if a new local mapping wasn't already defined globally.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 if (map_table == curbuf->b_maphash && haskey && hasarg && maptype != 1)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 // need to loop over all global hash lists
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 for (hash = 0; hash < 256 && !got_int; ++hash)
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 if (abbrev)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 if (hash != 0) // there is only one abbreviation list
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 mp = first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 mp = maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 for ( ; mp != NULL && !got_int; mp = mp->m_next)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 // check entries with the same mode
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 if ((mp->m_mode & mode) != 0
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 && mp->m_keylen == len
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 && unique
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 && STRNCMP(mp->m_keys, keys, (size_t)len) == 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 if (abbrev)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 semsg(_("E224: global abbreviation already exists for %s"),
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 mp->m_keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 semsg(_("E225: global mapping already exists for %s"),
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 mp->m_keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 retval = 5;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 goto theend;
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 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 }
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 // When listing global mappings, also list buffer-local ones here.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 if (map_table != curbuf->b_maphash && !hasarg && maptype != 1)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 // need to loop over all global hash lists
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 for (hash = 0; hash < 256 && !got_int; ++hash)
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 if (abbrev)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 if (hash != 0) // there is only one abbreviation list
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 mp = curbuf->b_first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 mp = curbuf->b_maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 for ( ; mp != NULL && !got_int; mp = mp->m_next)
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 // check entries with the same mode
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 if ((mp->m_mode & mode) != 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 if (!haskey) // show all entries
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 showmap(mp, TRUE);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 did_local = TRUE;
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 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 n = mp->m_keylen;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 if (STRNCMP(mp->m_keys, keys,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 (size_t)(n < len ? n : len)) == 0)
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 showmap(mp, TRUE);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 did_local = TRUE;
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 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 }
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 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 // Find an entry in the maphash[] list that matches.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 // For :unmap we may loop two times: once to try to unmap an entry with a
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 // matching 'from' part, a second time, if the first fails, to unmap an
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 // entry with a matching 'to' part. This was done to allow ":ab foo bar"
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 // to be unmapped by typing ":unab foo", where "foo" will be replaced by
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 // "bar" because of the abbreviation.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 for (round = 0; (round == 0 || maptype == 1) && round <= 1
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 && !did_it && !got_int; ++round)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 // need to loop over all hash lists
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 for (hash = 0; hash < 256 && !got_int; ++hash)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 if (abbrev)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 if (hash > 0) // there is only one abbreviation list
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 mpp = abbr_table;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 mpp = &(map_table[hash]);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 for (mp = *mpp; mp != NULL && !got_int; mp = *mpp)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 {
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 (!(mp->m_mode & mode)) // skip entries with wrong mode
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 mpp = &(mp->m_next);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 if (!haskey) // show all entries
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 showmap(mp, map_table != maphash);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 did_it = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 else // do we have a match?
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 if (round) // second round: Try unmap "rhs" string
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 n = (int)STRLEN(mp->m_str);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 p = mp->m_str;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 n = mp->m_keylen;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 p = mp->m_keys;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 if (STRNCMP(p, keys, (size_t)(n < len ? n : len)) == 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 if (maptype == 1) // delete entry
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 // Only accept a full match. For abbreviations we
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 // ignore trailing space when matching with the
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 // "lhs", since an abbreviation can't have
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 // trailing space.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 if (n != len && (!abbrev || round || n > len
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 || *skipwhite(keys + n) != NUL))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 mpp = &(mp->m_next);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 // We reset the indicated mode bits. If nothing is
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 // left the entry is deleted below.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 mp->m_mode &= ~mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 did_it = TRUE; // remember we did something
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 else if (!hasarg) // show matching entry
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 showmap(mp, map_table != maphash);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 did_it = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 else if (n != len) // new entry is ambiguous
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 mpp = &(mp->m_next);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 else if (unique)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 if (abbrev)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 semsg(_("E226: abbreviation already exists for %s"),
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 p);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 semsg(_("E227: mapping already exists for %s"), p);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 retval = 5;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 goto theend;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 else // new rhs for existing entry
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 mp->m_mode &= ~mode; // remove mode bits
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 if (mp->m_mode == 0 && !did_it) // reuse entry
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 newstr = vim_strsave(rhs);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 if (newstr == NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 retval = 4; // no mem
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 goto theend;
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 vim_free(mp->m_str);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 mp->m_str = newstr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 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
638 mp->m_orig_str = vim_strsave(orig_rhs);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 mp->m_noremap = noremap;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 mp->m_nowait = nowait;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 mp->m_silent = silent;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 mp->m_mode = mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 mp->m_expr = expr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 mp->m_script_ctx = current_sctx;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 mp->m_script_ctx.sc_lnum += sourcing_lnum;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 did_it = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 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
652 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 map_free(mpp);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 continue; // continue with *mpp
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 // 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
658 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
659 if (!abbrev && new_hash != hash)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 *mpp = mp->m_next;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 mp->m_next = map_table[new_hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 map_table[new_hash] = mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 continue; // continue with *mpp
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 mpp = &(mp->m_next);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 if (maptype == 1) // delete entry
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 if (!did_it)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 retval = 2; // no match
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 else if (*keys == Ctrl_C)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 // If CTRL-C has been unmapped, reuse it for Interrupting.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 if (map_table == curbuf->b_maphash)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 curbuf->b_mapped_ctrl_c &= ~mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 mapped_ctrl_c &= ~mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 goto theend;
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 if (!haskey || !hasarg) // print entries
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 if (!did_it && !did_local)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 if (abbrev)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 msg(_("No abbreviation found"));
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 msg(_("No mapping found"));
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 goto theend; // listing finished
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 if (did_it) // have added the new entry already
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 goto theend;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 // Get here when adding a new entry to the maphash[] list or abbrlist.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 mp = ALLOC_ONE(mapblock_T);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 if (mp == NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 retval = 4; // no mem
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 goto theend;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 // If CTRL-C has been mapped, don't always use it for Interrupting.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 if (*keys == Ctrl_C)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 if (map_table == curbuf->b_maphash)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 curbuf->b_mapped_ctrl_c |= mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 mapped_ctrl_c |= mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 mp->m_keys = vim_strsave(keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 mp->m_str = vim_strsave(rhs);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 mp->m_orig_str = vim_strsave(orig_rhs);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 if (mp->m_keys == NULL || mp->m_str == NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 vim_free(mp->m_keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 vim_free(mp->m_str);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 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
729 vim_free(mp);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 retval = 4; // no mem
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 goto theend;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 mp->m_keylen = (int)STRLEN(mp->m_keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 mp->m_noremap = noremap;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 mp->m_nowait = nowait;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 mp->m_silent = silent;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 mp->m_mode = mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 mp->m_expr = expr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 mp->m_script_ctx = current_sctx;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 mp->m_script_ctx.sc_lnum += sourcing_lnum;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 // add the new entry in front of the abbrlist or maphash[] list
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 if (abbrev)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 mp->m_next = *abbr_table;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 *abbr_table = mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 n = 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
753 mp->m_next = map_table[n];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 map_table[n] = mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 theend:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 vim_free(keys_buf);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 vim_free(arg_buf);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 return retval;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 * 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
765 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 static int
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 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
768 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 char_u *p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 int modec;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 int mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 p = *cmdp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 modec = *p++;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 if (modec == 'i')
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 mode = INSERT; // :imap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 else if (modec == 'l')
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 mode = LANGMAP; // :lmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 else if (modec == 'c')
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 mode = CMDLINE; // :cmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 else if (modec == 'n' && *p != 'o') // avoid :noremap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 mode = NORMAL; // :nmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 else if (modec == 'v')
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 mode = VISUAL + SELECTMODE; // :vmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 else if (modec == 'x')
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 mode = VISUAL; // :xmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 else if (modec == 's')
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 mode = SELECTMODE; // :smap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 else if (modec == 'o')
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 mode = OP_PENDING; // :omap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 else if (modec == 't')
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 mode = TERMINAL; // :tmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 --p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 if (forceit)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 mode = INSERT + CMDLINE; // :map !
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 mode = VISUAL + SELECTMODE + NORMAL + OP_PENDING;// :map
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 *cmdp = p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 return mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 * Clear all mappings or abbreviations.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 * 'abbr' should be FALSE for mappings, TRUE for abbreviations.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 static void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 map_clear(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 char_u *cmdp,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 char_u *arg UNUSED,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 int forceit,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 int abbr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 int mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 int local;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 local = (STRCMP(arg, "<buffer>") == 0);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 if (!local && *arg != NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 emsg(_(e_invarg));
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 return;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 mode = get_map_mode(&cmdp, forceit);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 map_clear_int(curbuf, mode, local, abbr);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 * Clear all mappings in "mode".
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 map_clear_int(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 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
837 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
838 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
839 int abbr) // TRUE for abbreviations
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 mapblock_T *mp, **mpp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 int hash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 int new_hash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 validate_maphash();
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 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
848 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 if (abbr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 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
852 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 if (local)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 mpp = &buf->b_first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 mpp = &first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 if (local)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 mpp = &buf->b_maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 mpp = &maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 while (*mpp != NULL)
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 mp = *mpp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 if (mp->m_mode & mode)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 mp->m_mode &= ~mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 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
872 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 map_free(mpp);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 // 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
877 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
878 if (!abbr && new_hash != hash)
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 *mpp = mp->m_next;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 if (local)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 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
884 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
885 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 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
889 maphash[new_hash] = mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 continue; // continue with *mpp
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 mpp = &(mp->m_next);
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 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 #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
900 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 * Return TRUE if a map exists that has "str" in the rhs for mode "modechars".
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 * Recognize termcap codes in "str".
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 * 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
904 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 int
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 map_to_exists(char_u *str, char_u *modechars, int abbr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 int mode = 0;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 char_u *rhs;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 char_u *buf;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 int retval;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 rhs = replace_termcodes(str, &buf, FALSE, TRUE, FALSE);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 if (vim_strchr(modechars, 'n') != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 mode |= NORMAL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 if (vim_strchr(modechars, 'v') != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 mode |= VISUAL + SELECTMODE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 if (vim_strchr(modechars, 'x') != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 mode |= VISUAL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 if (vim_strchr(modechars, 's') != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 mode |= SELECTMODE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 if (vim_strchr(modechars, 'o') != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 mode |= OP_PENDING;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 if (vim_strchr(modechars, 'i') != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 mode |= INSERT;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 if (vim_strchr(modechars, 'l') != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 mode |= LANGMAP;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 if (vim_strchr(modechars, 'c') != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 mode |= CMDLINE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 retval = map_to_exists_mode(rhs, mode, abbr);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 vim_free(buf);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 return retval;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 * 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
941 * 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
942 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 int
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 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
945 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 mapblock_T *mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 int hash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 int exp_buffer = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 validate_maphash();
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 // 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
953 for (;;)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 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
956 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 if (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 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
960 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 if (exp_buffer)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 mp = curbuf->b_first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 mp = first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 else if (exp_buffer)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 mp = curbuf->b_maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 mp = maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 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
971 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 if ((mp->m_mode & mode)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 && 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
974 return TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 if (exp_buffer)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 exp_buffer = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 return FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 * 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
987 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 static int expand_mapmodes = 0;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 static int expand_isabbrev = 0;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 static int expand_buffer = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 * 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
994 * or abbreviation names.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 char_u *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 set_context_in_map_cmd(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 expand_T *xp,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 char_u *cmd,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 char_u *arg,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 int forceit, // TRUE if '!' given
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 int isabbrev, // TRUE if abbreviation
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 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
1004 cmdidx_T cmdidx)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 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
1007 xp->xp_context = EXPAND_NOTHING;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 if (isunmap)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 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
1012 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 expand_mapmodes = INSERT + CMDLINE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 if (!isabbrev)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 expand_mapmodes += VISUAL + SELECTMODE + NORMAL + OP_PENDING;
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 expand_isabbrev = isabbrev;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 xp->xp_context = EXPAND_MAPPINGS;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 expand_buffer = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 for (;;)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 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
1024 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 expand_buffer = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 arg = skipwhite(arg + 8);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 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
1030 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 arg = skipwhite(arg + 8);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 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
1035 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 arg = skipwhite(arg + 8);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 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
1040 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 arg = skipwhite(arg + 8);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 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
1045 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 arg = skipwhite(arg + 9);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 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
1051 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 arg = skipwhite(arg + 8);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 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
1056 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 arg = skipwhite(arg + 6);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 break;
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 xp->xp_pattern = arg;
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
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 return NULL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 * 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
1071 * 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
1072 * 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
1073 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 int
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 ExpandMappings(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 regmatch_T *regmatch,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 int *num_file,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 char_u ***file)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 mapblock_T *mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 int hash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 int count;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 int round;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 char_u *p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 int i;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 validate_maphash();
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 *num_file = 0; // return values in case of FAIL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 *file = NULL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 // round == 1: Count the matches.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 // round == 2: Build the array to keep the matches.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 for (round = 1; round <= 2; ++round)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 count = 0;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 for (i = 0; i < 7; ++i)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 if (i == 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 p = (char_u *)"<silent>";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 else if (i == 1)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 p = (char_u *)"<unique>";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 else if (i == 2)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 p = (char_u *)"<script>";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 else if (i == 3)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 p = (char_u *)"<expr>";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 else if (i == 4 && !expand_buffer)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 p = (char_u *)"<buffer>";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 else if (i == 5)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 p = (char_u *)"<nowait>";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 else if (i == 6)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 p = (char_u *)"<special>";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 continue;
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 if (vim_regexec(regmatch, p, (colnr_T)0))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 if (round == 1)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 ++count;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 (*file)[count++] = vim_strsave(p);
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 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 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
1129 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 if (expand_isabbrev)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 if (hash > 0) // only one abbrev list
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 break; // for (hash)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 mp = first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 else if (expand_buffer)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 mp = curbuf->b_maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 mp = maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 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
1141 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 if (mp->m_mode & expand_mapmodes)
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 p = translate_mapping(mp->m_keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 if (p != NULL && vim_regexec(regmatch, p, (colnr_T)0))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 if (round == 1)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 ++count;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 else
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 (*file)[count++] = p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 p = NULL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 }
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 vim_free(p);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 } // for (mp)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 } // for (hash)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 if (count == 0) // no match found
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 break; // for (round)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 if (round == 1)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 *file = ALLOC_MULT(char_u *, count);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 if (*file == NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 } // for (round)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 if (count > 1)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 char_u **ptr1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 char_u **ptr2;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 char_u **ptr3;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 // Sort the matches
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 sort_strings(*file, count);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 // Remove multiple entries
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 ptr1 = *file;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 ptr2 = ptr1 + 1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 ptr3 = ptr1 + count;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 while (ptr2 < ptr3)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 if (STRCMP(*ptr1, *ptr2))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 *++ptr1 = *ptr2++;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 vim_free(*ptr2++);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 count--;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 *num_file = count;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 return (count == 0 ? FAIL : OK);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 * Check for an abbreviation.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 * Cursor is at ptr[col].
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 * 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
1205 * 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
1206 * "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
1207 * 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
1208 *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 * 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
1210 * 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
1211 * 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
1212 * "#include".
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 * 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
1215 * 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
1216 *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 * 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
1218 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 int
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 check_abbr(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 int c,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 char_u *ptr,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 int col,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 int mincol)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 int len;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 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
1228 int j;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 char_u *s;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 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
1231 mapblock_T *mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 mapblock_T *mp2;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 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
1234 int is_id = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 int vim_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 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
1238 return FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 // 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
1241 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
1242 return FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 // 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
1245 // 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
1246 // 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
1247 // before it except white space.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 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
1249 return FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 if (has_mbyte)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 char_u *p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 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
1256 if (!vim_iswordp(p))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 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
1258 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 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
1261 if (p > ptr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 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
1263 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 clen = 1;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 while (p > ptr + mincol)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 p = mb_prevptr(ptr, p);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 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
1269 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 p += (*mb_ptr2len)(p);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 ++clen;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 scol = (int)(p - ptr);
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 else
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 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
1280 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
1281 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 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
1284 if (col > 1)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 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
1286 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 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
1288 && (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
1289 ;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 }
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 if (scol < mincol)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 scol = mincol;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 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
1295 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 ptr += scol;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 len = col - scol;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 mp = curbuf->b_first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 mp2 = first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 if (mp == NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 mp = mp2;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 mp2 = NULL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 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
1306 ? (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
1307 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 int qlen = mp->m_keylen;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 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
1310 int match;
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 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
1313 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 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
1315
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 // 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
1317 if (qe != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 q = qe;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 vim_unescape_csi(q);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 qlen = (int)STRLEN(q);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 }
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
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 // 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
1326 match = (mp->m_mode & State)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 && qlen == len
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 && !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
1329 if (q != mp->m_keys)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 vim_free(q);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 if (match)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 if (mp != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 // Found a match:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 // 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
1338 // 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
1339 //
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 // 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
1341 // 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
1342 // 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
1343 // 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
1344 //
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 // 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
1346 // 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
1347 j = 0;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 if (c != Ctrl_RSB)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 // special key code, split up
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 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
1352 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 tb[j++] = K_SPECIAL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 tb[j++] = K_SECOND(c);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 tb[j++] = K_THIRD(c);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 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
1360 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
1361 if (has_mbyte)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 // 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
1364 if (c >= ABBR_OFF)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 c -= ABBR_OFF;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 j += (*mb_char2bytes)(c, tb + j);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 tb[j++] = c;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 tb[j] = NUL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 // insert the last typed char
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 (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
1374 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 if (mp->m_expr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 s = eval_map_expr(mp->m_str, c);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 s = mp->m_str;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 if (s != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 // insert the to string
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 (void)ins_typebuf(s, mp->m_noremap, 0, TRUE, mp->m_silent);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 // no abbrev. for these chars
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 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
1387 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 if (mp->m_expr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 vim_free(s);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 tb[0] = Ctrl_H;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 tb[1] = NUL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 if (has_mbyte)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 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
1397 while (len-- > 0) // delete the from string
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 (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
1399 return TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 return FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 * 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
1408 * special characters.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 char_u *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 eval_map_expr(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 char_u *str,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 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
1414 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 char_u *res;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 char_u *p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 char_u *expr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 pos_T save_cursor;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 int save_msg_col;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 int save_msg_row;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 // 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
1423 // typeahead.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 expr = vim_strsave(str);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 if (expr == NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 return NULL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 vim_unescape_csi(expr);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 // 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
1430 // effects. Also restore the cursor position.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 ++textlock;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 ++ex_normal_lock;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 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
1434 save_cursor = curwin->w_cursor;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 save_msg_col = msg_col;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 save_msg_row = msg_row;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 p = eval_to_string(expr, NULL, FALSE);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 --textlock;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 --ex_normal_lock;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 curwin->w_cursor = save_cursor;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 msg_col = save_msg_col;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 msg_row = save_msg_row;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 vim_free(expr);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 if (p == NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 return NULL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 // 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
1449 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
1450 vim_free(p);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 return res;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 * 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
1458 * 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
1459 * 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
1460 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 char_u *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 vim_strsave_escape_csi(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 char_u *p)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 char_u *res;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 char_u *s, *d;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 // 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
1469 // illegal utf-8 byte:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 // 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
1471 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
1472 if (res != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 d = res;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 for (s = p; *s != NUL; )
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 // Copy special key unmodified.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 *d++ = *s++;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 *d++ = *s++;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 *d++ = *s++;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 // 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
1487 // 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
1488 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
1489 s += MB_CPTR2LEN(s);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 }
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 *d = NUL;
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 return res;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496
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 * 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
1499 * 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
1500 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 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
1503 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 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
1505
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 while (*s != NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 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
1509 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 *d++ = K_SPECIAL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 s += 3;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 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
1514 && 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
1515 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 *d++ = CSI;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 s += 3;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 *d++ = *s++;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 *d = NUL;
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
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 * 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
1527 * 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
1528 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 int
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 makemap(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 FILE *fd,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 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
1533 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 mapblock_T *mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 char_u c1, c2, c3;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 char_u *p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 char *cmd;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 int abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 int hash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 int did_cpo = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 int i;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 validate_maphash();
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 // 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
1546 // 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
1547 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
1548 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
1549 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 if (abbr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 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
1553 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 if (buf != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 mp = buf->b_first_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 mp = first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 if (buf != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 mp = buf->b_maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 mp = maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 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
1568 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 // skip script-local mappings
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 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
1571 continue;
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 // 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
1574 // 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
1575 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
1576 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
1577 && p[2] == (int)KE_SNR)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 if (*p != NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 // 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
1583 // 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
1584 // 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
1585 c1 = NUL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 c2 = NUL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 c3 = NUL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 if (abbr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 cmd = "abbr";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 cmd = "map";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 switch (mp->m_mode)
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 case NORMAL + VISUAL + SELECTMODE + OP_PENDING:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 case NORMAL:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 c1 = 'n';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 case VISUAL:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 c1 = 'x';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 case SELECTMODE:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 c1 = 's';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 case OP_PENDING:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 c1 = 'o';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 case NORMAL + VISUAL:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 c1 = 'n';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 c2 = 'x';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 case NORMAL + SELECTMODE:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 c1 = 'n';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 c2 = 's';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 case NORMAL + OP_PENDING:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 c1 = 'n';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 c2 = 'o';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 case VISUAL + SELECTMODE:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 c1 = 'v';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 case VISUAL + OP_PENDING:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 c1 = 'x';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 c2 = 'o';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 case SELECTMODE + OP_PENDING:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 c1 = 's';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 c2 = 'o';
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 case NORMAL + VISUAL + SELECTMODE:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 c1 = 'n';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 c2 = 'v';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 case NORMAL + VISUAL + OP_PENDING:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 c1 = 'n';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 c2 = 'x';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 c3 = 'o';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 case NORMAL + SELECTMODE + OP_PENDING:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 c1 = 'n';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 c2 = 's';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 c3 = 'o';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 case VISUAL + SELECTMODE + OP_PENDING:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646 c1 = 'v';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 c2 = 'o';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 case CMDLINE + INSERT:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 if (!abbr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 cmd = "map!";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 case CMDLINE:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 c1 = 'c';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 case INSERT:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 c1 = 'i';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 case LANGMAP:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 c1 = 'l';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 case TERMINAL:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 c1 = 't';
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 default:
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 iemsg(_("E228: makemap: Illegal mode"));
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 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
1670 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 // 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
1672 // 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
1673 if (!did_cpo)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 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
1676 did_cpo = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 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
1679 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
1680 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
1681 did_cpo = TRUE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 if (did_cpo)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 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
1685 || put_eol(fd) < 0
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 || 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
1687 || put_eol(fd) < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 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
1692 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 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
1694 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 if (fputs(cmd, fd) < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 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
1698 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 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
1700 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 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
1702 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 #ifdef FEAT_EVAL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 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
1705 && fputs("<script>", fd) < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 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
1708 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 if ( putc(' ', fd) < 0
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 || 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
1713 || putc(' ', fd) < 0
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 || 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
1715 || put_eol(fd) < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 c1 = c2;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 c2 = c3;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 c3 = NUL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 } while (c1 != NUL);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 }
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 if (did_cpo)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 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
1726 || put_eol(fd) < 0
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 || 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
1728 || put_eol(fd) < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 return OK;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732
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 * write escape string to file
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735 * "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
1736 *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 * 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
1738 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 int
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 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
1741 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 char_u *str = strstart;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 int c;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 int modifiers;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 // :map xx <Nop>
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 if (*str == NUL && what == 1)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 if (fprintf(fd, "<Nop>") < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 return OK;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 for ( ; *str != NUL; ++str)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 char_u *p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 // 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
1759 // K_SPECIAL and CSI bytes
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 p = mb_unescape(&str);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 if (p != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 while (*p != NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764 if (fputc(*p++, fd) < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 --str;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 c = *str;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 // 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
1772 // when they are read back.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 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
1774 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 modifiers = 0x0;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 if (str[1] == KS_MODIFIER)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 modifiers = str[2];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 str += 3;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 c = *str;
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 (c == K_SPECIAL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784 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
1785 str += 2;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 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
1788 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 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
1790 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 continue;
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 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 // 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
1796 // 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
1797 if (c == NL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 if (what == 2)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 if (fprintf(fd, IF_EB("\\\026\n", "\\" CTRL_V_STR "\n")) < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 if (fprintf(fd, "<NL>") < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 return FAIL;
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 continue;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 // 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
1813 // 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
1814 // 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
1815 // 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
1816 // 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
1817 // ":map" rhs.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 // 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
1819 // 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
1820 // 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
1821 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
1822 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 if (putc('\\', fd) < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 else if (c < ' ' || c > '~' || c == '|'
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 || (what == 0 && c == ' ')
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 || (what == 1 && str == strstart && c == ' ')
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 || (what != 2 && c == '<'))
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 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
1832 return FAIL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 if (putc(c, fd) < 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 return FAIL;
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 return OK;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 }
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 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 * 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
1842 * Used after ":set term=xxx".
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 check_map_keycodes(void)
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 mapblock_T *mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 char_u *p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 int i;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 char_u buf[3];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 char_u *save_name;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 int abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 int hash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 buf_T *bp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 validate_maphash();
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 save_name = sourcing_name;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 sourcing_name = (char_u *)"mappings"; // avoids giving error messages
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 // This this once for each buffer, and then once for global
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 // mappings/abbreviations with bp == NULL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 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
1863 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 // 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
1865 // 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
1866 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
1867 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
1868 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 if (abbr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 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
1872 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 if (bp != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 mp = bp->b_first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 mp = first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 if (bp != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 mp = bp->b_maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 mp = maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 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
1886 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 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
1888 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 if (i == 0)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 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
1891 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 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
1893 while (*p)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 if (*p == K_SPECIAL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 ++p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 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
1899 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 buf[0] = p[0];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 buf[1] = p[1];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 buf[2] = NUL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 (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
1904 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 ++p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 ++p;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 }
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 if (bp == NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 sourcing_name = save_name;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 #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
1919 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 * 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
1921 * 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
1922 * NULL when no mapping found.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 char_u *
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 check_map(
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 char_u *keys,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 int mode,
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 int exact, // require exact match
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 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
1930 int abbr, // do abbreviations
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 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
1932 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
1933 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 int hash;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 int len, minlen;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 mapblock_T *mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 char_u *s;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 int local;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 validate_maphash();
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 len = (int)STRLEN(keys);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 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
1944 // loop over all hash lists
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 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
1946 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 if (abbr)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 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
1950 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 if (local)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 mp = curbuf->b_first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 mp = first_abbr;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 else if (local)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 mp = curbuf->b_maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 mp = maphash[hash];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 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
1961 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 // 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
1963 // ones
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 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
1965 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 if (len > mp->m_keylen)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 minlen = mp->m_keylen;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 minlen = len;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 s = mp->m_keys;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 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
1972 && s[2] != NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 s += 3;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 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
1976 minlen = mp->m_keylen - 3;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 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
1979 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 if (mp_ptr != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 *mp_ptr = mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 if (local_ptr != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 *local_ptr = local;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 return mp->m_str;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 return NULL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 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
1995 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 char_u *keys;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 char_u *which;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 char_u buf[NUMBUFLEN];
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 char_u *keys_buf = NULL;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 char_u *rhs;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 int mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 int abbr = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 int get_dict = FALSE;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 mapblock_T *mp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 int buffer_local;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 // return empty string for failure
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 rettv->v_type = VAR_STRING;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 rettv->vval.v_string = NULL;
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 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
2012 if (*keys == NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 return;
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 (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
2016 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 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
2018 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
2019 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 abbr = (int)tv_get_number(&argvars[2]);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 if (argvars[3].v_type != VAR_UNKNOWN)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022 get_dict = (int)tv_get_number(&argvars[3]);
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 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026 which = (char_u *)"";
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027 if (which == NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 return;
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 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
2031
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 keys = replace_termcodes(keys, &keys_buf, TRUE, TRUE, FALSE);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 rhs = check_map(keys, mode, exact, FALSE, abbr, &mp, &buffer_local);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 vim_free(keys_buf);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 if (!get_dict)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 // Return a string.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 if (rhs != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 if (*rhs == NUL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 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
2043 else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 rettv->vval.v_string = str2special_save(rhs, FALSE);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2047 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 else if (rettv_dict_alloc(rettv) != FAIL && rhs != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 // Return a dictionary.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 char_u *lhs = str2special_save(mp->m_keys, TRUE);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 char_u *mapmode = 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
2053 dict_T *dict = rettv->vval.v_dict;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055 dict_add_string(dict, "lhs", lhs);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 dict_add_string(dict, "rhs", mp->m_orig_str);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 dict_add_number(dict, "noremap", mp->m_noremap ? 1L : 0L);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 dict_add_number(dict, "expr", mp->m_expr ? 1L : 0L);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 dict_add_number(dict, "silent", mp->m_silent ? 1L : 0L);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 dict_add_number(dict, "sid", (long)mp->m_script_ctx.sc_sid);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 dict_add_number(dict, "lnum", (long)mp->m_script_ctx.sc_lnum);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 dict_add_number(dict, "buffer", (long)buffer_local);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 dict_add_number(dict, "nowait", mp->m_nowait ? 1L : 0L);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 dict_add_string(dict, "mode", mapmode);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 vim_free(lhs);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 vim_free(mapmode);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 #endif
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 #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
2073
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 # define VIS_SEL (VISUAL+SELECTMODE) // abbreviation
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075
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 * 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
2078 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079 struct initmap
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 char_u *arg;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 int mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083 };
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 # ifdef FEAT_GUI_MSWIN
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 // 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
2087 static struct initmap initmappings[] =
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 // paste, copy and cut
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 {(char_u *)"<S-Insert> \"*P", NORMAL},
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 {(char_u *)"<S-Insert> \"-d\"*P", VIS_SEL},
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 {(char_u *)"<S-Insert> <C-R><C-O>*", INSERT+CMDLINE},
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093 {(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
2094 {(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
2095 {(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
2096 {(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
2097 // 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
2098 };
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 # endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 # 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
2102 // 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
2103 static struct initmap cinitmappings[] =
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 {(char_u *)"\316w <C-Home>", NORMAL+VIS_SEL},
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 {(char_u *)"\316w <C-Home>", INSERT+CMDLINE},
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 {(char_u *)"\316u <C-End>", NORMAL+VIS_SEL},
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 {(char_u *)"\316u <C-End>", INSERT+CMDLINE},
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 // paste, copy and cut
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 # ifdef FEAT_CLIPBOARD
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 {(char_u *)"\316\324 \"*P", NORMAL}, // SHIFT-Insert is "*P
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 {(char_u *)"\316\324 \"-d\"*P", VIS_SEL}, // SHIFT-Insert is "-d"*P
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 {(char_u *)"\316\324 \022\017*", INSERT}, // SHIFT-Insert is ^R^O*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 {(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
2116 {(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
2117 {(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
2118 {(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
2119 # else
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 {(char_u *)"\316\324 P", NORMAL}, // SHIFT-Insert is P
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 {(char_u *)"\316\324 \"-dP", VIS_SEL}, // SHIFT-Insert is "-dP
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 {(char_u *)"\316\324 \022\017\"", INSERT}, // SHIFT-Insert is ^R^O"
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 {(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
2124 {(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
2125 {(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
2126 # endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127 };
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 # endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 # if defined(MACOS_X)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 static struct initmap initmappings[] =
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 // Use the Standard MacOS binding.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 // paste, copy and cut
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 {(char_u *)"<D-v> \"*P", NORMAL},
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 {(char_u *)"<D-v> \"-d\"*P", VIS_SEL},
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 {(char_u *)"<D-v> <C-R>*", INSERT+CMDLINE},
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 {(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
2139 {(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
2140 {(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
2141 };
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 # endif
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 # undef VIS_SEL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 * Set up default mappings.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 init_mappings(void)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 #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
2154 int i;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 # 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
2157 # ifdef VIMDLL
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 if (!gui.starting)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 # endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 for (i = 0;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 i < (int)(sizeof(cinitmappings) / sizeof(struct initmap)); ++i)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 add_map(cinitmappings[i].arg, cinitmappings[i].mode);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 # endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 # if defined(FEAT_GUI_MSWIN) || defined(MACOS_X)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 for (i = 0; i < (int)(sizeof(initmappings) / sizeof(struct initmap)); ++i)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 add_map(initmappings[i].arg, initmappings[i].mode);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 # endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 #endif
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 #if defined(MSWIN) || defined(FEAT_CMDWIN) || defined(MACOS_X) \
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 || defined(PROTO)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 * Add a mapping "map" for mode "mode".
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 * 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
2178 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 add_map(char_u *map, int mode)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 char_u *s;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183 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
2184
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 p_cpo = (char_u *)""; // Allow <> notation
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 s = vim_strsave(map);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 if (s != NULL)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189 (void)do_map(0, s, mode, FALSE);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 vim_free(s);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 p_cpo = cpo_save;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 #endif
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 static void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 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
2198 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2199 int mode;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2200 char_u *cmdp;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202 cmdp = eap->cmd;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 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
2204
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2205 switch (do_map((*cmdp == 'n') ? 2 : (*cmdp == 'u'),
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2206 eap->arg, mode, isabbrev))
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 case 1: emsg(_(e_invarg));
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2210 case 2: emsg((isabbrev ? _(e_noabbr) : _(e_nomap)));
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 break;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 * ":abbreviate" and friends.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2217 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 ex_abbreviate(exarg_T *eap)
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 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
2222 }
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 * ":map" and friends.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228 ex_map(exarg_T *eap)
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 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
2231 // 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
2232 if (secure)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2234 secure = 2;
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 msg_outtrans(eap->cmd);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 msg_putchar('\n');
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 do_exmap(eap, FALSE);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 }
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 /*
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2242 * ":unmap" and friends.
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 */
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 ex_unmap(exarg_T *eap)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 do_exmap(eap, FALSE);
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 }
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 * ":mapclear" and friends.
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 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 ex_mapclear(exarg_T *eap)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 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
2257 }
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 * ":abclear" and friends.
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 void
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263 ex_abclear(exarg_T *eap)
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 {
97a750e8707f patch 8.1.1785: map functionality mixed with character input
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 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
2266 }