vim-patch:9.1.0010: Keymap completion is not available (#26888)

Problem:  Keymap completion is not available
Solution: Add keymap completion (Doug Kearns)

Add keymap completion to the 'keymap' option, user commands and builtin
completion functions.

closes: vim/vim#13692

81642d9d6f

Co-authored-by: Doug Kearns <dougkearns@gmail.com>
This commit is contained in:
zeertzjq
2024-01-05 08:23:51 +08:00
committed by GitHub
parent 88eb0ad149
commit dab5844082
10 changed files with 31 additions and 0 deletions

View File

@ -2372,6 +2372,7 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
help help subjects
highlight highlight groups
history |:history| suboptions
keymap keyboard mappings
locale locale names (as output of locale -a)
mapclear buffer argument
mapping mapping name

View File

@ -1389,6 +1389,7 @@ completion can be enabled:
-complete=help help subjects
-complete=highlight highlight groups
-complete=history :history suboptions
-complete=keymap keyboard mappings
-complete=locale locale names (as output of locale -a)
-complete=lua Lua expression |:lua|
-complete=mapclear buffer argument

View File

@ -2889,6 +2889,7 @@ function vim.fn.getcmdwintype() end
--- help help subjects
--- highlight highlight groups
--- history |:history| suboptions
--- keymap keyboard mappings
--- locale locale names (as output of locale -a)
--- mapclear buffer argument
--- mapping mapping name

View File

@ -99,6 +99,7 @@ static bool cmdline_fuzzy_completion_supported(const expand_T *const xp)
&& xp->xp_context != EXPAND_FILES_IN_PATH
&& xp->xp_context != EXPAND_FILETYPE
&& xp->xp_context != EXPAND_HELP
&& xp->xp_context != EXPAND_KEYMAP
&& xp->xp_context != EXPAND_LUA
&& xp->xp_context != EXPAND_OLD_SETTING
&& xp->xp_context != EXPAND_STRING_SETTING
@ -1215,6 +1216,7 @@ char *addstar(char *fname, size_t len, int context)
|| context == EXPAND_COMPILER
|| context == EXPAND_OWNSYNTAX
|| context == EXPAND_FILETYPE
|| context == EXPAND_KEYMAP
|| context == EXPAND_PACKADD
|| context == EXPAND_RUNTIME
|| ((context == EXPAND_TAGS_LISTFILES || context == EXPAND_TAGS)
@ -2741,6 +2743,10 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
char *directories[] = { "syntax", "indent", "ftplugin", NULL };
return ExpandRTDir(pat, 0, numMatches, matches, directories);
}
if (xp->xp_context == EXPAND_KEYMAP) {
char *directories[] = { "keymap", NULL };
return ExpandRTDir(pat, 0, numMatches, matches, directories);
}
if (xp->xp_context == EXPAND_USER_LIST) {
return ExpandUserList(xp, matches, numMatches);
}

View File

@ -105,6 +105,7 @@ enum {
EXPAND_STRING_SETTING,
EXPAND_SETTING_SUBTRACT,
EXPAND_ARGOPT,
EXPAND_KEYMAP,
EXPAND_CHECKHEALTH,
EXPAND_LUA,
};

View File

@ -3609,6 +3609,7 @@ M.funcs = {
help help subjects
highlight highlight groups
history |:history| suboptions
keymap keyboard mappings
locale locale names (as output of locale -a)
mapclear buffer argument
mapping mapping name

View File

@ -5461,6 +5461,10 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
xp->xp_context = EXPAND_FILETYPE;
return;
}
if (options[opt_idx].var == &p_keymap) {
xp->xp_context = EXPAND_KEYMAP;
return;
}
// Now pick. If the option has a custom expander, use that. Otherwise, just
// fill with the existing option value.

View File

@ -75,6 +75,7 @@ static const char *command_complete[] = {
[EXPAND_HELP] = "help",
[EXPAND_HIGHLIGHT] = "highlight",
[EXPAND_HISTORY] = "history",
[EXPAND_KEYMAP] = "keymap",
#ifdef HAVE_WORKING_LIBINTL
[EXPAND_LOCALES] = "locale",
#endif

View File

@ -532,6 +532,13 @@ func Test_getcompletion()
let l = getcompletion('horse', 'filetype')
call assert_equal([], l)
if has('keymap')
let l = getcompletion('acc', 'keymap')
call assert_true(index(l, 'accents') >= 0)
let l = getcompletion('nullkeymap', 'keymap')
call assert_equal([], l)
endif
let l = getcompletion('z', 'syntax')
call assert_true(index(l, 'zimbu') >= 0)
let l = getcompletion('emacs', 'syntax')

View File

@ -439,6 +439,14 @@ func Test_set_completion()
call assert_equal('"set syntax=sshdconfig', @:)
call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
if has('keymap')
" Expand values for 'keymap'
call feedkeys(":set keymap=acc\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set keymap=accents', @:)
call feedkeys(":set keymap=a\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set keymap=' .. getcompletion('a*', 'keymap')->join(), @:)
endif
endfunc
" Test handling of expanding individual string option values