]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1679: unclear what key causes CmdlineLeave autocommand v9.1.1679
authorGirish Palya <girishji@gmail.com>
Sat, 23 Aug 2025 16:08:27 +0000 (18:08 +0200)
committerChristian Brabandt <cb@256bit.org>
Sat, 23 Aug 2025 16:08:27 +0000 (18:08 +0200)
Problem:  unclear what key causes CmdlineLeave autocommand
Solution: Set |v:char| to the key (Girish Palya).

related: #17806
closes: #18063

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/autocmd.txt
runtime/doc/eval.txt
runtime/doc/version9.txt
src/ex_getln.c
src/proto/cmdexpand.pro
src/testdir/test_cmdline.vim
src/version.c

index d11cb1f1851c02868c9949d3fcb8783fc9e5b2fb..f5ccae2147c1fcc0cb54fac8daf7081445212a1d 100644 (file)
@@ -1,4 +1,4 @@
-*autocmd.txt*   For Vim version 9.1.  Last change: 2025 Jun 19
+*autocmd.txt*   For Vim version 9.1.  Last change: 2025 Aug 23
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -644,6 +644,8 @@ CmdlineLeave                        Before leaving the command line; including
                                <afile> is set to a single character,
                                indicating the type of command-line.
                                |cmdwin-char|
+                               Sets the |v:char| to the key that exited the
+                               command-line (e.g. <CR>, <CTRL-C>, <Esc>).
                                                        *CmdlineLeavePre*
 CmdlineLeavePre                        Just before leaving the command line, and
                                before |CmdlineLeave|.  Useful for capturing
@@ -656,6 +658,7 @@ CmdlineLeavePre                     Just before leaving the command line, and
                                or <Esc>.  <afile> is set to a single
                                character indicating the command-line type.
                                See |cmdwin-char| for details.
+                               Sets |v:char| as with |CmdlineLeave|.
                                                        *CmdwinEnter*
 CmdwinEnter                    After entering the command-line window.
                                Useful for setting options specifically for
index 01ab14203e7883ac34a8ab8dbc373dbaaa785171..c13e3a0b79be1b34345fdb062690ced88beb0649 100644 (file)
@@ -2227,8 +2227,8 @@ v:beval_winid     The |window-ID| of the window, over which the mouse pointer
                                        *v:char* *char-variable*
 v:char         Argument for evaluating 'formatexpr' and used for the typed
                character when using <expr> in an abbreviation |:map-<expr>|.
-               It is also used by the |InsertCharPre|, |InsertEnter| and
-               |KeyInputPre| events.
+               It is also used by the |InsertCharPre|, |InsertEnter|,
+               |KeyInputPre|, |CmdlineLeave| and |CmdlineLeavePre| events.
 
                        *v:charconvert_from* *charconvert_from-variable*
 v:charconvert_from
index 1daf2f19120db808e1c7b764c91134086ab74864..b82071757702f25ee6d9ed6b6d13e080c79f266a 100644 (file)
@@ -41750,6 +41750,8 @@ Others: ~
   ANGLE BRACKET "]>".
 - Support for Unix domain sockets have been added for the clientserver
   feature, see |socketserver-clientserver|.
+- |CmdlineLeave| sets |v:char| to the character that caused exiting the
+  Command-line.
 
 Platform specific ~
 - MS-Winodws: Paths like "\Windows" and "/Windows" are now considered to be
index 3f5f852a449094fd046e3f2231e672823ebfcf4a..289231045c3d0d76a80ba44b72b9c684a9178a90 100644 (file)
@@ -1980,6 +1980,9 @@ getcmdline_int(
 #endif
                    || c == Ctrl_C))
        {
+#ifdef FEAT_EVAL
+           set_vim_var_char(c);  // Set v:char
+#endif
            trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVEPRE);
            event_cmdlineleavepre_triggered = TRUE;
 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
@@ -2646,7 +2649,12 @@ cmdline_changed:
 returncmd:
     // Trigger CmdlineLeavePre autocommands if not already triggered.
     if (!event_cmdlineleavepre_triggered)
+    {
+#ifdef FEAT_EVAL
+       set_vim_var_char(c);  // Set v:char
+#endif
        trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVEPRE);
+    }
 
 #ifdef FEAT_RIGHTLEFT
     cmdmsg_rl = FALSE;
@@ -2704,6 +2712,9 @@ returncmd:
        need_wait_return = FALSE;
 
     // Trigger CmdlineLeave autocommands.
+#ifdef FEAT_EVAL
+    set_vim_var_char(c);  // Set v:char
+#endif
     trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVE);
 
     State = save_State;
index a2f6a16d470976c1ff6f0d5f860427ea6fd3fd47..69e7da9be600351a244fc3d75c2078fad02c48c7 100644 (file)
@@ -25,5 +25,5 @@ int wildmenu_process_key(cmdline_info_T *cclp, int key, expand_T *xp);
 void wildmenu_cleanup(cmdline_info_T *cclp);
 void f_getcompletion(typval_T *argvars, typval_T *rettv);
 void f_getcompletiontype(typval_T *argvars, typval_T *rettv);
-void f_cmdcomplete_info(typval_T *argvars, typval_T *rettv);
+void f_cmdcomplete_info(typval_T *argvars UNUSED, typval_T *rettv);
 /* vim: set ft=c : */
index 2ae27da7fab21d362457d5b70ee3b9bf2315a472..3f8cb2d8fb2c55ae6dfe7229903e2e08cc942090 100644 (file)
@@ -4918,4 +4918,23 @@ func Test_long_line_noselect()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_CmdlineLeave_vchar_keys()
+  func OnLeave()
+    let g:leave_key = v:char
+  endfunction
+
+  new
+  for event in ["CmdlineLeavePre", "CmdlineLeave"]
+    exec "autocmd" event "* :call OnLeave()"
+    for key in ["\<C-C>", "\<Esc>", "\<CR>"]
+      call feedkeys($":echo{key}", 'tx')
+      call assert_equal(key, g:leave_key)
+    endfor
+    exec "autocmd!" event
+  endfor
+  bwipe!
+  delfunc OnLeave
+  unlet g:leave_key
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index a9f345547c4b7a2b5dec87efe20fd63163d9ce2d..98ecbc99a893e3e072429b0069f56a3a5c1e6720 100644 (file)
@@ -724,6 +724,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1679,
 /**/
     1678,
 /**/