Skip to content

Commit bdcba24

Browse files
committed
patch 8.2.3433: :delcommand does not take a -buffer option
Problem: :delcommand does not take a -buffer option. Solution: Add the -buffer option.
1 parent ca0627d commit bdcba24

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

runtime/doc/map.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,10 @@ See |:verbose-cmd| for more information.
13681368
:delc[ommand] {cmd} *:delc* *:delcommand* *E184*
13691369
Delete the user-defined command {cmd}.
13701370

1371+
:delc[ommand] -buffer {cmd} *E1237*
1372+
Delete the user-defined command {cmd} that was defined
1373+
for the current buffer.
1374+
13711375
:comc[lear] *:comc* *:comclear*
13721376
Delete all user-defined commands.
13731377

src/errors.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ EXTERN char e_undefined_variable_str[]
141141
EXTERN char e_undefined_variable_char_str[]
142142
INIT(= N_("E121: Undefined variable: %c:%s"));
143143
#endif
144+
EXTERN char e_no_such_user_defined_command_str[]
145+
INIT(= N_("E184: No such user-defined command: %s"));
144146
#ifndef FEAT_DIGRAPHS
145147
EXTERN char e_no_digraphs_version[]
146148
INIT(= N_("E196: No digraphs in this version"));
@@ -656,3 +658,5 @@ EXTERN char e_function_reference_is_not_set[]
656658
INIT(= N_("E1235: Function reference is not set"));
657659
EXTERN char e_cannot_use_str_itself_it_is_imported_with_star[]
658660
INIT(= N_("E1236: Cannot use %s itself, it is imported with '*'"));
661+
EXTERN char e_no_such_user_defined_command_in_current_buffer_str[]
662+
INIT(= N_("E1237: No such user-defined command in current buffer: %s"));

src/testdir/test_usercommands.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,4 +656,25 @@ func Test_usercmd_with_block()
656656
call CheckScriptFailure(lines, 'E1231:')
657657
endfunc
658658

659+
func Test_delcommand_buffer()
660+
command Global echo 'global'
661+
command -buffer OneBuffer echo 'one'
662+
new
663+
command -buffer TwoBuffer echo 'two'
664+
call assert_equal(0, exists(':OneBuffer'))
665+
call assert_equal(2, exists(':Global'))
666+
call assert_equal(2, exists(':TwoBuffer'))
667+
delcommand -buffer TwoBuffer
668+
call assert_equal(0, exists(':TwoBuffer'))
669+
call assert_fails('delcommand -buffer Global', 'E1237:')
670+
call assert_fails('delcommand -buffer OneBuffer', 'E1237:')
671+
bwipe!
672+
call assert_equal(2, exists(':OneBuffer'))
673+
delcommand -buffer OneBuffer
674+
call assert_equal(0, exists(':OneBuffer'))
675+
call assert_fails('delcommand -buffer Global', 'E1237:')
676+
delcommand Global
677+
call assert_equal(0, exists(':Global'))
678+
endfunc
679+
659680
" vim: shiftwidth=2 sts=2 expandtab

src/usercmd.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,27 +1162,37 @@ ex_delcommand(exarg_T *eap)
11621162
{
11631163
int i = 0;
11641164
ucmd_T *cmd = NULL;
1165-
int cmp = -1;
1165+
int res = -1;
11661166
garray_T *gap;
1167+
char_u *arg = eap->arg;
1168+
int buffer_only = FALSE;
1169+
1170+
if (STRNCMP(arg, "-buffer", 7) == 0 && VIM_ISWHITE(arg[7]))
1171+
{
1172+
buffer_only = TRUE;
1173+
arg = skipwhite(arg + 7);
1174+
}
11671175

11681176
gap = &curbuf->b_ucmds;
11691177
for (;;)
11701178
{
11711179
for (i = 0; i < gap->ga_len; ++i)
11721180
{
11731181
cmd = USER_CMD_GA(gap, i);
1174-
cmp = STRCMP(eap->arg, cmd->uc_name);
1175-
if (cmp <= 0)
1182+
res = STRCMP(arg, cmd->uc_name);
1183+
if (res <= 0)
11761184
break;
11771185
}
1178-
if (gap == &ucmds || cmp == 0)
1186+
if (gap == &ucmds || res == 0 || buffer_only)
11791187
break;
11801188
gap = &ucmds;
11811189
}
11821190

1183-
if (cmp != 0)
1191+
if (res != 0)
11841192
{
1185-
semsg(_("E184: No such user-defined command: %s"), eap->arg);
1193+
semsg(_(buffer_only
1194+
? e_no_such_user_defined_command_in_current_buffer_str
1195+
: e_no_such_user_defined_command_str), arg);
11861196
return;
11871197
}
11881198

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3433,
758760
/**/
759761
3432,
760762
/**/

0 commit comments

Comments
 (0)