aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/arglist.c23
-rw-r--r--src/nvim/ex_cmds.lua6
-rw-r--r--src/nvim/testdir/test_arglist.vim29
3 files changed, 58 insertions, 0 deletions
diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c
index d19f6ed623..7d8917cc73 100644
--- a/src/nvim/arglist.c
+++ b/src/nvim/arglist.c
@@ -620,6 +620,29 @@ void ex_next(exarg_T *eap)
}
}
+/// ":argdedupe"
+void ex_argdedupe(exarg_T *eap FUNC_ATTR_UNUSED)
+{
+ for (int i = 0; i < ARGCOUNT; i++) {
+ for (int j = i + 1; j < ARGCOUNT; j++) {
+ if (FNAMECMP(ARGLIST[i].ae_fname, ARGLIST[j].ae_fname) == 0) {
+ xfree(ARGLIST[j].ae_fname);
+ memmove(ARGLIST + j, ARGLIST + j + 1,
+ (size_t)(ARGCOUNT - j - 1) * sizeof(aentry_T));
+ ARGCOUNT--;
+
+ if (curwin->w_arg_idx == j) {
+ curwin->w_arg_idx = i;
+ } else if (curwin->w_arg_idx > j) {
+ curwin->w_arg_idx--;
+ }
+
+ j--;
+ }
+ }
+ }
+}
+
/// ":argedit"
void ex_argedit(exarg_T *eap)
{
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index a5ba5e0b30..37f12a7600 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -107,6 +107,12 @@ module.cmds = {
func='ex_listdo',
},
{
+ command='argdedupe',
+ flags=TRLBAR,
+ addr_type='ADDR_NONE',
+ func='ex_argdedupe',
+ },
+ {
command='argedit',
flags=bit.bor(BANG, NEEDARG, RANGE, ZEROR, FILES, CMDARG, ARGOPT, TRLBAR),
addr_type='ADDR_ARGUMENTS',
diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim
index 0a72e38755..521c3fcd57 100644
--- a/src/nvim/testdir/test_arglist.vim
+++ b/src/nvim/testdir/test_arglist.vim
@@ -412,6 +412,35 @@ func Test_argedit()
bw! x
endfunc
+" Test for the :argdedupe command
+func Test_argdedupe()
+ call Reset_arglist()
+ argdedupe
+ call assert_equal([], argv())
+ args a a a aa b b a b aa
+ argdedupe
+ call assert_equal(['a', 'aa', 'b'], argv())
+ args a b c
+ argdedupe
+ call assert_equal(['a', 'b', 'c'], argv())
+ args a
+ argdedupe
+ call assert_equal(['a'], argv())
+ args a A b B
+ argdedupe
+ if has('fname_case')
+ call assert_equal(['a', 'A', 'b', 'B'], argv())
+ else
+ call assert_equal(['a', 'b'], argv())
+ endif
+ args a b a c a b
+ last
+ argdedupe
+ next
+ call assert_equal('c', expand('%:t'))
+ %argd
+endfunc
+
" Test for the :argdelete command
func Test_argdelete()
call Reset_arglist()