Patch 8.2.3629
Problem:    Command completion in cmdline window uses global user commands,
            not local commands for the window where it was opened from.
Solution:   Use local commands. (closes #9168)
Files:      src/ex_getln.c, src/proto/ex_getln.pro, src/evalvars.c,
            src/usercmd.c, src/testdir/test_ins_complete.vim


*** ../vim-8.2.3628/src/ex_getln.c      2021-10-17 17:20:20.399745698 +0100
--- src/ex_getln.c      2021-11-20 19:04:33.830004928 +0000
***************
*** 4485,4490 ****
--- 4485,4499 ----
  
      return cmdwin_result;
  }
+ 
+ /*
+  * Return TRUE if in the cmdwin, not editing the command line.
+  */
+     int
+ is_in_cmdwin(void)
+ {
+     return cmdwin_type != 0 && get_cmdline_type() == NUL;
+ }
  #endif // FEAT_CMDWIN
  
  /*
*** ../vim-8.2.3628/src/proto/ex_getln.pro      2021-10-17 17:20:20.399745698 
+0100
--- src/proto/ex_getln.pro      2021-11-20 19:09:38.689499396 +0000
***************
*** 38,43 ****
--- 38,44 ----
  int get_cmdline_firstc(void);
  int get_list_range(char_u **str, int *num1, int *num2);
  char *check_cedit(void);
+ int is_in_cmdwin(void);
  char_u *script_get(exarg_T *eap, char_u *cmd);
  void get_user_input(typval_T *argvars, typval_T *rettv, int inputdialog, int 
secret);
  /* vim: set ft=c : */
*** ../vim-8.2.3628/src/evalvars.c      2021-11-02 21:39:40.097064632 +0000
--- src/evalvars.c      2021-11-20 19:03:13.346152946 +0000
***************
*** 2074,2081 ****
      ht =
  #ifdef FEAT_CMDWIN
        // In cmdwin, the alternative buffer should be used.
!       (cmdwin_type != 0 && get_cmdline_type() == NUL) ?
!       &prevwin->w_buffer->b_vars->dv_hashtab :
  #endif
        &curbuf->b_vars->dv_hashtab;
      if (bdone < ht->ht_used)
--- 2074,2080 ----
      ht =
  #ifdef FEAT_CMDWIN
        // In cmdwin, the alternative buffer should be used.
!       is_in_cmdwin() ? &prevwin->w_buffer->b_vars->dv_hashtab :
  #endif
        &curbuf->b_vars->dv_hashtab;
      if (bdone < ht->ht_used)
***************
*** 2093,2100 ****
      ht =
  #ifdef FEAT_CMDWIN
        // In cmdwin, the alternative window should be used.
!       (cmdwin_type != 0 && get_cmdline_type() == NUL) ?
!       &prevwin->w_vars->dv_hashtab :
  #endif
        &curwin->w_vars->dv_hashtab;
      if (wdone < ht->ht_used)
--- 2092,2098 ----
      ht =
  #ifdef FEAT_CMDWIN
        // In cmdwin, the alternative window should be used.
!       is_in_cmdwin() ? &prevwin->w_vars->dv_hashtab :
  #endif
        &curwin->w_vars->dv_hashtab;
      if (wdone < ht->ht_used)
*** ../vim-8.2.3628/src/usercmd.c       2021-11-12 11:25:06.291264320 +0000
--- src/usercmd.c       2021-11-20 19:05:09.733941238 +0000
***************
*** 141,147 ****
      /*
       * Look for buffer-local user commands first, then global ones.
       */
!     gap = &curbuf->b_ucmds;
      for (;;)
      {
        for (j = 0; j < gap->ga_len; ++j)
--- 141,151 ----
      /*
       * Look for buffer-local user commands first, then global ones.
       */
!     gap =
! #ifdef FEAT_CMDWIN
!       is_in_cmdwin() ? &prevwin->w_buffer->b_ucmds :
! #endif
!       &curbuf->b_ucmds;
      for (;;)
      {
        for (j = 0; j < gap->ga_len; ++j)
***************
*** 303,309 ****
      // In cmdwin, the alternative buffer should be used.
      buf_T *buf =
  #ifdef FEAT_CMDWIN
!       (cmdwin_type != 0 && get_cmdline_type() == NUL) ? prevwin->w_buffer :
  #endif
        curbuf;
  
--- 307,313 ----
      // In cmdwin, the alternative buffer should be used.
      buf_T *buf =
  #ifdef FEAT_CMDWIN
!       is_in_cmdwin() ? prevwin->w_buffer :
  #endif
        curbuf;
  
***************
*** 330,339 ****
        // In cmdwin, the alternative buffer should be used.
        buf_T *buf =
  #ifdef FEAT_CMDWIN
!                   (cmdwin_type != 0 && get_cmdline_type() == NUL)
!                                                         ? prevwin->w_buffer :
  #endif
!           curbuf;
  
        if (idx < buf->b_ucmds.ga_len)
            return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
--- 334,342 ----
        // In cmdwin, the alternative buffer should be used.
        buf_T *buf =
  #ifdef FEAT_CMDWIN
!                   is_in_cmdwin() ? prevwin->w_buffer :
  #endif
!                   curbuf;
  
        if (idx < buf->b_ucmds.ga_len)
            return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
***************
*** 420,429 ****
      // In cmdwin, the alternative buffer should be used.
      gap =
  #ifdef FEAT_CMDWIN
!       (cmdwin_type != 0 && get_cmdline_type() == NUL) ?
!       &prevwin->w_buffer->b_ucmds :
  #endif
!       &curbuf->b_ucmds;
      for (;;)
      {
        for (i = 0; i < gap->ga_len; ++i)
--- 423,431 ----
      // In cmdwin, the alternative buffer should be used.
      gap =
  #ifdef FEAT_CMDWIN
!           is_in_cmdwin() ? &prevwin->w_buffer->b_ucmds :
  #endif
!           &curbuf->b_ucmds;
      for (;;)
      {
        for (i = 0; i < gap->ga_len; ++i)
*** ../vim-8.2.3628/src/testdir/test_ins_complete.vim   2021-08-31 
18:12:47.757554157 +0100
--- src/testdir/test_ins_complete.vim   2021-11-20 19:11:59.765286373 +0000
***************
*** 373,378 ****
--- 373,386 ----
    set completeopt&
  endfunc
  
+ func s:ComplInCmdwin_GlobalCompletion(a, l, p)
+   return 'global'
+ endfunc
+ 
+ func s:ComplInCmdwin_LocalCompletion(a, l, p)
+   return 'local'
+ endfunc
+ 
  func Test_compl_in_cmdwin()
    CheckFeature cmdwin
  
***************
*** 411,416 ****
--- 419,465 ----
    call feedkeys("q::GetInput b:test_\<Tab>\<CR>:q\<CR>", 'tx!')
    call assert_equal('b:test_', input)
  
+ 
+   " Argument completion of buffer-local command
+   func s:ComplInCmdwin_GlobalCompletionList(a, l, p)
+     return ['global']
+   endfunc
+ 
+   func s:ComplInCmdwin_LocalCompletionList(a, l, p)
+     return ['local']
+   endfunc
+ 
+   func s:ComplInCmdwin_CheckCompletion(arg)
+     call assert_equal('local', a:arg)
+   endfunc
+ 
+   com! -nargs=1 -complete=custom,<SID>ComplInCmdwin_GlobalCompletion
+        \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
+   com! -buffer -nargs=1 -complete=custom,<SID>ComplInCmdwin_LocalCompletion
+        \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
+   call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
+ 
+   com! -nargs=1 -complete=customlist,<SID>ComplInCmdwin_GlobalCompletionList
+        \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
+   com! -buffer -nargs=1 
-complete=customlist,<SID>ComplInCmdwin_LocalCompletionList
+        \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
+ 
+   call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
+ 
+   func! s:ComplInCmdwin_CheckCompletion(arg)
+     call assert_equal('global', a:arg)
+   endfunc
+   new
+   call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
+   quit
+ 
+   delfunc s:ComplInCmdwin_GlobalCompletion
+   delfunc s:ComplInCmdwin_LocalCompletion
+   delfunc s:ComplInCmdwin_GlobalCompletionList
+   delfunc s:ComplInCmdwin_LocalCompletionList
+   delfunc s:ComplInCmdwin_CheckCompletion
+ 
+   delcom -buffer TestCommand
    delcom TestCommand
    delcom GetInput
    unlet w:test_winvar
*** ../vim-8.2.3628/src/version.c       2021-11-20 13:45:37.814729588 +0000
--- src/version.c       2021-11-20 19:00:31.242476601 +0000
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     3629,
  /**/

-- 
My girlfriend told me I should be more affectionate.
So I got TWO girlfriends.

 /// 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/20211120191414.7749A1C044E%40moolenaar.net.

Raspunde prin e-mail lui