mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 17:28:23 +00:00
vim-patch:8.2.3433: :delcommand does not take a -buffer option
Problem: :delcommand does not take a -buffer option.
Solution: Add the -buffer option.
bdcba24d85
This commit is contained in:
@@ -1241,6 +1241,10 @@ See |:verbose-cmd| for more information.
|
|||||||
:delc[ommand] {cmd} *:delc* *:delcommand* *E184*
|
:delc[ommand] {cmd} *:delc* *:delcommand* *E184*
|
||||||
Delete the user-defined command {cmd}.
|
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*
|
:comc[lear] *:comc* *:comclear*
|
||||||
Delete all user-defined commands.
|
Delete all user-defined commands.
|
||||||
|
|
||||||
|
@@ -78,6 +78,10 @@
|
|||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
#include "nvim/window.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 int quitmore = 0;
|
||||||
static bool ex_pressedreturn = false;
|
static bool ex_pressedreturn = false;
|
||||||
|
|
||||||
@@ -5737,26 +5741,36 @@ static void ex_delcommand(exarg_T *eap)
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
ucmd_T *cmd = NULL;
|
ucmd_T *cmd = NULL;
|
||||||
int cmp = -1;
|
int res = -1;
|
||||||
garray_T *gap;
|
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;
|
gap = &curbuf->b_ucmds;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
for (i = 0; i < gap->ga_len; i++) {
|
for (i = 0; i < gap->ga_len; i++) {
|
||||||
cmd = USER_CMD_GA(gap, i);
|
cmd = USER_CMD_GA(gap, i);
|
||||||
cmp = STRCMP(eap->arg, cmd->uc_name);
|
res = STRCMP(arg, cmd->uc_name);
|
||||||
if (cmp <= 0) {
|
if (res <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gap == &ucmds || cmp == 0) {
|
if (gap == &ucmds || res == 0 || buffer_only) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
gap = &ucmds;
|
gap = &ucmds;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmp != 0) {
|
if (res != 0) {
|
||||||
semsg(_("E184: No such user-defined command: %s"), eap->arg);
|
semsg(_(buffer_only
|
||||||
|
? e_no_such_user_defined_command_in_current_buffer_str
|
||||||
|
: e_no_such_user_defined_command_str),
|
||||||
|
arg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -551,3 +551,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 Xxx'))
|
||||||
call assert_equal("\nNo user-defined commands found", execute('command'))
|
call assert_equal("\nNo user-defined commands found", execute('command'))
|
||||||
endfunc
|
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
|
||||||
|
Reference in New Issue
Block a user