diff src/misc2.c @ 9869:989d44d35a66 v7.4.2209

commit https://github.com/vim/vim/commit/35a4cfa200917dd171b1fff3cd5b6cee9add673d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 14 16:07:48 2016 +0200 patch 7.4.2209 Problem: Cannot map <M-">. (Stephen Riehm) Solution: Solve the memory access problem in another way. (Dominique Pelle) Allow for using <M-\"> in a string.
author Christian Brabandt <cb@256bit.org>
date Sun, 14 Aug 2016 16:15:06 +0200
parents 80ac9cf77c9b
children 4aead6a9b7a9
line wrap: on
line diff
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -2674,13 +2674,14 @@ get_special_key_name(int c, int modifier
 trans_special(
     char_u	**srcp,
     char_u	*dst,
-    int		keycode) /* prefer key code, e.g. K_DEL instead of DEL */
+    int		keycode, /* prefer key code, e.g. K_DEL instead of DEL */
+    int		in_string) /* TRUE when inside a double quoted string */
 {
     int		modifiers = 0;
     int		key;
     int		dlen = 0;
 
-    key = find_special_key(srcp, &modifiers, keycode, FALSE);
+    key = find_special_key(srcp, &modifiers, keycode, FALSE, in_string);
     if (key == 0)
 	return 0;
 
@@ -2720,7 +2721,8 @@ find_special_key(
     char_u	**srcp,
     int		*modp,
     int		keycode,     /* prefer key code, e.g. K_DEL instead of DEL */
-    int		keep_x_key)  /* don't translate xHome to Home key */
+    int		keep_x_key,  /* don't translate xHome to Home key */
+    int		in_string)   /* TRUE in string, double quote is escaped */
 {
     char_u	*last_dash;
     char_u	*end_of_name;
@@ -2751,10 +2753,14 @@ find_special_key(
 		else
 #endif
 		    l = 1;
-		/* Anything accepted, like <C-?>, except <C-">, because the "
-		 * ends the string. */
-		if (bp[l] != '"' && bp[l + 1] == '>')
+		/* Anything accepted, like <C-?>.
+		 * <C-"> or <M-"> are not special in strings as " is
+		 * the string delimiter. With a backslash it works: <M-\"> */
+		if (!(in_string && bp[1] == '"') && bp[2] == '>')
 		    bp += l;
+		else if (in_string && bp[1] == '\\' && bp[2] == '"'
+							       && bp[3] == '>')
+		    bp += 2;
 	    }
 	}
 	if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3])
@@ -2798,20 +2804,22 @@ find_special_key(
 	    }
 	    else
 	    {
-		/*
-		 * Modifier with single letter, or special key name.
-		 */
+		int off = 1;
+
+		/* Modifier with single letter, or special key name.  */
+		if (in_string && last_dash[1] == '\\' && last_dash[2] == '"')
+		    off = 2;
 #ifdef FEAT_MBYTE
 		if (has_mbyte)
-		    l = mb_ptr2len(last_dash + 1);
+		    l = mb_ptr2len(last_dash + off);
 		else
 #endif
 		    l = 1;
-		if (modifiers != 0 && last_dash[l + 1] == '>')
-		    key = PTR2CHAR(last_dash + 1);
+		if (modifiers != 0 && last_dash[l + off] == '>')
+		    key = PTR2CHAR(last_dash + off);
 		else
 		{
-		    key = get_special_key_code(last_dash + 1);
+		    key = get_special_key_code(last_dash + off);
 		    if (!keep_x_key)
 			key = handle_x_keys(key);
 		}