mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	vim-patch:9.1.0748: :keep* commmands are sometimes misidentified as :k
Problem:  The :keep{alt,jumps,marks,patterns} commmands are sometimes
          misidentified as :k.
Solution: Make sure one_letter_cmd() only returns true for :k and not
          other :keep* commands (Doug Kearns).
This currently manifests as missing completion for :keep* commands and
incorrect results from fullcommand().
E.g., fullcommand("keepmarks") returns "k" rather than "keepmarks".
The correct command, however, is executed as command modifiers are
handled specially in do_one_cmd() rather than using find_ex_command().
Fix exists(':k') so that it returns 2 for a full match.
closes: vim/vim#15742
ea84202372
Cherry-pick Test_ex_command_completion() from patch 9.1.0624.
Co-authored-by: Doug Kearns <dougkearns@gmail.com>
(cherry picked from commit 70bb7999f7)
			
			
This commit is contained in:
		
				
					committed by
					
						
						github-actions[bot]
					
				
			
			
				
	
			
			
			
						parent
						
							fb6c677d57
						
					
				
				
					commit
					6c2f06b537
				
			@@ -3023,13 +3023,16 @@ static void append_command(const char *cmd)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Return true and set "*idx" if "p" points to a one letter command.
 | 
					/// Return true and set "*idx" if "p" points to a one letter command.
 | 
				
			||||||
/// - The 'k' command can directly be followed by any character.
 | 
					/// - The 'k' command can directly be followed by any character
 | 
				
			||||||
 | 
					///          but :keepa[lt] is another command, as are :keepj[umps],
 | 
				
			||||||
 | 
					///          :kee[pmarks] and :keepp[atterns].
 | 
				
			||||||
/// - The 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r'
 | 
					/// - The 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r'
 | 
				
			||||||
///          but :sre[wind] is another command, as are :scr[iptnames],
 | 
					///          but :sre[wind] is another command, as are :scr[iptnames],
 | 
				
			||||||
///          :scs[cope], :sim[alt], :sig[ns] and :sil[ent].
 | 
					///          :scs[cope], :sim[alt], :sig[ns] and :sil[ent].
 | 
				
			||||||
static int one_letter_cmd(const char *p, cmdidx_T *idx)
 | 
					static int one_letter_cmd(const char *p, cmdidx_T *idx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  if (*p == 'k') {
 | 
					  if (p[0] == 'k'
 | 
				
			||||||
 | 
					      && (p[1] != 'e' || (p[1] == 'e' && p[2] != 'e'))) {
 | 
				
			||||||
    *idx = CMD_k;
 | 
					    *idx = CMD_k;
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -3062,6 +3065,9 @@ char *find_ex_command(exarg_T *eap, int *full)
 | 
				
			|||||||
  char *p = eap->cmd;
 | 
					  char *p = eap->cmd;
 | 
				
			||||||
  if (one_letter_cmd(p, &eap->cmdidx)) {
 | 
					  if (one_letter_cmd(p, &eap->cmdidx)) {
 | 
				
			||||||
    p++;
 | 
					    p++;
 | 
				
			||||||
 | 
					    if (full != NULL) {
 | 
				
			||||||
 | 
					      *full = true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    while (ASCII_ISALPHA(*p)) {
 | 
					    while (ASCII_ISALPHA(*p)) {
 | 
				
			||||||
      p++;
 | 
					      p++;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1204,6 +1204,10 @@ func Test_cmdline_complete_various()
 | 
				
			|||||||
  call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
 | 
					  call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
 | 
				
			||||||
  call assert_equal("\"ka\<C-A>", @:)
 | 
					  call assert_equal("\"ka\<C-A>", @:)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  " completion for :keepmarks command
 | 
				
			||||||
 | 
					  call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
 | 
				
			||||||
 | 
					  call assert_equal("\"kee edit", @:)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  " completion for short version of the :s command
 | 
					  " completion for short version of the :s command
 | 
				
			||||||
  call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
 | 
					  call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
 | 
				
			||||||
  call assert_equal("\"sI \<C-A>", @:)
 | 
					  call assert_equal("\"sI \<C-A>", @:)
 | 
				
			||||||
@@ -4276,6 +4280,28 @@ func Test_term_option()
 | 
				
			|||||||
  let &cpo = _cpo
 | 
					  let &cpo = _cpo
 | 
				
			||||||
endfunc
 | 
					endfunc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Test_ex_command_completion()
 | 
				
			||||||
 | 
					  " required for :*
 | 
				
			||||||
 | 
					  " set cpo+=*
 | 
				
			||||||
 | 
					  let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
 | 
				
			||||||
 | 
					  " :++ and :-- are only valid in Vim9 script context, so they can be ignored
 | 
				
			||||||
 | 
					  " call assert_equal(['++', '--'], sort(list))
 | 
				
			||||||
 | 
					  call assert_equal([], sort(list))
 | 
				
			||||||
 | 
					  call assert_equal(2, exists(':k'))
 | 
				
			||||||
 | 
					  call assert_equal(0, exists(':ke'))
 | 
				
			||||||
 | 
					  call assert_equal(1, exists(':kee'))
 | 
				
			||||||
 | 
					  call assert_equal(1, exists(':keep'))
 | 
				
			||||||
 | 
					  call assert_equal(1, exists(':keepm'))
 | 
				
			||||||
 | 
					  call assert_equal(1, exists(':keepma'))
 | 
				
			||||||
 | 
					  call assert_equal(1, exists(':keepmar'))
 | 
				
			||||||
 | 
					  call assert_equal(1, exists(':keepmark'))
 | 
				
			||||||
 | 
					  call assert_equal(2, exists(':keepmarks'))
 | 
				
			||||||
 | 
					  call assert_equal(2, exists(':keepalt'))
 | 
				
			||||||
 | 
					  call assert_equal(2, exists(':keepjumps'))
 | 
				
			||||||
 | 
					  call assert_equal(2, exists(':keeppatterns'))
 | 
				
			||||||
 | 
					  set cpo-=*
 | 
				
			||||||
 | 
					endfunc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Test_cd_bslash_completion_windows()
 | 
					func Test_cd_bslash_completion_windows()
 | 
				
			||||||
  CheckMSWindows
 | 
					  CheckMSWindows
 | 
				
			||||||
  let save_shellslash = &shellslash
 | 
					  let save_shellslash = &shellslash
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										38
									
								
								test/old/testdir/test_cmdmods.vim
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								test/old/testdir/test_cmdmods.vim
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					" Test for all command modifiers in
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Test_keep_cmdmods_names()
 | 
				
			||||||
 | 
					  call assert_equal('k', fullcommand(':k'))
 | 
				
			||||||
 | 
					  call assert_equal('k', fullcommand(':ke'))
 | 
				
			||||||
 | 
					  call assert_equal('keepmarks', fullcommand(':kee'))
 | 
				
			||||||
 | 
					  call assert_equal('keepmarks', fullcommand(':keep'))
 | 
				
			||||||
 | 
					  call assert_equal('keepmarks', fullcommand(':keepm'))
 | 
				
			||||||
 | 
					  call assert_equal('keepmarks', fullcommand(':keepma'))
 | 
				
			||||||
 | 
					  call assert_equal('keepmarks', fullcommand(':keepmar'))
 | 
				
			||||||
 | 
					  call assert_equal('keepmarks', fullcommand(':keepmark'))
 | 
				
			||||||
 | 
					  call assert_equal('keepmarks', fullcommand(':keepmarks'))
 | 
				
			||||||
 | 
					  call assert_equal('keepalt', fullcommand(':keepa'))
 | 
				
			||||||
 | 
					  call assert_equal('keepalt', fullcommand(':keepal'))
 | 
				
			||||||
 | 
					  call assert_equal('keepalt', fullcommand(':keepalt'))
 | 
				
			||||||
 | 
					  call assert_equal('keepjumps', fullcommand(':keepj'))
 | 
				
			||||||
 | 
					  call assert_equal('keepjumps', fullcommand(':keepju'))
 | 
				
			||||||
 | 
					  call assert_equal('keepjumps', fullcommand(':keepjum'))
 | 
				
			||||||
 | 
					  call assert_equal('keepjumps', fullcommand(':keepjump'))
 | 
				
			||||||
 | 
					  call assert_equal('keepjumps', fullcommand(':keepjumps'))
 | 
				
			||||||
 | 
					  call assert_equal('keeppatterns', fullcommand(':keepp'))
 | 
				
			||||||
 | 
					  call assert_equal('keeppatterns', fullcommand(':keeppa'))
 | 
				
			||||||
 | 
					  call assert_equal('keeppatterns', fullcommand(':keeppat'))
 | 
				
			||||||
 | 
					  call assert_equal('keeppatterns', fullcommand(':keeppatt'))
 | 
				
			||||||
 | 
					  call assert_equal('keeppatterns', fullcommand(':keeppatte'))
 | 
				
			||||||
 | 
					  call assert_equal('keeppatterns', fullcommand(':keeppatter'))
 | 
				
			||||||
 | 
					  call assert_equal('keeppatterns', fullcommand(':keeppattern'))
 | 
				
			||||||
 | 
					  call assert_equal('keeppatterns', fullcommand(':keeppatterns'))
 | 
				
			||||||
 | 
					endfunc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Test_cmdmod_completion()
 | 
				
			||||||
 | 
					  call assert_equal('edit', getcompletion('keepalt ed',      'cmdline')[0])
 | 
				
			||||||
 | 
					  call assert_equal('edit', getcompletion('keepjumps ed',    'cmdline')[0])
 | 
				
			||||||
 | 
					  call assert_equal('edit', getcompletion('keepmarks ed',    'cmdline')[0])
 | 
				
			||||||
 | 
					  call assert_equal('edit', getcompletion('keeppatterns ed', 'cmdline')[0])
 | 
				
			||||||
 | 
					endfunc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					" vim: shiftwidth=2 sts=2 expandtab
 | 
				
			||||||
@@ -105,6 +105,13 @@ func Test_exists()
 | 
				
			|||||||
  " Internal command with a count
 | 
					  " Internal command with a count
 | 
				
			||||||
  call assert_equal(0, exists(':3buffer'))
 | 
					  call assert_equal(0, exists(':3buffer'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  " Valid internal command (full match)
 | 
				
			||||||
 | 
					  call assert_equal(2, exists(':k'))
 | 
				
			||||||
 | 
					  " Non-existing internal command (':k' with arg 'e')
 | 
				
			||||||
 | 
					  call assert_equal(0, exists(':ke'))
 | 
				
			||||||
 | 
					  " Valid internal command (partial match)
 | 
				
			||||||
 | 
					  call assert_equal(1, exists(':kee'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  " User defined command (full match)
 | 
					  " User defined command (full match)
 | 
				
			||||||
  command! MyCmd :echo 'My command'
 | 
					  command! MyCmd :echo 'My command'
 | 
				
			||||||
  call assert_equal(2, exists(':MyCmd'))
 | 
					  call assert_equal(2, exists(':MyCmd'))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user