Skip to content

Commit e353c40

Browse files
committed
patch 8.0.0302: cannot set terminal key codes with :let
Problem: Cannot set terminal key codes with :let. Solution: Make it work.
1 parent 698f8b2 commit e353c40

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

src/option.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9197,7 +9197,35 @@ get_option_value(
91979197

91989198
opt_idx = findoption(name);
91999199
if (opt_idx < 0) /* unknown option */
9200+
{
9201+
int key;
9202+
9203+
if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9204+
&& (key = find_key_option(name)) != 0)
9205+
{
9206+
char_u key_name[2];
9207+
char_u *p;
9208+
9209+
if (key < 0)
9210+
{
9211+
key_name[0] = KEY2TERMCAP0(key);
9212+
key_name[1] = KEY2TERMCAP1(key);
9213+
}
9214+
else
9215+
{
9216+
key_name[0] = KS_KEY;
9217+
key_name[1] = (key & 0xff);
9218+
}
9219+
p = find_termcode(key_name);
9220+
if (p != NULL)
9221+
{
9222+
if (stringval != NULL)
9223+
*stringval = vim_strsave(p);
9224+
return 0;
9225+
}
9226+
}
92009227
return -3;
9228+
}
92019229

92029230
varp = get_varp_scope(&(options[opt_idx]), opt_flags);
92039231

@@ -9455,7 +9483,33 @@ set_option_value(
94559483

94569484
opt_idx = findoption(name);
94579485
if (opt_idx < 0)
9486+
{
9487+
int key;
9488+
9489+
if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9490+
&& (key = find_key_option(name)) != 0)
9491+
{
9492+
char_u key_name[2];
9493+
9494+
if (key < 0)
9495+
{
9496+
key_name[0] = KEY2TERMCAP0(key);
9497+
key_name[1] = KEY2TERMCAP1(key);
9498+
}
9499+
else
9500+
{
9501+
key_name[0] = KS_KEY;
9502+
key_name[1] = (key & 0xff);
9503+
}
9504+
add_termcode(key_name, string, FALSE);
9505+
if (full_screen)
9506+
ttest(FALSE);
9507+
redraw_all_later(CLEAR);
9508+
return NULL;
9509+
}
9510+
94589511
EMSG2(_("E355: Unknown option: %s"), name);
9512+
}
94599513
else
94609514
{
94619515
flags = options[opt_idx].flags;

src/testdir/test_assign.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,23 @@ func Test_no_type_checking()
77
let v = 3.4
88
let v = 'hello'
99
endfunc
10+
11+
func Test_let_termcap()
12+
" Terminal code
13+
let old_t_te = &t_te
14+
let &t_te = "\<Esc>[yes;"
15+
call assert_match('t_te.*^[[yes;', execute("set termcap"))
16+
let &t_te = old_t_te
17+
18+
" Key code
19+
let old_t_k1 = &t_k1
20+
let &t_k1 = "that"
21+
call assert_match('t_k1.*that', execute("set termcap"))
22+
let &t_k1 = old_t_k1
23+
24+
call assert_fails('let x = &t_xx', 'E15')
25+
let &t_xx = "yes"
26+
call assert_equal("yes", &t_xx)
27+
let &t_xx = ""
28+
call assert_fails('let x = &t_xx', 'E15')
29+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
302,
767769
/**/
768770
301,
769771
/**/

0 commit comments

Comments
 (0)