comparison src/getchar.c @ 17602:653ab352b019 v8.1.1798

patch 8.1.1798: warning for unused variable in tiny version commit https://github.com/vim/vim/commit/eda35f7127c6ac51573eda808687f6369c31ee2d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 3 14:59:44 2019 +0200 patch 8.1.1798: warning for unused variable in tiny version Problem: Warning for unused variable in tiny version. (Tony Mechelynck) Solution: Move inside #ifdef. Reformat code.
author Bram Moolenaar <Bram@vim.org>
date Sat, 03 Aug 2019 15:00:05 +0200
parents ca42eb789472
children 506dd2efcbb2
comparison
equal deleted inserted replaced
17601:de9cdfda3326 17602:653ab352b019
1908 } map_result_T; 1908 } map_result_T;
1909 1909
1910 /* 1910 /*
1911 * Handle mappings in the typeahead buffer. 1911 * Handle mappings in the typeahead buffer.
1912 * - When something was mapped, return map_result_retry for recursive mappings. 1912 * - When something was mapped, return map_result_retry for recursive mappings.
1913 * - When nothing mapped and typeahead has a character return map_result_get. 1913 * - When nothing mapped and typeahead has a character: return map_result_get.
1914 * - When there is no match yet, return map_result_nomatch, need to get more 1914 * - When there is no match yet, return map_result_nomatch, need to get more
1915 * typeahead. 1915 * typeahead.
1916 */ 1916 */
1917 static int 1917 static int
1918 handle_mapping( 1918 handle_mapping(
1934 int i; 1934 int i;
1935 int local_State = get_real_state(); 1935 int local_State = get_real_state();
1936 1936
1937 /* 1937 /*
1938 * Check for a mappable key sequence. 1938 * Check for a mappable key sequence.
1939 * Walk through one maphash[] list until we find an 1939 * Walk through one maphash[] list until we find an entry that matches.
1940 * entry that matches.
1941 * 1940 *
1942 * Don't look for mappings if: 1941 * Don't look for mappings if:
1943 * - no_mapping set: mapping disabled (e.g. for CTRL-V) 1942 * - no_mapping set: mapping disabled (e.g. for CTRL-V)
1944 * - maphash_valid not set: no mappings present. 1943 * - maphash_valid not set: no mappings present.
1945 * - typebuf.tb_buf[typebuf.tb_off] should not be remapped 1944 * - typebuf.tb_buf[typebuf.tb_off] should not be remapped
1946 * - in insert or cmdline mode and 'paste' option set 1945 * - in insert or cmdline mode and 'paste' option set
1947 * - waiting for "hit return to continue" and CR or SPACE 1946 * - waiting for "hit return to continue" and CR or SPACE typed
1948 * typed
1949 * - waiting for a char with --more-- 1947 * - waiting for a char with --more--
1950 * - in Ctrl-X mode, and we get a valid char for that mode 1948 * - in Ctrl-X mode, and we get a valid char for that mode
1951 */ 1949 */
1952 tb_c1 = typebuf.tb_buf[typebuf.tb_off]; 1950 tb_c1 = typebuf.tb_buf[typebuf.tb_off];
1953 if (no_mapping == 0 && is_maphash_valid() 1951 if (no_mapping == 0 && is_maphash_valid()
1959 && !(p_paste && (State & (INSERT + CMDLINE))) 1957 && !(p_paste && (State & (INSERT + CMDLINE)))
1960 && !(State == HITRETURN && (tb_c1 == CAR || tb_c1 == ' ')) 1958 && !(State == HITRETURN && (tb_c1 == CAR || tb_c1 == ' '))
1961 && State != ASKMORE 1959 && State != ASKMORE
1962 && State != CONFIRM 1960 && State != CONFIRM
1963 #ifdef FEAT_INS_EXPAND 1961 #ifdef FEAT_INS_EXPAND
1964 && !((ctrl_x_mode_not_default() 1962 && !((ctrl_x_mode_not_default() && vim_is_ctrl_x_key(tb_c1))
1965 && vim_is_ctrl_x_key(tb_c1))
1966 || ((compl_cont_status & CONT_LOCAL) 1963 || ((compl_cont_status & CONT_LOCAL)
1967 && (tb_c1 == Ctrl_N || tb_c1 == Ctrl_P))) 1964 && (tb_c1 == Ctrl_N || tb_c1 == Ctrl_P)))
1968 #endif 1965 #endif
1969 ) 1966 )
1970 { 1967 {
1971 #ifdef FEAT_LANGMAP 1968 #ifdef FEAT_LANGMAP
1972 if (tb_c1 == K_SPECIAL) 1969 if (tb_c1 == K_SPECIAL)
1973 nolmaplen = 2; 1970 nolmaplen = 2;
1974 else 1971 else
1975 { 1972 {
1976 LANGMAP_ADJUST(tb_c1, 1973 LANGMAP_ADJUST(tb_c1, (State & (CMDLINE | INSERT)) == 0
1977 (State & (CMDLINE | INSERT)) == 0 1974 && get_real_state() != SELECTMODE);
1978 && get_real_state() != SELECTMODE);
1979 nolmaplen = 0; 1975 nolmaplen = 0;
1980 } 1976 }
1981 #endif 1977 #endif
1982 // First try buffer-local mappings. 1978 // First try buffer-local mappings.
1983 mp = get_buf_maphash_list(local_State, tb_c1); 1979 mp = get_buf_maphash_list(local_State, tb_c1);
1986 { 1982 {
1987 // There are no buffer-local mappings. 1983 // There are no buffer-local mappings.
1988 mp = mp2; 1984 mp = mp2;
1989 mp2 = NULL; 1985 mp2 = NULL;
1990 } 1986 }
1987
1991 /* 1988 /*
1992 * Loop until a partly matching mapping is found or 1989 * Loop until a partly matching mapping is found or all (local)
1993 * all (local) mappings have been checked. 1990 * mappings have been checked.
1994 * The longest full match is remembered in "mp_match". 1991 * The longest full match is remembered in "mp_match".
1995 * A full match is only accepted if there is no partly 1992 * A full match is only accepted if there is no partly match, so "aa"
1996 * match, so "aa" and "aaa" can both be mapped. 1993 * and "aaa" can both be mapped.
1997 */ 1994 */
1998 mp_match = NULL; 1995 mp_match = NULL;
1999 mp_match_len = 0; 1996 mp_match_len = 0;
2000 for ( ; mp != NULL; 1997 for ( ; mp != NULL;
2001 mp->m_next == NULL ? (mp = mp2, mp2 = NULL) 1998 mp->m_next == NULL ? (mp = mp2, mp2 = NULL) : (mp = mp->m_next))
2002 : (mp = mp->m_next)) 1999 {
2003 { 2000 // Only consider an entry if the first character matches and it is
2004 // Only consider an entry if the first character 2001 // for the current state.
2005 // matches and it is for the current state.
2006 // Skip ":lmap" mappings if keys were mapped. 2002 // Skip ":lmap" mappings if keys were mapped.
2007 if (mp->m_keys[0] == tb_c1 2003 if (mp->m_keys[0] == tb_c1
2008 && (mp->m_mode & local_State) 2004 && (mp->m_mode & local_State)
2009 && ((mp->m_mode & LANGMAP) == 0 2005 && ((mp->m_mode & LANGMAP) == 0 || typebuf.tb_maplen == 0))
2010 || typebuf.tb_maplen == 0))
2011 { 2006 {
2012 #ifdef FEAT_LANGMAP 2007 #ifdef FEAT_LANGMAP
2013 int nomap = nolmaplen; 2008 int nomap = nolmaplen;
2014 int c2; 2009 int c2;
2015 #endif 2010 #endif
2030 typebuf.tb_buf[typebuf.tb_off + mlen]) 2025 typebuf.tb_buf[typebuf.tb_off + mlen])
2031 #endif 2026 #endif
2032 break; 2027 break;
2033 } 2028 }
2034 2029
2035 // Don't allow mapping the first byte(s) of a 2030 // Don't allow mapping the first byte(s) of a multi-byte char.
2036 // multi-byte char. Happens when mapping 2031 // Happens when mapping <M-a> and then changing 'encoding'.
2037 // <M-a> and then changing 'encoding'. Beware 2032 // Beware that 0x80 is escaped.
2038 // that 0x80 is escaped.
2039 { 2033 {
2040 char_u *p1 = mp->m_keys; 2034 char_u *p1 = mp->m_keys;
2041 char_u *p2 = mb_unescape(&p1); 2035 char_u *p2 = mb_unescape(&p1);
2042 2036
2043 if (has_mbyte && p2 != NULL 2037 if (has_mbyte && p2 != NULL
2044 && MB_BYTE2LEN(tb_c1) > MB_PTR2LEN(p2)) 2038 && MB_BYTE2LEN(tb_c1) > MB_PTR2LEN(p2))
2045 mlen = 0; 2039 mlen = 0;
2046 } 2040 }
2047 2041
2048 // Check an entry whether it matches. 2042 // Check an entry whether it matches.
2049 // - Full match: mlen == keylen 2043 // - Full match: mlen == keylen
2050 // - Partly match: mlen == typebuf.tb_len 2044 // - Partly match: mlen == typebuf.tb_len
2051 keylen = mp->m_keylen; 2045 keylen = mp->m_keylen;
2052 if (mlen == keylen 2046 if (mlen == keylen || (mlen == typebuf.tb_len
2053 || (mlen == typebuf.tb_len 2047 && typebuf.tb_len < keylen))
2054 && typebuf.tb_len < keylen))
2055 { 2048 {
2056 char_u *s; 2049 char_u *s;
2057 int n; 2050 int n;
2058 2051
2059 // If only script-local mappings are 2052 // If only script-local mappings are allowed, check if the
2060 // allowed, check if the mapping starts 2053 // mapping starts with K_SNR.
2061 // with K_SNR.
2062 s = typebuf.tb_noremap + typebuf.tb_off; 2054 s = typebuf.tb_noremap + typebuf.tb_off;
2063 if (*s == RM_SCRIPT 2055 if (*s == RM_SCRIPT
2064 && (mp->m_keys[0] != K_SPECIAL 2056 && (mp->m_keys[0] != K_SPECIAL
2065 || mp->m_keys[1] != KS_EXTRA 2057 || mp->m_keys[1] != KS_EXTRA
2066 || mp->m_keys[2] 2058 || mp->m_keys[2] != (int)KE_SNR))
2067 != (int)KE_SNR))
2068 continue; 2059 continue;
2069 2060
2070 // If one of the typed keys cannot be 2061 // If one of the typed keys cannot be remapped, skip the
2071 // remapped, skip the entry. 2062 // entry.
2072 for (n = mlen; --n >= 0; ) 2063 for (n = mlen; --n >= 0; )
2073 if (*s++ & (RM_NONE|RM_ABBR)) 2064 if (*s++ & (RM_NONE|RM_ABBR))
2074 break; 2065 break;
2075 if (n >= 0) 2066 if (n >= 0)
2076 continue; 2067 continue;
2077 2068
2078 if (keylen > typebuf.tb_len) 2069 if (keylen > typebuf.tb_len)
2079 { 2070 {
2080 if (!*timedout && !(mp_match != NULL 2071 if (!*timedout && !(mp_match != NULL
2081 && mp_match->m_nowait)) 2072 && mp_match->m_nowait))
2082 { 2073 {
2083 // break at a partly match 2074 // break at a partly match
2084 keylen = KEYLEN_PART_MAP; 2075 keylen = KEYLEN_PART_MAP;
2085 break; 2076 break;
2086 } 2077 }
2091 mp_match = mp; 2082 mp_match = mp;
2092 mp_match_len = keylen; 2083 mp_match_len = keylen;
2093 } 2084 }
2094 } 2085 }
2095 else 2086 else
2096 // No match; may have to check for 2087 // No match; may have to check for termcode at next
2097 // termcode at next character. 2088 // character.
2098 if (max_mlen < mlen) 2089 if (max_mlen < mlen)
2099 max_mlen = mlen; 2090 max_mlen = mlen;
2100 } 2091 }
2101 } 2092 }
2102 2093
2103 // If no partly match found, use the longest full 2094 // If no partly match found, use the longest full match.
2104 // match.
2105 if (keylen != KEYLEN_PART_MAP) 2095 if (keylen != KEYLEN_PART_MAP)
2106 { 2096 {
2107 mp = mp_match; 2097 mp = mp_match;
2108 keylen = mp_match_len; 2098 keylen = mp_match_len;
2109 } 2099 }
2112 /* 2102 /*
2113 * Check for match with 'pastetoggle' 2103 * Check for match with 'pastetoggle'
2114 */ 2104 */
2115 if (*p_pt != NUL && mp == NULL && (State & (INSERT|NORMAL))) 2105 if (*p_pt != NUL && mp == NULL && (State & (INSERT|NORMAL)))
2116 { 2106 {
2117 for (mlen = 0; mlen < typebuf.tb_len && p_pt[mlen]; 2107 for (mlen = 0; mlen < typebuf.tb_len && p_pt[mlen]; ++mlen)
2118 ++mlen) 2108 if (p_pt[mlen] != typebuf.tb_buf[typebuf.tb_off + mlen])
2119 if (p_pt[mlen] != typebuf.tb_buf[typebuf.tb_off
2120 + mlen])
2121 break; 2109 break;
2122 if (p_pt[mlen] == NUL) // match 2110 if (p_pt[mlen] == NUL) // match
2123 { 2111 {
2124 // write chars to script file(s) 2112 // write chars to script file(s)
2125 if (mlen > typebuf.tb_maplen) 2113 if (mlen > typebuf.tb_maplen)
2126 gotchars(typebuf.tb_buf + typebuf.tb_off 2114 gotchars(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_maplen,
2127 + typebuf.tb_maplen, 2115 mlen - typebuf.tb_maplen);
2128 mlen - typebuf.tb_maplen);
2129 2116
2130 del_typebuf(mlen, 0); // remove the chars 2117 del_typebuf(mlen, 0); // remove the chars
2131 set_option_value((char_u *)"paste", 2118 set_option_value((char_u *)"paste", (long)!p_paste, NULL, 0);
2132 (long)!p_paste, NULL, 0);
2133 if (!(State & INSERT)) 2119 if (!(State & INSERT))
2134 { 2120 {
2135 msg_col = 0; 2121 msg_col = 0;
2136 msg_row = Rows - 1; 2122 msg_row = Rows - 1;
2137 msg_clr_eos(); // clear ruler 2123 msg_clr_eos(); // clear ruler
2145 } 2131 }
2146 // Need more chars for partly match. 2132 // Need more chars for partly match.
2147 if (mlen == typebuf.tb_len) 2133 if (mlen == typebuf.tb_len)
2148 keylen = KEYLEN_PART_KEY; 2134 keylen = KEYLEN_PART_KEY;
2149 else if (max_mlen < mlen) 2135 else if (max_mlen < mlen)
2150 // no match, may have to check for termcode at 2136 // no match, may have to check for termcode at next character
2151 // next character
2152 max_mlen = mlen + 1; 2137 max_mlen = mlen + 1;
2153 } 2138 }
2154 2139
2155 if ((mp == NULL || max_mlen >= mp_match_len) 2140 if ((mp == NULL || max_mlen >= mp_match_len) && keylen != KEYLEN_PART_MAP)
2156 && keylen != KEYLEN_PART_MAP)
2157 { 2141 {
2158 int save_keylen = keylen; 2142 int save_keylen = keylen;
2159 2143
2160 /* 2144 /*
2161 * When no matching mapping found or found a 2145 * When no matching mapping found or found a non-matching mapping that
2162 * non-matching mapping that matches at least what the 2146 * matches at least what the matching mapping matched:
2163 * matching mapping matched:
2164 * Check if we have a terminal code, when: 2147 * Check if we have a terminal code, when:
2165 * mapping is allowed, 2148 * - mapping is allowed,
2166 * keys have not been mapped, 2149 * - keys have not been mapped,
2167 * and not an ESC sequence, not in insert mode or 2150 * - and not an ESC sequence, not in insert mode or p_ek is on,
2168 * p_ek is on, 2151 * - and when not timed out,
2169 * and when not timed out,
2170 */ 2152 */
2171 if ((no_mapping == 0 || allow_keys != 0) 2153 if ((no_mapping == 0 || allow_keys != 0)
2172 && (typebuf.tb_maplen == 0 2154 && (typebuf.tb_maplen == 0
2173 || (p_remap && typebuf.tb_noremap[ 2155 || (p_remap && typebuf.tb_noremap[
2174 typebuf.tb_off] == RM_YES)) 2156 typebuf.tb_off] == RM_YES))
2175 && !*timedout) 2157 && !*timedout)
2176 { 2158 {
2177 keylen = check_termcode(max_mlen + 1, 2159 keylen = check_termcode(max_mlen + 1,
2178 NULL, 0, NULL); 2160 NULL, 0, NULL);
2179 2161
2180 // If no termcode matched but 'pastetoggle' 2162 // If no termcode matched but 'pastetoggle' matched partially it's
2181 // matched partially it's like an incomplete key 2163 // like an incomplete key sequence.
2182 // sequence.
2183 if (keylen == 0 && save_keylen == KEYLEN_PART_KEY) 2164 if (keylen == 0 && save_keylen == KEYLEN_PART_KEY)
2184 keylen = KEYLEN_PART_KEY; 2165 keylen = KEYLEN_PART_KEY;
2185 2166
2186 // When getting a partial match, but the last 2167 // When getting a partial match, but the last characters were not
2187 // characters were not typed, don't wait for a 2168 // typed, don't wait for a typed character to complete the
2188 // typed character to complete the termcode. 2169 // termcode. This helps a lot when a ":normal" command ends in an
2189 // This helps a lot when a ":normal" command ends 2170 // ESC.
2190 // in an ESC. 2171 if (keylen < 0 && typebuf.tb_len == typebuf.tb_maplen)
2191 if (keylen < 0
2192 && typebuf.tb_len == typebuf.tb_maplen)
2193 keylen = 0; 2172 keylen = 0;
2194 } 2173 }
2195 else 2174 else
2196 keylen = 0; 2175 keylen = 0;
2197 if (keylen == 0) // no matching terminal code 2176 if (keylen == 0) // no matching terminal code
2198 { 2177 {
2199 #ifdef AMIGA // check for window bounds report 2178 #ifdef AMIGA
2179 // check for window bounds report
2200 if (typebuf.tb_maplen == 0 && (typebuf.tb_buf[ 2180 if (typebuf.tb_maplen == 0 && (typebuf.tb_buf[
2201 typebuf.tb_off] & 0xff) == CSI) 2181 typebuf.tb_off] & 0xff) == CSI)
2202 { 2182 {
2203 char_u *s; 2183 char_u *s;
2204 2184
2205 for (s = typebuf.tb_buf + typebuf.tb_off + 1; 2185 for (s = typebuf.tb_buf + typebuf.tb_off + 1;
2206 s < typebuf.tb_buf + typebuf.tb_off 2186 s < typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len
2207 + typebuf.tb_len 2187 && (VIM_ISDIGIT(*s) || *s == ';' || *s == ' ');
2208 && (VIM_ISDIGIT(*s) || *s == ';'
2209 || *s == ' ');
2210 ++s) 2188 ++s)
2211 ; 2189 ;
2212 if (*s == 'r' || *s == '|') // found one 2190 if (*s == 'r' || *s == '|') // found one
2213 { 2191 {
2214 del_typebuf((int)(s + 1 - 2192 del_typebuf(
2215 (typebuf.tb_buf + typebuf.tb_off)), 0); 2193 (int)(s + 1 - (typebuf.tb_buf + typebuf.tb_off)), 0);
2216 // get size and redraw screen 2194 // get size and redraw screen
2217 shell_resized(); 2195 shell_resized();
2218 *keylenp = keylen; 2196 *keylenp = keylen;
2219 return map_result_retry; 2197 return map_result_retry;
2220 } 2198 }
2221 if (*s == NUL) // need more characters 2199 if (*s == NUL) // need more characters
2222 keylen = KEYLEN_PART_KEY; 2200 keylen = KEYLEN_PART_KEY;
2223 } 2201 }
2224 if (keylen >= 0) 2202 if (keylen >= 0)
2225 #endif 2203 #endif
2226 // When there was a matching mapping and no 2204 // When there was a matching mapping and no termcode could be
2227 // termcode could be replaced after another one, 2205 // replaced after another one, use that mapping (loop around).
2228 // use that mapping (loop around). If there was 2206 // If there was no mapping at all use the character from the
2229 // no mapping at all use the character from the 2207 // typeahead buffer right here.
2230 // typeahead buffer right here. 2208 if (mp == NULL)
2231 if (mp == NULL) 2209 {
2232 { 2210 *keylenp = keylen;
2233 *keylenp = keylen; 2211 return map_result_get; // got character, break for loop
2234 return map_result_get; // got character, break for loop 2212 }
2235 }
2236 } 2213 }
2237 2214
2238 if (keylen > 0) // full matching terminal code 2215 if (keylen > 0) // full matching terminal code
2239 { 2216 {
2240 #if defined(FEAT_GUI) && defined(FEAT_MENU) 2217 #if defined(FEAT_GUI) && defined(FEAT_MENU)
2241 if (typebuf.tb_len >= 2 2218 if (typebuf.tb_len >= 2
2242 && typebuf.tb_buf[typebuf.tb_off] == K_SPECIAL 2219 && typebuf.tb_buf[typebuf.tb_off] == K_SPECIAL
2243 && typebuf.tb_buf[typebuf.tb_off + 1] 2220 && typebuf.tb_buf[typebuf.tb_off + 1] == KS_MENU)
2244 == KS_MENU)
2245 { 2221 {
2246 int idx; 2222 int idx;
2247 2223
2248 // Using a menu may cause a break in undo! 2224 // Using a menu may cause a break in undo! It's like using
2249 // It's like using gotchars(), but without 2225 // gotchars(), but without recording or writing to a script
2250 // recording or writing to a script file. 2226 // file.
2251 may_sync_undo(); 2227 may_sync_undo();
2252 del_typebuf(3, 0); 2228 del_typebuf(3, 0);
2253 idx = get_menu_index(current_menu, local_State); 2229 idx = get_menu_index(current_menu, local_State);
2254 if (idx != MENU_INDEX_INVALID) 2230 if (idx != MENU_INDEX_INVALID)
2255 { 2231 {
2256 // In Select mode and a Visual mode menu 2232 // In Select mode and a Visual mode menu is used: Switch
2257 // is used: Switch to Visual mode 2233 // to Visual mode temporarily. Append K_SELECT to switch
2258 // temporarily. Append K_SELECT to switch
2259 // back to Select mode. 2234 // back to Select mode.
2260 if (VIsual_active && VIsual_select 2235 if (VIsual_active && VIsual_select
2261 && (current_menu->modes & VISUAL)) 2236 && (current_menu->modes & VISUAL))
2262 { 2237 {
2263 VIsual_select = FALSE; 2238 VIsual_select = FALSE;
2264 (void)ins_typebuf(K_SELECT_STRING, 2239 (void)ins_typebuf(K_SELECT_STRING,
2265 REMAP_NONE, 0, TRUE, FALSE); 2240 REMAP_NONE, 0, TRUE, FALSE);
2266 } 2241 }
2267 ins_typebuf(current_menu->strings[idx], 2242 ins_typebuf(current_menu->strings[idx],
2268 current_menu->noremap[idx], 2243 current_menu->noremap[idx],
2269 0, TRUE, 2244 0, TRUE, current_menu->silent[idx]);
2270 current_menu->silent[idx]);
2271 } 2245 }
2272 } 2246 }
2273 #endif // FEAT_GUI && FEAT_MENU 2247 #endif // FEAT_GUI && FEAT_MENU
2274 *keylenp = keylen; 2248 *keylenp = keylen;
2275 return map_result_retry; // try mapping again 2249 return map_result_retry; // try mapping again
2276 } 2250 }
2277 2251
2278 // Partial match: get some more characters. When a 2252 // Partial match: get some more characters. When a matching mapping
2279 // matching mapping was found use that one. 2253 // was found use that one.
2280 if (mp == NULL || keylen < 0) 2254 if (mp == NULL || keylen < 0)
2281 keylen = KEYLEN_PART_KEY; 2255 keylen = KEYLEN_PART_KEY;
2282 else 2256 else
2283 keylen = mp_match_len; 2257 keylen = mp_match_len;
2284 } 2258 }
2289 if (keylen >= 0 && keylen <= typebuf.tb_len) 2263 if (keylen >= 0 && keylen <= typebuf.tb_len)
2290 { 2264 {
2291 char_u *map_str; 2265 char_u *map_str;
2292 2266
2293 #ifdef FEAT_EVAL 2267 #ifdef FEAT_EVAL
2294 int save_m_expr; 2268 int save_m_expr;
2295 int save_m_noremap; 2269 int save_m_noremap;
2296 int save_m_silent; 2270 int save_m_silent;
2297 char_u *save_m_keys; 2271 char_u *save_m_keys;
2298 char_u *save_m_str; 2272 char_u *save_m_str;
2299 #else 2273 #else
2300 # define save_m_noremap mp->m_noremap 2274 # define save_m_noremap mp->m_noremap
2301 # define save_m_silent mp->m_silent 2275 # define save_m_silent mp->m_silent
2302 #endif 2276 #endif
2303 2277
2304 // write chars to script file(s) 2278 // write chars to script file(s)
2305 if (keylen > typebuf.tb_maplen) 2279 if (keylen > typebuf.tb_maplen)
2306 gotchars(typebuf.tb_buf + typebuf.tb_off 2280 gotchars(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_maplen,
2307 + typebuf.tb_maplen, 2281 keylen - typebuf.tb_maplen);
2308 keylen - typebuf.tb_maplen);
2309 2282
2310 cmd_silent = (typebuf.tb_silent > 0); 2283 cmd_silent = (typebuf.tb_silent > 0);
2311 del_typebuf(keylen, 0); // remove the mapped keys 2284 del_typebuf(keylen, 0); // remove the mapped keys
2312 2285
2313 /* 2286 /*
2326 *keylenp = keylen; 2299 *keylenp = keylen;
2327 return map_result_fail; 2300 return map_result_fail;
2328 } 2301 }
2329 2302
2330 /* 2303 /*
2331 * In Select mode and a Visual mode mapping is used: 2304 * In Select mode and a Visual mode mapping is used: Switch to Visual
2332 * Switch to Visual mode temporarily. Append K_SELECT 2305 * mode temporarily. Append K_SELECT to switch back to Select mode.
2333 * to switch back to Select mode.
2334 */ 2306 */
2335 if (VIsual_active && VIsual_select 2307 if (VIsual_active && VIsual_select && (mp->m_mode & VISUAL))
2336 && (mp->m_mode & VISUAL))
2337 { 2308 {
2338 VIsual_select = FALSE; 2309 VIsual_select = FALSE;
2339 (void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, 2310 (void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, 0, TRUE, FALSE);
2340 0, TRUE, FALSE);
2341 } 2311 }
2342 2312
2343 #ifdef FEAT_EVAL 2313 #ifdef FEAT_EVAL
2344 // Copy the values from *mp that are used, because 2314 // Copy the values from *mp that are used, because evaluating the
2345 // evaluating the expression may invoke a function 2315 // expression may invoke a function that redefines the mapping, thereby
2346 // that redefines the mapping, thereby making *mp 2316 // making *mp invalid.
2347 // invalid.
2348 save_m_expr = mp->m_expr; 2317 save_m_expr = mp->m_expr;
2349 save_m_noremap = mp->m_noremap; 2318 save_m_noremap = mp->m_noremap;
2350 save_m_silent = mp->m_silent; 2319 save_m_silent = mp->m_silent;
2351 save_m_keys = NULL; // only saved when needed 2320 save_m_keys = NULL; // only saved when needed
2352 save_m_str = NULL; // only saved when needed 2321 save_m_str = NULL; // only saved when needed
2353 2322
2354 /* 2323 /*
2355 * Handle ":map <expr>": evaluate the {rhs} as an 2324 * Handle ":map <expr>": evaluate the {rhs} as an expression. Also
2356 * expression. Also save and restore the command line 2325 * save and restore the command line for "normal :".
2357 * for "normal :".
2358 */ 2326 */
2359 if (mp->m_expr) 2327 if (mp->m_expr)
2360 { 2328 {
2361 int save_vgetc_busy = vgetc_busy; 2329 int save_vgetc_busy = vgetc_busy;
2362 int save_may_garbage_collect = may_garbage_collect; 2330 int save_may_garbage_collect = may_garbage_collect;
2375 #endif 2343 #endif
2376 map_str = mp->m_str; 2344 map_str = mp->m_str;
2377 2345
2378 /* 2346 /*
2379 * Insert the 'to' part in the typebuf.tb_buf. 2347 * Insert the 'to' part in the typebuf.tb_buf.
2380 * If 'from' field is the same as the start of the 2348 * If 'from' field is the same as the start of the 'to' field, don't
2381 * 'to' field, don't remap the first character (but do 2349 * remap the first character (but do allow abbreviations).
2382 * allow abbreviations). 2350 * If m_noremap is set, don't remap the whole 'to' part.
2383 * If m_noremap is set, don't remap the whole 'to'
2384 * part.
2385 */ 2351 */
2386 if (map_str == NULL) 2352 if (map_str == NULL)
2387 i = FAIL; 2353 i = FAIL;
2388 else 2354 else
2389 { 2355 {
2391 2357
2392 if (save_m_noremap != REMAP_YES) 2358 if (save_m_noremap != REMAP_YES)
2393 noremap = save_m_noremap; 2359 noremap = save_m_noremap;
2394 else if ( 2360 else if (
2395 #ifdef FEAT_EVAL 2361 #ifdef FEAT_EVAL
2396 STRNCMP(map_str, save_m_keys != NULL 2362 STRNCMP(map_str, save_m_keys != NULL ? save_m_keys : mp->m_keys,
2397 ? save_m_keys : mp->m_keys, 2363 (size_t)keylen)
2398 (size_t)keylen)
2399 #else 2364 #else
2400 STRNCMP(map_str, mp->m_keys, (size_t)keylen) 2365 STRNCMP(map_str, mp->m_keys, (size_t)keylen)
2401 #endif 2366 #endif
2402 != 0) 2367 != 0)
2403 noremap = REMAP_YES; 2368 noremap = REMAP_YES;
2468 int c, c1; 2433 int c, c1;
2469 int timedout = FALSE; /* waited for more than 1 second 2434 int timedout = FALSE; /* waited for more than 1 second
2470 for mapping to complete */ 2435 for mapping to complete */
2471 int mapdepth = 0; /* check for recursive mapping */ 2436 int mapdepth = 0; /* check for recursive mapping */
2472 int mode_deleted = FALSE; /* set when mode has been deleted */ 2437 int mode_deleted = FALSE; /* set when mode has been deleted */
2473 int i;
2474 #ifdef FEAT_CMDL_INFO 2438 #ifdef FEAT_CMDL_INFO
2475 int new_wcol, new_wrow; 2439 int new_wcol, new_wrow;
2476 #endif 2440 #endif
2477 #ifdef FEAT_GUI 2441 #ifdef FEAT_GUI
2478 int shape_changed = FALSE; /* adjusted cursor shape */ 2442 int shape_changed = FALSE; /* adjusted cursor shape */
2539 */ 2503 */
2540 for (;;) 2504 for (;;)
2541 { 2505 {
2542 long wait_time; 2506 long wait_time;
2543 int keylen = 0; 2507 int keylen = 0;
2544 2508 #ifdef FEAT_CMDL_INFO
2509 int showcmd_idx;
2510 #endif
2545 /* 2511 /*
2546 * ui_breakcheck() is slow, don't use it too often when 2512 * ui_breakcheck() is slow, don't use it too often when
2547 * inside a mapping. But call it each time for typed 2513 * inside a mapping. But call it each time for typed
2548 * characters. 2514 * characters.
2549 */ 2515 */
2818 * If we have a partial match (and are going to wait for more 2784 * If we have a partial match (and are going to wait for more
2819 * input from the user), show the partially matched characters 2785 * input from the user), show the partially matched characters
2820 * to the user with showcmd. 2786 * to the user with showcmd.
2821 */ 2787 */
2822 #ifdef FEAT_CMDL_INFO 2788 #ifdef FEAT_CMDL_INFO
2823 i = 0; 2789 showcmd_idx = 0;
2824 #endif 2790 #endif
2825 c1 = 0; 2791 c1 = 0;
2826 if (typebuf.tb_len > 0 && advance && !exmode_active) 2792 if (typebuf.tb_len > 0 && advance && !exmode_active)
2827 { 2793 {
2828 if (((State & (NORMAL | INSERT)) || State == LANGMAP) 2794 if (((State & (NORMAL | INSERT)) || State == LANGMAP)
2844 old_wrow = curwin->w_wrow; 2810 old_wrow = curwin->w_wrow;
2845 curwin->w_wcol = new_wcol; 2811 curwin->w_wcol = new_wcol;
2846 curwin->w_wrow = new_wrow; 2812 curwin->w_wrow = new_wrow;
2847 push_showcmd(); 2813 push_showcmd();
2848 if (typebuf.tb_len > SHOWCMD_COLS) 2814 if (typebuf.tb_len > SHOWCMD_COLS)
2849 i = typebuf.tb_len - SHOWCMD_COLS; 2815 showcmd_idx = typebuf.tb_len - SHOWCMD_COLS;
2850 while (i < typebuf.tb_len) 2816 while (showcmd_idx < typebuf.tb_len)
2851 (void)add_to_showcmd(typebuf.tb_buf[typebuf.tb_off 2817 (void)add_to_showcmd(
2852 + i++]); 2818 typebuf.tb_buf[typebuf.tb_off + showcmd_idx++]);
2853 curwin->w_wcol = old_wcol; 2819 curwin->w_wcol = old_wcol;
2854 curwin->w_wrow = old_wrow; 2820 curwin->w_wrow = old_wrow;
2855 #endif 2821 #endif
2856 } 2822 }
2857 2823
2896 c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 2862 c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len,
2897 typebuf.tb_buflen - typebuf.tb_off - typebuf.tb_len - 1, 2863 typebuf.tb_buflen - typebuf.tb_off - typebuf.tb_len - 1,
2898 wait_time); 2864 wait_time);
2899 2865
2900 #ifdef FEAT_CMDL_INFO 2866 #ifdef FEAT_CMDL_INFO
2901 if (i != 0) 2867 if (showcmd_idx != 0)
2902 pop_showcmd(); 2868 pop_showcmd();
2903 #endif 2869 #endif
2904 if (c1 == 1) 2870 if (c1 == 1)
2905 { 2871 {
2906 if (State & INSERT) 2872 if (State & INSERT)