]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0029: Cannot act on various terminal response codes v9.1.0029
authorDanek Duvall <duvall@comfychair.org>
Sun, 14 Jan 2024 19:19:59 +0000 (20:19 +0100)
committerChristian Brabandt <cb@256bit.org>
Sun, 14 Jan 2024 19:19:59 +0000 (20:19 +0100)
Problem:  Cannot act on various terminal response codes
Solution: Add the TerminalResponseAll autocommand
          (Danek Duvall)

closes: #13829

Signed-off-by: Danek Duvall <duvall@comfychair.org>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/autocmd.txt
runtime/doc/eval.txt
runtime/doc/tags
runtime/doc/todo.txt
runtime/syntax/vim.vim
src/autocmd.c
src/term.c
src/version.c
src/vim.h

index 2ac0247bb0c51ec05581f9f812d521c053fe9d10..0ace7b1dae892b2de979c74e4d81250715144af9 100644 (file)
@@ -1,4 +1,4 @@
-*autocmd.txt*   For Vim version 9.1.  Last change: 2023 May 20
+*autocmd.txt*   For Vim version 9.1.  Last change: 2024 Jan 14
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -340,6 +340,7 @@ Name                        triggered by ~
 |GUIEnter|             after starting the GUI successfully
 |GUIFailed|            after starting the GUI failed
 |TermResponse|         after the terminal response to |t_RV| is received
+|TermResponseAll|      after the terminal response to |t_RV| and others is received
 
 |QuitPre|              when using `:quit`, before deciding whether to exit
 |ExitPre|              when using a command that may make Vim exit
@@ -1220,6 +1221,24 @@ TermResponse                     After the response to |t_RV| is received from
                                triggered halfway executing another event,
                                especially if file I/O, a shell command or
                                anything else that takes time is involved.
+                                                       *TermResponseAll*
+TermResponseAll                        After the response to |t_RV|, |t_RC|, |t_RS|,
+                               |t_RB|, |t_RF|, or |t_u7| are received from
+                               the terminal.  The value of |v:termresponse|,
+                               |v:termblinkresp|, |v:termstyleresp|,
+                               |v:termrbgresp|, |v:termrfgresp|, and
+                               |v:termu7resp|, correspondingly, can be used.
+                               <amatch> will be set to any of:
+                                   "version",
+                                   "cursorblink",
+                                   "cursorshape",
+                                   "background",
+                                   "foreground",
+                                   "ambiguouswidth"
+                               Note that this event may be triggered halfway
+                               executing another event, especially if file I/O,
+                               a shell command or anything else that takes time
+                               is involved.
                                                        *TextChanged*
 TextChanged                    After a change was made to the text in the
                                current buffer in Normal mode.  That is after
index d52f7fe169ee72ca6641e413c950c846cb649e93..9c12fb8504b0fc86690fcbcb2ffeec51db4dc734 100644 (file)
@@ -1,4 +1,4 @@
-*eval.txt*     For Vim version 9.1.  Last change: 2023 Dec 09
+*eval.txt*     For Vim version 9.1.  Last change: 2024 Jan 14
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -2568,8 +2568,9 @@ v:termresponse    The escape sequence returned by the terminal for the |t_RV|
                'c', with only digits and ';' in between.
                When this option is set, the TermResponse autocommand event is
                fired, so that you can react to the response from the
-               terminal.  You can use |terminalprops()| to see what Vim
-               figured out about the terminal.
+               terminal.  The TermResponseAll event is also fired, with
+               <amatch> set to "version".  You can use |terminalprops()| to see
+               what Vim figured out about the terminal.
                The response from a new xterm is: "<Esc>[> Pp ; Pv ; Pc c".  Pp
                is the terminal type: 0 for vt100 and 1 for vt220.  Pv is the
                patch level (since this was introduced in patch 95, it's
@@ -2581,27 +2582,37 @@ v:termresponse  The escape sequence returned by the terminal for the |t_RV|
                                                *v:termblinkresp*
 v:termblinkresp        The escape sequence returned by the terminal for the |t_RC|
                termcap entry.  This is used to find out whether the terminal
-               cursor is blinking. This is used by |term_getcursor()|.
+               cursor is blinking. This is used by |term_getcursor()|.  When
+               this option is set, the TermResponseAll autocommand event is
+               fired, with <amatch> set to "cursorblink".
 
                                                *v:termstyleresp*
 v:termstyleresp        The escape sequence returned by the terminal for the |t_RS|
                termcap entry.  This is used to find out what the shape of the
-               cursor is.  This is used by |term_getcursor()|.
+               cursor is.  This is used by |term_getcursor()|.  When this
+               option is set, the TermResponseAll autocommand event is fired,
+               with <amatch> set to "cursorshape".
 
                                                *v:termrbgresp*
 v:termrbgresp  The escape sequence returned by the terminal for the |t_RB|
                termcap entry.  This is used to find out what the terminal
-               background color is, see 'background'.
+               background color is; see 'background'.  When this option is
+               set, the TermResponseAll autocommand event is fired, with
+               <amatch> set to "background".
 
                                                *v:termrfgresp*
 v:termrfgresp  The escape sequence returned by the terminal for the |t_RF|
                termcap entry.  This is used to find out what the terminal
-               foreground color is.
+               foreground color is.  When this option is set, the
+               TermResponseAll autocommand event is fired, with <amatch> set
+               to "foreground".
 
                                                *v:termu7resp*
 v:termu7resp   The escape sequence returned by the terminal for the |t_u7|
                termcap entry.  This is used to find out what the terminal
-               does with ambiguous width characters, see 'ambiwidth'.
+               does with ambiguous width characters, see 'ambiwidth'.  When
+               this option is set, the TermResponseAll autocommand event is
+               fired, with <amatch> set to "ambiguouswidth".
 
                                        *v:testing* *testing-variable*
 v:testing      Must be set before using `test_garbagecollect_now()`.
index caa76bcc47e06c62078919139ca4f2d2b6bfae0a..88518600f615d9f5fe4ff6946e172be6a25675b6 100644 (file)
@@ -5706,6 +5706,7 @@ TabNew    autocmd.txt     /*TabNew*
 Tcl    if_tcl.txt      /*Tcl*
 TermChanged    autocmd.txt     /*TermChanged*
 TermResponse   autocmd.txt     /*TermResponse*
+TermResponseAll        autocmd.txt     /*TermResponseAll*
 TermdebugStartPost     terminal.txt    /*TermdebugStartPost*
 TermdebugStartPre      terminal.txt    /*TermdebugStartPre*
 TermdebugStopPost      terminal.txt    /*TermdebugStopPost*
index 746488ecc41954584b4f2903d1257ec0c44d6d3f..c29ac2e2c050a02f0b73bb100bf6e27d8f5361d4 100644 (file)
@@ -1,4 +1,4 @@
-*todo.txt*      For Vim version 9.1.  Last change: 2023 Dec 14
+*todo.txt*      For Vim version 9.1.  Last change: 2024 Jan 14
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1121,9 +1121,6 @@ When t_Co is changed from termresponse, the OptionSet autocommand event isn't
 triggered.  Use the code from the end of set_num_option() in
 set_color_count().
 
-Add another autocommand like TermResponse that is fired for the other terminal
-responses, such as bg and fg.  Use "bg", "fg", "blink", etc. for the name.
-
 When using command line window, CmdlineLeave is triggered without
 CmdlineEnter.  (xtal8, 2017 Oct 30, #2263)
 Add some way to get the nested state.  Although CmdwinEnter is obviously
index 165a809596cdcc7ce1ee00f83cf65821f86725e1..12e6f34741ad63e2438ae1781b0437992f6319f4 100644 (file)
@@ -8,6 +8,7 @@
 "      2023 Dec 10 by Vim Project (improve variable matching)
 "      2023 Dec 21 by Vim Project (improve ex command matching)
 "      2023 Dec 30 by Vim Project (:syntax improvements)
+"      2024 Jan 14 by Vim Project (TermResponseAll autocommand)
 " Version:     9.0-25
 " URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_VIM
 " Automatically generated keyword lists: {{{1
@@ -73,7 +74,7 @@ syn keyword vimErrSetting contained   bioskey biosk conskey consk autoprint beauti
 
 " AutoCmd Events {{{2
 syn case ignore
-syn keyword vimAutoEvent contained     BufAdd BufDelete BufFilePost BufHidden BufNew BufRead BufReadPost BufUnload BufWinLeave BufWrite BufWritePost CmdlineChanged CmdlineLeave CmdwinEnter ColorScheme CompleteChanged CompleteDonePre CursorHoldI CursorMovedI DiffUpdated DirChanged DirChangedPre EncodingChanged ExitPre FileAppendCmd FileAppendPost FileAppendPre FileChangedRO FileChangedShell FileChangedShellPost FileEncoding FileExplorer FileReadCmd FileReadPost FileReadPre FileType FileWriteCmd FileWritePost FileWritePre FilterReadPost FilterReadPre FilterWritePost FilterWritePre FocusGained FocusLost FuncUndefined GUIEnter GUIFailed InsertChange InsertCharPre InsertEnter InsertLeave InsertLeavePre MenuPopup ModeChanged OptionSet QuickFixCmdPost QuickFixCmdPre QuitPre RemoteReply SafeState SafeStateAgain SessionLoadPost ShellCmdPost ShellFilterPost SigUSR1 SourceCmd SourcePost SourcePre SpellFileMissing StdinReadPost StdinReadPre SwapExists Syntax TabClosed TabEnter TabLeave TabNew TermChanged TerminalOpen TerminalWinOpen TermResponse TextChanged TextChangedI TextChangedP TextChangedT TextYankPost User VimEnter VimLeave VimLeavePre VimResized VimResume VimSuspend WinClosed WinEnter WinLeave WinNew WinResized WinScrolled
+syn keyword vimAutoEvent contained     BufAdd BufDelete BufFilePost BufHidden BufNew BufRead BufReadPost BufUnload BufWinLeave BufWrite BufWritePost CmdlineChanged CmdlineLeave CmdwinEnter ColorScheme CompleteChanged CompleteDonePre CursorHoldI CursorMovedI DiffUpdated DirChanged DirChangedPre EncodingChanged ExitPre FileAppendCmd FileAppendPost FileAppendPre FileChangedRO FileChangedShell FileChangedShellPost FileEncoding FileExplorer FileReadCmd FileReadPost FileReadPre FileType FileWriteCmd FileWritePost FileWritePre FilterReadPost FilterReadPre FilterWritePost FilterWritePre FocusGained FocusLost FuncUndefined GUIEnter GUIFailed InsertChange InsertCharPre InsertEnter InsertLeave InsertLeavePre MenuPopup ModeChanged OptionSet QuickFixCmdPost QuickFixCmdPre QuitPre RemoteReply SafeState SafeStateAgain SessionLoadPost ShellCmdPost ShellFilterPost SigUSR1 SourceCmd SourcePost SourcePre SpellFileMissing StdinReadPost StdinReadPre SwapExists Syntax TabClosed TabEnter TabLeave TabNew TermChanged TerminalOpen TerminalWinOpen TermResponse TermResponseAll TextChanged TextChangedI TextChangedP TextChangedT TextYankPost User VimEnter VimLeave VimLeavePre VimResized VimResume VimSuspend WinClosed WinEnter WinLeave WinNew WinResized WinScrolled
 syn keyword vimAutoEvent contained     BufCreate BufEnter BufFilePre BufLeave BufNewFile BufReadCmd BufReadPre BufWinEnter BufWipeout BufWriteCmd BufWritePre CmdlineEnter CmdUndefined CmdwinLeave ColorSchemePre CompleteDone CursorHold CursorMoved
 
 " Highlight commonly used Groupnames {{{2
index a78e78b02437301363aef77a4764cdfde309c69a..8b8f109ea097613dda7600ab8ebd670d4db5d7bf 100644 (file)
@@ -179,6 +179,7 @@ static struct event_name
     {"TerminalOpen",   EVENT_TERMINALOPEN},
     {"TerminalWinOpen", EVENT_TERMINALWINOPEN},
     {"TermResponse",   EVENT_TERMRESPONSE},
+    {"TermResponseAll",        EVENT_TERMRESPONSEALL},
     {"TextChanged",    EVENT_TEXTCHANGED},
     {"TextChangedI",   EVENT_TEXTCHANGEDI},
     {"TextChangedP",   EVENT_TEXTCHANGEDP},
@@ -2100,7 +2101,8 @@ apply_autocmds_group(
     {
        if (event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE
                                                 || event == EVENT_OPTIONSET
-                                                || event == EVENT_MODECHANGED)
+                                                || event == EVENT_MODECHANGED
+                                                || event == EVENT_TERMRESPONSEALL)
            autocmd_fname = NULL;
        else if (fname != NULL && !ends_excmd(*fname))
            autocmd_fname = fname;
@@ -2180,7 +2182,8 @@ apply_autocmds_group(
                || event == EVENT_USER
                || event == EVENT_WINCLOSED
                || event == EVENT_WINRESIZED
-               || event == EVENT_WINSCROLLED)
+               || event == EVENT_WINSCROLLED
+               || event == EVENT_TERMRESPONSEALL)
        {
            fname = vim_strsave(fname);
            autocmd_fname_full = TRUE; // don't expand it later
@@ -2418,6 +2421,11 @@ BYPASS_AU:
 
 # ifdef FEAT_EVAL
 static char_u  *old_termresponse = NULL;
+static char_u  *old_termu7resp = NULL;
+static char_u  *old_termblinkresp = NULL;
+static char_u  *old_termrbgresp = NULL;
+static char_u  *old_termrfgresp = NULL;
+static char_u  *old_termstyleresp = NULL;
 # endif
 
 /*
@@ -2430,7 +2438,14 @@ block_autocmds(void)
 # ifdef FEAT_EVAL
     // Remember the value of v:termresponse.
     if (autocmd_blocked == 0)
+    {
        old_termresponse = get_vim_var_str(VV_TERMRESPONSE);
+       old_termu7resp = get_vim_var_str(VV_TERMU7RESP);
+       old_termblinkresp = get_vim_var_str(VV_TERMBLINKRESP);
+       old_termrbgresp = get_vim_var_str(VV_TERMRBGRESP);
+       old_termrfgresp = get_vim_var_str(VV_TERMRFGRESP);
+       old_termstyleresp = get_vim_var_str(VV_TERMSTYLERESP);
+    }
 # endif
     ++autocmd_blocked;
 }
@@ -2441,12 +2456,37 @@ unblock_autocmds(void)
     --autocmd_blocked;
 
 # ifdef FEAT_EVAL
-    // When v:termresponse was set while autocommands were blocked, trigger
-    // the autocommands now.  Esp. useful when executing a shell command
-    // during startup (vimdiff).
-    if (autocmd_blocked == 0
-                     && get_vim_var_str(VV_TERMRESPONSE) != old_termresponse)
-       apply_autocmds(EVENT_TERMRESPONSE, NULL, NULL, FALSE, curbuf);
+    // When v:termresponse, etc, were set while autocommands were blocked,
+    // trigger the autocommands now.  Esp. useful when executing a shell
+    // command during startup (vimdiff).
+    if (autocmd_blocked == 0)
+    {
+       if (get_vim_var_str(VV_TERMRESPONSE) != old_termresponse)
+       {
+           apply_autocmds(EVENT_TERMRESPONSE, NULL, NULL, FALSE, curbuf);
+           apply_autocmds(EVENT_TERMRESPONSEALL, (char_u *)"version", NULL, FALSE, curbuf);
+       }
+       if (get_vim_var_str(VV_TERMU7RESP) != old_termu7resp)
+       {
+           apply_autocmds(EVENT_TERMRESPONSEALL, (char_u *)"ambiguouswidth", NULL, FALSE, curbuf);
+       }
+       if (get_vim_var_str(VV_TERMBLINKRESP) != old_termblinkresp)
+       {
+           apply_autocmds(EVENT_TERMRESPONSEALL, (char_u *)"cursorblink", NULL, FALSE, curbuf);
+       }
+       if (get_vim_var_str(VV_TERMRBGRESP) != old_termrbgresp)
+       {
+           apply_autocmds(EVENT_TERMRESPONSEALL, (char_u *)"background", NULL, FALSE, curbuf);
+       }
+       if (get_vim_var_str(VV_TERMRFGRESP) != old_termrfgresp)
+       {
+           apply_autocmds(EVENT_TERMRESPONSEALL, (char_u *)"foreground", NULL, FALSE, curbuf);
+       }
+       if (get_vim_var_str(VV_TERMSTYLERESP) != old_termstyleresp)
+       {
+           apply_autocmds(EVENT_TERMRESPONSEALL, (char_u *)"cursorshape", NULL, FALSE, curbuf);
+       }
+    }
 # endif
 }
 
index dd59fdf65dc179a60fa68300b39d214e4a9732d1..734b759e30b480cbc4aa5183c22b7880d4b37b1e 100644 (file)
@@ -4986,6 +4986,8 @@ handle_u7_response(int *arg, char_u *tp UNUSED, int csi_len UNUSED)
 #ifdef FEAT_EVAL
            set_vim_var_string(VV_TERMU7RESP, tp, csi_len);
 #endif
+           apply_autocmds(EVENT_TERMRESPONSEALL,
+                                       (char_u *)"ambiguouswidth", NULL, FALSE, curbuf);
        }
     }
     else if (arg[0] == 3)
@@ -5595,6 +5597,8 @@ handle_csi(
 #endif
        apply_autocmds(EVENT_TERMRESPONSE,
                                        NULL, NULL, FALSE, curbuf);
+       apply_autocmds(EVENT_TERMRESPONSEALL,
+                                       (char_u *)"version", NULL, FALSE, curbuf);
        key_name[0] = (int)KS_EXTRA;
        key_name[1] = (int)KE_IGNORE;
     }
@@ -5621,6 +5625,8 @@ handle_csi(
 # ifdef FEAT_EVAL
        set_vim_var_string(VV_TERMBLINKRESP, tp, *slen);
 # endif
+       apply_autocmds(EVENT_TERMRESPONSEALL,
+                                       (char_u *)"cursorblink", NULL, FALSE, curbuf);
     }
 #endif
 
@@ -5784,6 +5790,8 @@ handle_osc(char_u *tp, char_u *argp, int len, char_u *key_name, int *slen)
                set_vim_var_string(is_bg ? VV_TERMRBGRESP
                                                  : VV_TERMRFGRESP, tp, *slen);
 #endif
+               apply_autocmds(EVENT_TERMRESPONSEALL,
+                           is_bg ? (char_u *)"background" : (char_u *)"foreground", NULL, FALSE, curbuf);
                break;
            }
     if (i == len)
@@ -5882,6 +5890,8 @@ handle_dcs(char_u *tp, char_u *argp, int len, char_u *key_name, int *slen)
 #ifdef FEAT_EVAL
                set_vim_var_string(VV_TERMSTYLERESP, tp, *slen);
 #endif
+               apply_autocmds(EVENT_TERMRESPONSEALL,
+                                       (char_u *)"cursorshape", NULL, FALSE, curbuf);
                break;
            }
        }
index f01cac8b7c9413a120b088f17e6f8a2ebd9e9bcf..b44385a0d5dba853a5b71ffe1239c9887f366b55 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    29,
 /**/
     28,
 /**/
index e41dfef01bae8a2d1abd7dcbe37c8965ce955012..0f52ba217dcae352f6116ea2b05d234d9caa47ec 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1422,6 +1422,7 @@ enum auto_event
     EVENT_TERMINALWINOPEN,     // after a terminal buffer was created and
                                // entering its window
     EVENT_TERMRESPONSE,                // after setting "v:termresponse"
+    EVENT_TERMRESPONSEALL,     // after setting terminal response vars
     EVENT_TEXTCHANGED,         // text was modified not in Insert mode
     EVENT_TEXTCHANGEDI,                // text was modified in Insert mode
     EVENT_TEXTCHANGEDP,                // TextChangedI with popup menu visible