]> granicus.if.org Git - vim/commitdiff
patch 7.4.2209 v7.4.2209
authorBram Moolenaar <Bram@vim.org>
Sun, 14 Aug 2016 14:07:48 +0000 (16:07 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 14 Aug 2016 14:07:48 +0000 (16:07 +0200)
Problem:    Cannot map <M-">. (Stephen Riehm)
Solution:   Solve the memory access problem in another way. (Dominique Pelle)
            Allow for using <M-\"> in a string.

src/eval.c
src/gui_mac.c
src/misc2.c
src/option.c
src/proto/misc2.pro
src/syntax.c
src/term.c
src/testdir/test_mapping.vim
src/version.c

index 45b8f07c389c670f835b64ed1234f588d63c49ff..2ab3ee4b90fd00f6bf815042aec15d1096a3d5c5 100644 (file)
@@ -233,8 +233,6 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate);
 static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate);
 static int free_unref_items(int copyID);
 static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate);
-
-
 static int get_env_len(char_u **arg);
 static char_u * make_expanded_name(char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end);
 static void check_vars(char_u *name, int len);
@@ -4926,7 +4924,7 @@ get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
                          break;
 
                            /* Special key, e.g.: "\<C-W>" */
-               case '<': extra = trans_special(&p, name, TRUE);
+               case '<': extra = trans_special(&p, name, TRUE, TRUE);
                          if (extra != 0)
                          {
                              name += extra;
@@ -4943,6 +4941,11 @@ get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
 
     }
     *name = NUL;
+    if (p == NUL)
+    {
+       EMSG2(_("E114: Missing quote: %s"), *arg);
+       return FAIL;
+    }
     *arg = p + 1;
 
     return OK;
index b78c903bea1e498515e0a409a36e3a969d10817a..d750b3b1b6683031164ab539531c4d5ab1b6171f 100644 (file)
@@ -4830,7 +4830,7 @@ gui_mch_add_menu_item(vimmenu_T *menu, int idx)
        char_u      *p_actext;
 
        p_actext = menu->actext;
-       key = find_special_key(&p_actext, &modifiers, FALSE, FALSE);
+       key = find_special_key(&p_actext, &modifiers, FALSE, FALSE, FALSE);
        if (*p_actext != 0)
            key = 0; /* error: trailing text */
        /* find_special_key() returns a keycode with as many of the
index f44c33cea225931d06b809be6db31f3006619baa..00c01f463f0a21dbcca49e56ba6a60037240d08b 100644 (file)
@@ -2674,13 +2674,14 @@ get_special_key_name(int c, int modifiers)
 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);
                }
index d1a25339bececa6a4b127382a62f92220dac9f43..f417e9c177c2245b566f7a9de000df28e71a5b9d 100644 (file)
@@ -9478,7 +9478,7 @@ find_key_option(char_u *arg)
     {
        --arg;                      /* put arg at the '<' */
        modifiers = 0;
-       key = find_special_key(&arg, &modifiers, TRUE, TRUE);
+       key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
        if (modifiers)              /* can't handle modifiers here */
            key = 0;
     }
index 573dee559e2caf09fb4cabbee6aff7b4392bbb2b..70c7dae5b6bb259dfae24cab905ff3ff9736da46 100644 (file)
@@ -64,8 +64,8 @@ int name_to_mod_mask(int c);
 int simplify_key(int key, int *modifiers);
 int handle_x_keys(int key);
 char_u *get_special_key_name(int c, int modifiers);
-int trans_special(char_u **srcp, char_u *dst, int keycode);
-int find_special_key(char_u **srcp, int *modp, int keycode, int keep_x_key);
+int trans_special(char_u **srcp, char_u *dst, int keycode, int in_string);
+int find_special_key(char_u **srcp, int *modp, int keycode, int keep_x_key, int in_string);
 int extract_modifiers(int key, int *modp);
 int find_special_key_in_table(int c);
 int get_special_key_code(char_u *name);
index 0face62b7f6711e487386d565328bf85a637e493..19f9bc4686b9a9b4ada5d0cfccbb7bbe3e6726b0 100644 (file)
@@ -7939,7 +7939,7 @@ do_highlight(
                 */
                for (p = arg, off = 0; off < 100 - 6 && *p; )
                {
-                   len = trans_special(&p, buf + off, FALSE);
+                   len = trans_special(&p, buf + off, FALSE, FALSE);
                    if (len > 0)            /* recognized special char */
                        off += len;
                    else                    /* copy as normal char */
index 344fabc354ba79d1d44fdead678d88d7eebdf73b..774ef655270082ddf1135ebb8684cdbd6cfd8ec1 100644 (file)
@@ -5429,7 +5429,7 @@ replace_termcodes(
            }
 #endif
 
-           slen = trans_special(&src, result + dlen, TRUE);
+           slen = trans_special(&src, result + dlen, TRUE, FALSE);
            if (slen)
            {
                dlen += slen;
index d937565ce5971ca0fe04c01712df653ee61b2738..a1281eb4d36ad87cecd146e64fd85ed30b6fecbc 100644 (file)
@@ -98,3 +98,11 @@ func Test_break_undo()
   call assert_equal('new line here', getline(line('$') - 1))
   set nomodified
 endfunc
+
+func Test_map_meta_quotes()
+  imap <M-"> foo
+  call feedkeys("Go-\<M-\">-\<Esc>", "xt")
+  call assert_equal("-foo-", getline('$'))
+  set nomodified
+  iunmap <M-">
+endfunc
index 0f0aabc4c968673ec7473fc397c12e46a4f79862..cd3a52883ac04dbdf36760940bf5783c9edd28d8 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2209,
 /**/
     2208,
 /**/