Patch 9.0.1039
Problem:    Using a <Cmd> mapping CmdlineChanged may be triggered twice.
Solution:   Count the number of times CmdlineChanged is triggered and avoid
            doing it twice. (closes #116820
Files:      src/autocmd.c, src/globals.h, src/ex_getln.c,
            src/testdir/test_autocmd.vim


*** ../vim-9.0.1038/src/autocmd.c       2022-11-28 20:34:47.704140309 +0000
--- src/autocmd.c       2022-12-09 12:06:53.572492586 +0000
***************
*** 2068,2073 ****
--- 2068,2076 ----
                && (event == EVENT_WINLEAVE || event == EVENT_BUFLEAVE)))
        goto BYPASS_AU;
  
+     if (event == EVENT_CMDLINECHANGED)
+       ++aucmd_cmdline_changed_count;
+ 
      /*
       * Save the autocmd_* variables and info about the current buffer.
       */
***************
*** 2088,2095 ****
      if (fname_io == NULL)
      {
        if (event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE
!                                                  || event == EVENT_OPTIONSET
!                                                  || event == 
EVENT_MODECHANGED)
            autocmd_fname = NULL;
        else if (fname != NULL && !ends_excmd(*fname))
            autocmd_fname = fname;
--- 2091,2098 ----
      if (fname_io == NULL)
      {
        if (event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE
!                                                || event == EVENT_OPTIONSET
!                                                || event == EVENT_MODECHANGED)
            autocmd_fname = NULL;
        else if (fname != NULL && !ends_excmd(*fname))
            autocmd_fname = fname;
*** ../vim-9.0.1038/src/globals.h       2022-11-30 20:20:52.751228273 +0000
--- src/globals.h       2022-12-09 12:09:25.412660166 +0000
***************
*** 1582,1591 ****
--- 1582,1594 ----
  EXTERN char_u *last_cmdline INIT(= NULL); // last command line (for ":)
  EXTERN char_u *repeat_cmdline INIT(= NULL); // command line for "."
  EXTERN char_u *new_last_cmdline INIT(= NULL); // new value for last_cmdline
+                                               //
  EXTERN char_u *autocmd_fname INIT(= NULL); // fname for <afile> on cmdline
  EXTERN int    autocmd_fname_full;          // autocmd_fname is full path
  EXTERN int    autocmd_bufnr INIT(= 0);     // fnum for <abuf> on cmdline
  EXTERN char_u *autocmd_match INIT(= NULL); // name for <amatch> on cmdline
+ EXTERN int    aucmd_cmdline_changed_count INIT(= 0);
+ 
  EXTERN int    did_cursorhold INIT(= FALSE); // set when CursorHold t'gerd
  EXTERN pos_T  last_cursormoved              // for CursorMoved event
  # ifdef DO_INIT
*** ../vim-9.0.1038/src/ex_getln.c      2022-12-09 11:36:33.172960075 +0000
--- src/ex_getln.c      2022-12-09 12:20:54.829390662 +0000
***************
*** 1785,1795 ****
  
        if (c == K_COMMAND || c == K_SCRIPT_COMMAND)
        {
!           int     clen = ccline.cmdlen;
  
            if (do_cmdkey_command(c, DOCMD_NOWAIT) == OK)
            {
!               if (clen == ccline.cmdlen)
                    trigger_cmdlinechanged = FALSE;
                goto cmdline_changed;
            }
--- 1785,1797 ----
  
        if (c == K_COMMAND || c == K_SCRIPT_COMMAND)
        {
!           int     cc_count = aucmd_cmdline_changed_count;
  
            if (do_cmdkey_command(c, DOCMD_NOWAIT) == OK)
            {
!               // Do not trigger CmdlineChanged below if the <Cmd> mapping
!               // already did that.
!               if (cc_count != aucmd_cmdline_changed_count)
                    trigger_cmdlinechanged = FALSE;
                goto cmdline_changed;
            }
*** ../vim-9.0.1038/src/testdir/test_autocmd.vim        2022-12-07 
09:17:56.520551971 +0000
--- src/testdir/test_autocmd.vim        2022-12-09 12:13:19.032911942 +0000
***************
*** 1908,1913 ****
--- 1908,1922 ----
    call assert_equal(':', g:entered)
    au! CmdlineChanged
  
+   let g:log = []
+   cnoremap <F1> <Cmd>call setcmdline('ls')<CR>
+   autocmd CmdlineChanged : let g:log += [getcmdline()]
+   call feedkeys(":\<F1>", 'xt')
+   call assert_equal(['ls'], g:log)
+   unlet g:log
+   au! CmdlineChanged
+   cunmap <F1>
+ 
    au! CmdlineEnter : let g:entered = expand('<afile>')
    au! CmdlineLeave : let g:left = expand('<afile>')
    let g:entered = 0
*** ../vim-9.0.1038/src/version.c       2022-12-09 11:36:33.176960092 +0000
--- src/version.c       2022-12-09 12:11:08.480771993 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1039,
  /**/

-- 
       We're knights of the round table
       We dance whene'er we're able
       We do routines and chorus scenes
       With footwork impeccable.
       We dine well here in Camelot
       We eat ham and jam and spam a lot.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221209122224.7697E1C1742%40moolenaar.net.

Raspunde prin e-mail lui