patch 9.0.1957: termcap options should change when setting keyprotocol

Commit: 
https://github.com/vim/vim/commit/3695d0e41ba26db074dd5680564a6f87d522fb61
Author: Gregory Anders <g...@gpanders.com>
Date:   Fri Sep 29 20:17:20 2023 +0200

    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 <c...@256bit.org>
    Co-authored-by: Gregory Anders <g...@gpanders.com>

diff --git a/src/optionstr.c b/src/optionstr.c
index 5fceb8573..9b4464d85 100644
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -1945,9 +1945,13 @@ did_set_keymodel(optset_T *args UNUSED)
     char *
 did_set_keyprotocol(optset_T *args UNUSED)
 {
-    if (match_keyprotocol(NULL) == KEYPROTOCOL_FAIL)
+    char_u *term = T_NAME;
+    keyprot_T kpc = match_keyprotocol(term);
+    if (kpc == KEYPROTOCOL_FAIL)
        return e_invalid_argument;
 
+    apply_keyprotocol(term, kpc);
+
     return NULL;
 }
 
diff --git a/src/proto/term.pro b/src/proto/term.pro
index 4150cbe00..e95befef5 100644
--- a/src/proto/term.pro
+++ b/src/proto/term.pro
@@ -5,6 +5,7 @@ void init_term_props(int all);
 void f_terminalprops(typval_T *argvars, typval_T *rettv);
 void set_color_count(int nr);
 keyprot_T match_keyprotocol(char_u *term);
+void apply_keyprotocol(char_u *term, keyprot_T prot);
 int set_termname(char_u *term);
 void free_cur_term(void);
 void getlinecol(long *cp, long *rp);
diff --git a/src/term.c b/src/term.c
index 2dbfdad7d..43f5fe5db 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1607,6 +1607,23 @@ apply_builtin_tcap(char_u *term, tcap_entry_T *entries, 
int overwrite)
     }
 }
 
+/*
+ * Apply builtin termcap entries for a given keyprotocol.
+ */
+    void
+apply_keyprotocol(char_u *term, keyprot_T prot)
+{
+    if (prot == KEYPROTOCOL_KITTY)
+       apply_builtin_tcap(term, builtin_kitty, TRUE);
+    if (prot == KEYPROTOCOL_MOK2)
+       apply_builtin_tcap(term, builtin_mok2, TRUE);
+
+    if (prot != KEYPROTOCOL_NONE)
+       // Some function keys may accept modifiers even though the
+       // terminfo/termcap entry does not indicate this.
+       accept_modifiers_for_function_keys();
+}
+
 /*
  * Parsing of the builtin termcap entries.
  * Caller should check if "term" is a valid builtin terminal name.
@@ -2083,10 +2100,7 @@ set_termname(char_u *term)
        // Use the 'keyprotocol' option to adjust the t_TE and t_TI
        // termcap entries if there is an entry matching "term".
        keyprot_T kpc = match_keyprotocol(term);
-       if (kpc == KEYPROTOCOL_KITTY)
-           apply_builtin_tcap(term, builtin_kitty, TRUE);
-       else if (kpc == KEYPROTOCOL_MOK2)
-           apply_builtin_tcap(term, builtin_mok2, TRUE);
+       apply_keyprotocol(term, kpc);
 
 #ifdef FEAT_TERMGUICOLORS
        // There is no good way to detect that the terminal supports RGB
@@ -2098,11 +2112,6 @@ set_termname(char_u *term)
                && term_strings_not_set(KS_8U))
            apply_builtin_tcap(term, builtin_rgb, TRUE);
 #endif
-
-       if (kpc != KEYPROTOCOL_NONE)
-           // Some function keys may accept modifiers even though the
-           // terminfo/termcap entry does not indicate this.
-           accept_modifiers_for_function_keys();
     }
 
 /*
diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim
index fc81cec4e..ccaefc584 100644
--- a/src/testdir/test_options.vim
+++ b/src/testdir/test_options.vim
@@ -1861,4 +1861,18 @@ func Test_binary_depending_options()
   call delete('Xoutput_bin')
 endfunc
 
+func Test_set_keyprotocol()
+  CheckNotGui
+
+  let term = &term
+  set term=ansi
+  call assert_equal('', &t_TI)
+
+  " Setting 'keyprotocol' should affect terminal codes without needing to
+  " reset 'term'
+  set keyprotocol+=ansi:kitty
+  call assert_equal("\<Esc>[=1;1u", &t_TI)
+  let &term = term
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 3165cef29..da027c5a1 100644
--- a/src/version.c
+++ b/src/version.c
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1957,
 /**/
     1956,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1qmIFY-00HXTt-TY%40256bit.org.

Raspunde prin e-mail lui