Skip to content

Commit 3695d0e

Browse files
gpanderschrisbra
authored andcommitted
patch 9.0.1957: termcap options should change when setting keyprotocol
Problem: termcap options should change on keyprotocol setting Solution: Apply termcap entries when 'keyprotocol' changes When the 'keyprotocol' option was set after startup (including in a user's .vimrc) the termcap entries associated with the matching protocol were not applied. Thus, setting the option has no affect. When 'keyprotocol' is changed it should also update the termcap entries. closes: #13211 Signed-off-by: Christian Brabandt <[email protected]> Co-authored-by: Gregory Anders <[email protected]>
1 parent 28a2360 commit 3695d0e

5 files changed

Lines changed: 40 additions & 10 deletions

File tree

src/optionstr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,9 +1945,13 @@ did_set_keymodel(optset_T *args UNUSED)
19451945
char *
19461946
did_set_keyprotocol(optset_T *args UNUSED)
19471947
{
1948-
if (match_keyprotocol(NULL) == KEYPROTOCOL_FAIL)
1948+
char_u *term = T_NAME;
1949+
keyprot_T kpc = match_keyprotocol(term);
1950+
if (kpc == KEYPROTOCOL_FAIL)
19491951
return e_invalid_argument;
19501952

1953+
apply_keyprotocol(term, kpc);
1954+
19511955
return NULL;
19521956
}
19531957

src/proto/term.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ void init_term_props(int all);
55
void f_terminalprops(typval_T *argvars, typval_T *rettv);
66
void set_color_count(int nr);
77
keyprot_T match_keyprotocol(char_u *term);
8+
void apply_keyprotocol(char_u *term, keyprot_T prot);
89
int set_termname(char_u *term);
910
void free_cur_term(void);
1011
void getlinecol(long *cp, long *rp);

src/term.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,23 @@ apply_builtin_tcap(char_u *term, tcap_entry_T *entries, int overwrite)
16071607
}
16081608
}
16091609

1610+
/*
1611+
* Apply builtin termcap entries for a given keyprotocol.
1612+
*/
1613+
void
1614+
apply_keyprotocol(char_u *term, keyprot_T prot)
1615+
{
1616+
if (prot == KEYPROTOCOL_KITTY)
1617+
apply_builtin_tcap(term, builtin_kitty, TRUE);
1618+
if (prot == KEYPROTOCOL_MOK2)
1619+
apply_builtin_tcap(term, builtin_mok2, TRUE);
1620+
1621+
if (prot != KEYPROTOCOL_NONE)
1622+
// Some function keys may accept modifiers even though the
1623+
// terminfo/termcap entry does not indicate this.
1624+
accept_modifiers_for_function_keys();
1625+
}
1626+
16101627
/*
16111628
* Parsing of the builtin termcap entries.
16121629
* Caller should check if "term" is a valid builtin terminal name.
@@ -2083,10 +2100,7 @@ set_termname(char_u *term)
20832100
// Use the 'keyprotocol' option to adjust the t_TE and t_TI
20842101
// termcap entries if there is an entry matching "term".
20852102
keyprot_T kpc = match_keyprotocol(term);
2086-
if (kpc == KEYPROTOCOL_KITTY)
2087-
apply_builtin_tcap(term, builtin_kitty, TRUE);
2088-
else if (kpc == KEYPROTOCOL_MOK2)
2089-
apply_builtin_tcap(term, builtin_mok2, TRUE);
2103+
apply_keyprotocol(term, kpc);
20902104

20912105
#ifdef FEAT_TERMGUICOLORS
20922106
// There is no good way to detect that the terminal supports RGB
@@ -2098,11 +2112,6 @@ set_termname(char_u *term)
20982112
&& term_strings_not_set(KS_8U))
20992113
apply_builtin_tcap(term, builtin_rgb, TRUE);
21002114
#endif
2101-
2102-
if (kpc != KEYPROTOCOL_NONE)
2103-
// Some function keys may accept modifiers even though the
2104-
// terminfo/termcap entry does not indicate this.
2105-
accept_modifiers_for_function_keys();
21062115
}
21072116

21082117
/*

src/testdir/test_options.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,4 +1861,18 @@ func Test_binary_depending_options()
18611861
call delete('Xoutput_bin')
18621862
endfunc
18631863

1864+
func Test_set_keyprotocol()
1865+
CheckNotGui
1866+
1867+
let term = &term
1868+
set term=ansi
1869+
call assert_equal('', &t_TI)
1870+
1871+
" Setting 'keyprotocol' should affect terminal codes without needing to
1872+
" reset 'term'
1873+
set keyprotocol+=ansi:kitty
1874+
call assert_equal("\<Esc>[=1;1u", &t_TI)
1875+
let &term = term
1876+
endfunc
1877+
18641878
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

700700
static int included_patches[] =
701701
{ /* Add new patch number below this line */
702+
/**/
703+
1957,
702704
/**/
703705
1956,
704706
/**/

0 commit comments

Comments
 (0)