diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-02-13 18:04:39 -0500 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-02-13 18:17:25 -0500 |
commit | 54cd7298f8aa6adfa5a629b13ecb71b7779798bd (patch) | |
tree | 87e43c1069dc189a241f8fb834cb28871a0ef47f | |
parent | fd44bd4d4feb884460fd9f023b162f5ee166aae0 (diff) | |
download | rneovim-54cd7298f8aa6adfa5a629b13ecb71b7779798bd.tar.gz rneovim-54cd7298f8aa6adfa5a629b13ecb71b7779798bd.tar.bz2 rneovim-54cd7298f8aa6adfa5a629b13ecb71b7779798bd.zip |
vim-patch:8.2.0054: :diffget and :diffput don't have good completion
Problem: :diffget and :diffput don't have good completion.
Solution: Add proper completion. (Dominique Pelle, closes vim/vim#5409)
https://github.com/vim/vim/commit/ae7dba896975051a3f0b7123faa08dac5635972d
-rw-r--r-- | runtime/doc/eval.txt | 1 | ||||
-rw-r--r-- | src/nvim/buffer.c | 9 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 8 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 6 | ||||
-rw-r--r-- | src/nvim/ex_getln.h | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_diffmode.vim | 40 | ||||
-rw-r--r-- | src/nvim/vim.h | 1 |
7 files changed, 65 insertions, 1 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 0343998fe8..5a01724920 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -4454,6 +4454,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 diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 9e097a54a4..6b66d8733e 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2345,6 +2345,15 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) if (!buf->b_p_bl) { // skip unlisted buffers continue; } + 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; + } + } p = buflist_match(®match, buf, p_wic); if (p != NULL) { if (round == 1) { diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index ef11107779..35f6503ce4 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3512,6 +3512,13 @@ const char * set_one_cmd_context( xp->xp_context = EXPAND_BUFFERS; xp->xp_pattern = (char_u *)arg; break; + 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 = (char_u *)arg; + break; case CMD_USER: case CMD_USER_BUF: if (context != EXPAND_NOTHING) { @@ -5174,6 +5181,7 @@ static const char *command_complete[] = [EXPAND_CSCOPE] = "cscope", [EXPAND_USER_DEFINED] = "custom", [EXPAND_USER_LIST] = "customlist", + [EXPAND_DIFF_BUFFERS] = "diff_buffer", [EXPAND_DIRECTORIES] = "dir", [EXPAND_ENV_VARS] = "environment", [EXPAND_EVENTS] = "event", diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 4d1fd9b33f..c66ae13f53 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -5084,9 +5084,13 @@ ExpandFromContext ( } if (xp->xp_context == EXPAND_BUFFERS) return ExpandBufnames(pat, num_file, file, options); + if (xp->xp_context == EXPAND_DIFF_BUFFERS) { + return ExpandBufnames(pat, num_file, file, options | BUF_DIFF_FILTER); + } if (xp->xp_context == EXPAND_TAGS - || xp->xp_context == EXPAND_TAGS_LISTFILES) + || xp->xp_context == EXPAND_TAGS_LISTFILES) { return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); + } if (xp->xp_context == EXPAND_COLORS) { char *directories[] = { "colors", NULL }; return ExpandRTDir(pat, DIP_START + DIP_OPT, num_file, file, directories); diff --git a/src/nvim/ex_getln.h b/src/nvim/ex_getln.h index dc4395e081..3727aa5e62 100644 --- a/src/nvim/ex_getln.h +++ b/src/nvim/ex_getln.h @@ -32,6 +32,7 @@ #define WILD_IGNORE_COMPLETESLASH 0x400 #define WILD_NOERROR 0x800 // sets EW_NOERROR #define WILD_BUFLASTUSED 0x1000 +#define BUF_DIFF_FILTER 0x2000 /// Present history tables typedef enum { diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index 8a4276b2a6..dd67806953 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -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('%') diff --git a/src/nvim/vim.h b/src/nvim/vim.h index e70749795b..0245c472ef 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -158,6 +158,7 @@ enum { EXPAND_MESSAGES, EXPAND_MAPCLEAR, EXPAND_ARGLIST, + EXPAND_DIFF_BUFFERS, EXPAND_CHECKHEALTH, EXPAND_LUA, }; |