]> granicus.if.org Git - vim/commitdiff
patch 8.0.0302: cannot set terminal key codes with :let v8.0.0302
authorBram Moolenaar <Bram@vim.org>
Sat, 4 Feb 2017 18:49:16 +0000 (19:49 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 4 Feb 2017 18:49:16 +0000 (19:49 +0100)
Problem:    Cannot set terminal key codes with :let.
Solution:   Make it work.

src/option.c
src/testdir/test_assign.vim
src/version.c

index b90d5fdfa22be2480902a9928e574f0aee3987eb..1237d048bac1c55352e0a55f846f1ae02a8e3364 100644 (file)
@@ -9197,7 +9197,35 @@ get_option_value(
 
     opt_idx = findoption(name);
     if (opt_idx < 0)               /* unknown option */
+    {
+       int key;
+
+       if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
+               && (key = find_key_option(name)) != 0)
+       {
+           char_u key_name[2];
+           char_u *p;
+
+           if (key < 0)
+           {
+               key_name[0] = KEY2TERMCAP0(key);
+               key_name[1] = KEY2TERMCAP1(key);
+           }
+           else
+           {
+               key_name[0] = KS_KEY;
+               key_name[1] = (key & 0xff);
+           }
+           p = find_termcode(key_name);
+           if (p != NULL)
+           {
+               if (stringval != NULL)
+                   *stringval = vim_strsave(p);
+               return 0;
+           }
+       }
        return -3;
+    }
 
     varp = get_varp_scope(&(options[opt_idx]), opt_flags);
 
@@ -9455,7 +9483,33 @@ set_option_value(
 
     opt_idx = findoption(name);
     if (opt_idx < 0)
+    {
+       int key;
+
+       if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
+               && (key = find_key_option(name)) != 0)
+       {
+           char_u key_name[2];
+
+           if (key < 0)
+           {
+               key_name[0] = KEY2TERMCAP0(key);
+               key_name[1] = KEY2TERMCAP1(key);
+           }
+           else
+           {
+               key_name[0] = KS_KEY;
+               key_name[1] = (key & 0xff);
+           }
+           add_termcode(key_name, string, FALSE);
+           if (full_screen)
+               ttest(FALSE);
+           redraw_all_later(CLEAR);
+           return NULL;
+       }
+
        EMSG2(_("E355: Unknown option: %s"), name);
+    }
     else
     {
        flags = options[opt_idx].flags;
index c1f036a0f2245c0d0f703ac00f74a2ea97329da6..22aa4a1d319de3d2ae6da1eb19dab89caa01958b 100644 (file)
@@ -7,3 +7,23 @@ func Test_no_type_checking()
   let v = 3.4
   let v = 'hello'
 endfunc
+
+func Test_let_termcap()
+  " Terminal code
+  let old_t_te = &t_te
+  let &t_te = "\<Esc>[yes;"
+  call assert_match('t_te.*^[[yes;', execute("set termcap"))
+  let &t_te = old_t_te
+
+  " Key code
+  let old_t_k1 = &t_k1
+  let &t_k1 = "that"
+  call assert_match('t_k1.*that', execute("set termcap"))
+  let &t_k1 = old_t_k1
+
+  call assert_fails('let x = &t_xx', 'E15')
+  let &t_xx = "yes"
+  call assert_equal("yes", &t_xx)
+  let &t_xx = ""
+  call assert_fails('let x = &t_xx', 'E15')
+endfunc
index ffb7c6cb78c273f220c3c0455039a8cbf70bb32e..34add35ecc38bdea403881ef6a0b1a5111deb1db 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    302,
 /**/
     301,
 /**/