]> granicus.if.org Git - vim/commitdiff
patch 8.2.3433: :delcommand does not take a -buffer option v8.2.3433
authorBram Moolenaar <Bram@vim.org>
Sun, 12 Sep 2021 18:58:02 +0000 (20:58 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 12 Sep 2021 18:58:02 +0000 (20:58 +0200)
Problem:    :delcommand does not take a -buffer option.
Solution:   Add the -buffer option.

runtime/doc/map.txt
src/errors.h
src/testdir/test_usercommands.vim
src/usercmd.c
src/version.c

index 952abd6a027b49a26a7f401f3e49ee266aa61e8d..38687043b1c798f4714d2224912a467dc3fe2cf4 100644 (file)
@@ -1368,6 +1368,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.
 
index 2a76504b4291ae6165d0c8b62352247a7d7a2df1..d4ba7f0ea58f800ac412a1e418225088562a5c70 100644 (file)
@@ -141,6 +141,8 @@ EXTERN char e_undefined_variable_str[]
 EXTERN char e_undefined_variable_char_str[]
        INIT(= N_("E121: Undefined variable: %c:%s"));
 #endif
+EXTERN char e_no_such_user_defined_command_str[]
+       INIT(= N_("E184: No such user-defined command: %s"));
 #ifndef FEAT_DIGRAPHS
 EXTERN char e_no_digraphs_version[]
        INIT(= N_("E196: No digraphs in this version"));
@@ -656,3 +658,5 @@ EXTERN char e_function_reference_is_not_set[]
        INIT(= N_("E1235: Function reference is not set"));
 EXTERN char e_cannot_use_str_itself_it_is_imported_with_star[]
        INIT(= N_("E1236: Cannot use %s itself, it is imported with '*'"));
+EXTERN char e_no_such_user_defined_command_in_current_buffer_str[]
+       INIT(= N_("E1237: No such user-defined command in current buffer: %s"));
index 3f15dc187d1e723851a47a42e1572530235ee372..48bfd5a2521f066831b86e66cad11f45ecd3260a 100644 (file)
@@ -656,4 +656,25 @@ func Test_usercmd_with_block()
   call CheckScriptFailure(lines, 'E1231:')
 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
index e35f4a532e98f776f308689054751ed9fa8f6e8a..8ead42c5260fd4241333aa0adc4665c1eab183df 100644 (file)
@@ -1162,8 +1162,16 @@ ex_delcommand(exarg_T *eap)
 {
     int                i = 0;
     ucmd_T     *cmd = NULL;
-    int                cmp = -1;
+    int                res = -1;
     garray_T   *gap;
+    char_u     *arg = eap->arg;
+    int                buffer_only = FALSE;
+
+    if (STRNCMP(arg, "-buffer", 7) == 0 && VIM_ISWHITE(arg[7]))
+    {
+       buffer_only = TRUE;
+       arg = skipwhite(arg + 7);
+    }
 
     gap = &curbuf->b_ucmds;
     for (;;)
@@ -1171,18 +1179,20 @@ ex_delcommand(exarg_T *eap)
        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)
+    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;
     }
 
index 7d87105b6138249ef32b2cd58fc888e71e3998ea..e8e5bc4a6e00dafb4f7a07224d5948a6a2cce477 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3433,
 /**/
     3432,
 /**/