mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #17239 from seandewar/vim-8.2.3629
vim-patch:8.2.{3433,3629}
This commit is contained in:
commit
2870311a37
@ -1241,6 +1241,10 @@ See |:verbose-cmd| for more information.
|
||||
:delc[ommand] {cmd} *:delc* *:delcommand* *E184*
|
||||
Delete the user-defined command {cmd}.
|
||||
|
||||
:delc[ommand] -buffer {cmd} *E1237*
|
||||
Delete the user-defined command {cmd} that was defined
|
||||
for the current buffer.
|
||||
|
||||
:comc[lear] *:comc* *:comclear*
|
||||
Delete all user-defined commands.
|
||||
|
||||
|
@ -3218,9 +3218,8 @@ char_u *get_user_var_name(expand_T *xp, int idx)
|
||||
|
||||
// b: variables
|
||||
// In cmdwin, the alternative buffer should be used.
|
||||
hashtab_T *ht = (cmdwin_type != 0 && get_cmdline_type() == NUL)
|
||||
? &prevwin->w_buffer->b_vars->dv_hashtab
|
||||
: &curbuf->b_vars->dv_hashtab;
|
||||
hashtab_T *ht
|
||||
= is_in_cmdwin() ? &prevwin->w_buffer->b_vars->dv_hashtab : &curbuf->b_vars->dv_hashtab;
|
||||
if (bdone < ht->ht_used) {
|
||||
if (bdone++ == 0) {
|
||||
hi = ht->ht_array;
|
||||
@ -3235,9 +3234,7 @@ char_u *get_user_var_name(expand_T *xp, int idx)
|
||||
|
||||
// w: variables
|
||||
// In cmdwin, the alternative window should be used.
|
||||
ht = (cmdwin_type != 0 && get_cmdline_type() == NUL)
|
||||
? &prevwin->w_vars->dv_hashtab
|
||||
: &curwin->w_vars->dv_hashtab;
|
||||
ht = is_in_cmdwin() ? &prevwin->w_vars->dv_hashtab : &curwin->w_vars->dv_hashtab;
|
||||
if (wdone < ht->ht_used) {
|
||||
if (wdone++ == 0) {
|
||||
hi = ht->ht_array;
|
||||
|
@ -78,6 +78,10 @@
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/window.h"
|
||||
|
||||
static char *e_no_such_user_defined_command_str = N_("E184: No such user-defined command: %s");
|
||||
static char *e_no_such_user_defined_command_in_current_buffer_str
|
||||
= N_("E1237: No such user-defined command in current buffer: %s");
|
||||
|
||||
static int quitmore = 0;
|
||||
static bool ex_pressedreturn = false;
|
||||
|
||||
@ -2699,10 +2703,8 @@ static char_u *find_ucmd(exarg_T *eap, char_u *p, int *full, expand_T *xp, int *
|
||||
bool amb_local = false; // Found ambiguous buffer-local command,
|
||||
// only full match global is accepted.
|
||||
|
||||
/*
|
||||
* Look for buffer-local user commands first, then global ones.
|
||||
*/
|
||||
gap = &curbuf->b_ucmds;
|
||||
// Look for buffer-local user commands first, then global ones.
|
||||
gap = is_in_cmdwin() ? &prevwin->w_buffer->b_ucmds : &curbuf->b_ucmds;
|
||||
for (;;) {
|
||||
for (j = 0; j < gap->ga_len; j++) {
|
||||
uc = USER_CMD_GA(gap, j);
|
||||
@ -5349,9 +5351,7 @@ static void uc_list(char_u *name, size_t name_len)
|
||||
uint32_t a;
|
||||
|
||||
// In cmdwin, the alternative buffer should be used.
|
||||
garray_T *gap = (cmdwin_type != 0 && get_cmdline_type() == NUL)
|
||||
? &prevwin->w_buffer->b_ucmds
|
||||
: &curbuf->b_ucmds;
|
||||
garray_T *gap = is_in_cmdwin() ? &prevwin->w_buffer->b_ucmds : &curbuf->b_ucmds;
|
||||
for (;;) {
|
||||
for (i = 0; i < gap->ga_len; i++) {
|
||||
cmd = USER_CMD_GA(gap, i);
|
||||
@ -5739,26 +5739,36 @@ static void ex_delcommand(exarg_T *eap)
|
||||
{
|
||||
int i = 0;
|
||||
ucmd_T *cmd = NULL;
|
||||
int cmp = -1;
|
||||
int res = -1;
|
||||
garray_T *gap;
|
||||
const char_u *arg = eap->arg;
|
||||
bool buffer_only = false;
|
||||
|
||||
if (STRNCMP(arg, "-buffer", 7) == 0 && ascii_iswhite(arg[7])) {
|
||||
buffer_only = true;
|
||||
arg = skipwhite(arg + 7);
|
||||
}
|
||||
|
||||
gap = &curbuf->b_ucmds;
|
||||
for (;;) {
|
||||
for (i = 0; i < gap->ga_len; i++) {
|
||||
cmd = USER_CMD_GA(gap, i);
|
||||
cmp = STRCMP(eap->arg, cmd->uc_name);
|
||||
if (cmp <= 0) {
|
||||
res = STRCMP(arg, cmd->uc_name);
|
||||
if (res <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (gap == &ucmds || cmp == 0) {
|
||||
if (gap == &ucmds || res == 0 || buffer_only) {
|
||||
break;
|
||||
}
|
||||
gap = &ucmds;
|
||||
}
|
||||
|
||||
if (cmp != 0) {
|
||||
semsg(_("E184: No such user-defined command: %s"), eap->arg);
|
||||
if (res != 0) {
|
||||
semsg(_(buffer_only
|
||||
? e_no_such_user_defined_command_in_current_buffer_str
|
||||
: e_no_such_user_defined_command_str),
|
||||
arg);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -6295,9 +6305,7 @@ char_u *get_user_commands(expand_T *xp FUNC_ATTR_UNUSED, int idx)
|
||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
// In cmdwin, the alternative buffer should be used.
|
||||
const buf_T *const buf = (cmdwin_type != 0 && get_cmdline_type() == NUL)
|
||||
? prevwin->w_buffer
|
||||
: curbuf;
|
||||
const buf_T *const buf = is_in_cmdwin() ? prevwin->w_buffer : curbuf;
|
||||
|
||||
if (idx < buf->b_ucmds.ga_len) {
|
||||
return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
|
||||
@ -6319,7 +6327,7 @@ static char_u *get_user_command_name(int idx, int cmdidx)
|
||||
}
|
||||
if (cmdidx == CMD_USER_BUF) {
|
||||
// In cmdwin, the alternative buffer should be used.
|
||||
buf_T *buf = (cmdwin_type != 0 && get_cmdline_type() == NUL) ? prevwin->w_buffer : curbuf;
|
||||
buf_T *buf = is_in_cmdwin() ? prevwin->w_buffer : curbuf;
|
||||
if (idx < buf->b_ucmds.ga_len) {
|
||||
return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
|
||||
}
|
||||
|
@ -6587,6 +6587,13 @@ static int open_cmdwin(void)
|
||||
return cmdwin_result;
|
||||
}
|
||||
|
||||
/// @return true if in the cmdwin, not editing the command line.
|
||||
bool is_in_cmdwin(void)
|
||||
FUNC_ATTR_PURE
|
||||
{
|
||||
return cmdwin_type != 0 && get_cmdline_type() == NUL;
|
||||
}
|
||||
|
||||
/// Get script string
|
||||
///
|
||||
/// Used for commands which accept either `:command script` or
|
||||
|
@ -341,6 +341,14 @@ func Test_compl_feedkeys()
|
||||
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()
|
||||
set wildmenu wildchar=<Tab>
|
||||
com! -nargs=1 -complete=command GetInput let input = <q-args>
|
||||
@ -376,6 +384,47 @@ func Test_compl_in_cmdwin()
|
||||
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
|
||||
|
@ -350,7 +350,6 @@ func Test_use_execute_in_completion()
|
||||
endfunc
|
||||
|
||||
func Test_addr_all()
|
||||
throw 'skipped: requires patch v8.1.0341 to pass'
|
||||
command! -addr=lines DoSomething let g:a1 = <line1> | let g:a2 = <line2>
|
||||
%DoSomething
|
||||
call assert_equal(1, g:a1)
|
||||
@ -551,3 +550,26 @@ func Test_command_list()
|
||||
call assert_equal("\nNo user-defined commands found", execute(':command Xxx'))
|
||||
call assert_equal("\nNo user-defined commands found", execute('command'))
|
||||
endfunc
|
||||
|
||||
func Test_delcommand_buffer()
|
||||
command Global echo 'global'
|
||||
command -buffer OneBuffer echo 'one'
|
||||
new
|
||||
command -buffer TwoBuffer echo 'two'
|
||||
call assert_equal(0, exists(':OneBuffer'))
|
||||
call assert_equal(2, exists(':Global'))
|
||||
call assert_equal(2, exists(':TwoBuffer'))
|
||||
delcommand -buffer TwoBuffer
|
||||
call assert_equal(0, exists(':TwoBuffer'))
|
||||
call assert_fails('delcommand -buffer Global', 'E1237:')
|
||||
call assert_fails('delcommand -buffer OneBuffer', 'E1237:')
|
||||
bwipe!
|
||||
call assert_equal(2, exists(':OneBuffer'))
|
||||
delcommand -buffer OneBuffer
|
||||
call assert_equal(0, exists(':OneBuffer'))
|
||||
call assert_fails('delcommand -buffer Global', 'E1237:')
|
||||
delcommand Global
|
||||
call assert_equal(0, exists(':Global'))
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
Loading…
Reference in New Issue
Block a user