]> granicus.if.org Git - vim/commitdiff
patch 8.2.0054: :diffget and :diffput don't have good completion v8.2.0054
authorBram Moolenaar <Bram@vim.org>
Sun, 29 Dec 2019 12:56:33 +0000 (13:56 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 29 Dec 2019 12:56:33 +0000 (13:56 +0100)
Problem:    :diffget and :diffput don't have good completion.
Solution:   Add proper completion. (Dominique Pelle, closes #5409)

runtime/doc/eval.txt
src/buffer.c
src/cmdexpand.c
src/testdir/test_diffmode.vim
src/usercmd.c
src/version.c
src/vim.h

index e34cd4b42756a79ab6639592fd35a42077dab78b..f06a7276238f4863899b7d7b748bfe042d351d55 100644 (file)
@@ -5058,6 +5058,7 @@ getcompletion({pat}, {type} [, {filtered}])               *getcompletion()*
                command         Ex command (and arguments)
                compiler        compilers
                cscope          |:cscope| suboptions
+               diff_buffer     |:diffget| and |:diffput| completion
                dir             directory names
                environment     environment variable names
                event           autocommand events
index 740d31b91b000190c511bd4b22ce68100bfa5969..2502dee6271d1cc877a7c995ee99e4628a6c4b7f 100644 (file)
@@ -2702,6 +2702,15 @@ ExpandBufnames(
            {
                if (!buf->b_p_bl)       // skip unlisted buffers
                    continue;
+#ifdef FEAT_DIFF
+               if (options & BUF_DIFF_FILTER)
+                   // Skip buffers not suitable for
+                   // :diffget or :diffput completion.
+                   if (buf == curbuf
+                           || !diff_mode_buf(curbuf) || !diff_mode_buf(buf))
+                       continue;
+#endif
+
                p = buflist_match(&regmatch, buf, p_wic);
                if (p != NULL)
                {
index 1a7f9f2ecd5430dadf645d3345380f016c578701..9dc78ed5c3c0d88913c14c3b21bd0f7976299c51 100644 (file)
@@ -1582,7 +1582,15 @@ set_one_cmd_context(
            xp->xp_context = EXPAND_BUFFERS;
            xp->xp_pattern = arg;
            break;
-
+#ifdef FEAT_DIFF
+       case CMD_diffget:
+       case CMD_diffput:
+           // If current buffer is in diff mode, complete buffer names
+           // which are in diff mode, and different than current buffer.
+           xp->xp_context = EXPAND_DIFF_BUFFERS;
+           xp->xp_pattern = arg;
+           break;
+#endif
        case CMD_USER:
        case CMD_USER_BUF:
            if (compl != EXPAND_NOTHING)
@@ -2069,6 +2077,10 @@ ExpandFromContext(
        return ExpandOldSetting(num_file, file);
     if (xp->xp_context == EXPAND_BUFFERS)
        return ExpandBufnames(pat, num_file, file, options);
+#ifdef FEAT_DIFF
+    if (xp->xp_context == EXPAND_DIFF_BUFFERS)
+       return ExpandBufnames(pat, num_file, file, options | BUF_DIFF_FILTER);
+#endif
     if (xp->xp_context == EXPAND_TAGS
            || xp->xp_context == EXPAND_TAGS_LISTFILES)
        return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file);
index 9dfe2fefce3f4dff6233cfc0cb5d88a19d69a537..b93cc6d3e1be7278f8f79f59ef17999419efe128 100644 (file)
@@ -242,6 +242,46 @@ func Test_diffput_two()
   bwipe! b
 endfunc
 
+func Test_diffget_diffput_completion()
+  new Xdiff1 | diffthis
+  new Xdiff2 | diffthis
+  new Xdiff3 | diffthis
+  new Xdiff4
+
+  " :diffput and :diffget completes names of buffers which
+  " are in diff mode and which are different then current buffer.
+  b Xdiff1
+  call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"diffput Xdiff2 Xdiff3', @:)
+  call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"diffget Xdiff2 Xdiff3', @:)
+  call assert_equal(['Xdiff2', 'Xdiff3'], getcompletion('', 'diff_buffer'))
+
+  b Xdiff2
+  call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"diffput Xdiff1 Xdiff3', @:)
+  call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"diffget Xdiff1 Xdiff3', @:)
+  call assert_equal(['Xdiff1', 'Xdiff3'], getcompletion('', 'diff_buffer'))
+
+  b Xdiff3
+  call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"diffput Xdiff1 Xdiff2', @:)
+  call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"diffget Xdiff1 Xdiff2', @:)
+  call assert_equal(['Xdiff1', 'Xdiff2'], getcompletion('', 'diff_buffer'))
+
+  " No completion when in Xdiff4, it's not in diff mode.
+  b Xdiff4
+  call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"diffput ', @:)
+  call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"diffget ', @:)
+  call assert_equal([], getcompletion('', 'diff_buffer'))
+
+  %bwipe
+endfunc
+
 func Test_dp_do_buffer()
   e! one
   let bn1=bufnr('%')
index 5db6f48be3e7719ec2bf3aef2708344ac315bc20..1a6fbeebc62a33414dc5ad11976f381b88a5d827 100644 (file)
@@ -57,6 +57,7 @@ static struct
     {EXPAND_USER_DEFINED, "custom"},
     {EXPAND_USER_LIST, "customlist"},
 #endif
+    {EXPAND_DIFF_BUFFERS, "diff_buffer"},
     {EXPAND_DIRECTORIES, "dir"},
     {EXPAND_ENV_VARS, "environment"},
     {EXPAND_EVENTS, "event"},
index 0eaafd1f1c4215296d97ccec77e3598a53e7d236..a099cd3ec7777de47109d67510038350b77f85dd 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    54,
 /**/
     53,
 /**/
index a01d4b290858b347c06839cc24f337e1b687915e..c4c649c3dd2d2c8460792e6b2fa790c2680268e8 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -801,6 +801,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #define EXPAND_MESSAGES                46
 #define EXPAND_MAPCLEAR                47
 #define EXPAND_ARGLIST         48
+#define EXPAND_DIFF_BUFFERS    49
 
 // Values for exmode_active (0 is no exmode)
 #define EXMODE_NORMAL          1
@@ -829,6 +830,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #define WILD_IGNORE_COMPLETESLASH   0x400
 #define WILD_NOERROR               0x800  // sets EW_NOERROR
 #define WILD_BUFLASTUSED           0x1000
+#define BUF_DIFF_FILTER                    0x2000
 
 // Flags for expand_wildcards()
 #define EW_DIR         0x01    // include directory names