aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/ex_cmds.c38
-rw-r--r--src/nvim/ex_cmds2.c11
-rw-r--r--test/functional/ex_cmds/drop_spec.lua21
3 files changed, 56 insertions, 14 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 275feb7589..72fd009c32 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -2064,6 +2064,29 @@ theend:
return retval;
}
+/// set v:swapcommand for the SwapExists autocommands.
+///
+/// @param command [+cmd] to be executed (e.g. +10).
+/// @param newlnum if > 0: put cursor on this line number (if possible)
+//
+/// @return 1 if swapcommand was actually set, 0 otherwise
+bool set_swapcommand(char *command, linenr_T newlnum)
+{
+ if ((command == NULL && newlnum <= 0) || *get_vim_var_str(VV_SWAPCOMMAND) != NUL) {
+ return false;
+ }
+ const size_t len = (command != NULL) ? strlen(command) + 3 : 30;
+ char *const p = xmalloc(len);
+ if (command != NULL) {
+ vim_snprintf(p, len, ":%s\r", command);
+ } else {
+ vim_snprintf(p, len, "%" PRId64 "G", (int64_t)newlnum);
+ }
+ set_vim_var_string(VV_SWAPCOMMAND, p, -1);
+ xfree(p);
+ return true;
+}
+
/// start editing a new file
///
/// @param fnum file number; if zero use ffname/sfname
@@ -2197,20 +2220,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum
oldwin = NULL;
}
- if ((command != NULL || newlnum > 0)
- && *get_vim_var_str(VV_SWAPCOMMAND) == NUL) {
- // Set v:swapcommand for the SwapExists autocommands.
- const size_t len = (command != NULL) ? strlen(command) + 3 : 30;
- char *const p = xmalloc(len);
- if (command != NULL) {
- vim_snprintf(p, len, ":%s\r", command);
- } else {
- vim_snprintf(p, len, "%" PRId64 "G", (int64_t)newlnum);
- }
- set_vim_var_string(VV_SWAPCOMMAND, p, -1);
- did_set_swapcommand = true;
- xfree(p);
- }
+ did_set_swapcommand = set_swapcommand(command, newlnum);
// If we are starting to edit another file, open a (new) buffer.
// Otherwise we re-use the current buffer.
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 5bd79719e7..18206cb3c1 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -888,6 +888,17 @@ void ex_drop(exarg_T *eap)
if (curbuf->b_ml.ml_flags & ML_EMPTY) {
ex_rewind(eap);
}
+
+ // execute [+cmd]
+ if (eap->do_ecmd_cmd) {
+ bool did_set_swapcommand = set_swapcommand(eap->do_ecmd_cmd, 0);
+ do_cmdline(eap->do_ecmd_cmd, NULL, NULL, DOCMD_VERBOSE);
+ if (did_set_swapcommand) {
+ set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
+ }
+ }
+
+ // no need to execute [++opts] - they only apply for newly loaded buffers.
return;
}
}
diff --git a/test/functional/ex_cmds/drop_spec.lua b/test/functional/ex_cmds/drop_spec.lua
index d341c823b9..cd1ca978aa 100644
--- a/test/functional/ex_cmds/drop_spec.lua
+++ b/test/functional/ex_cmds/drop_spec.lua
@@ -75,4 +75,25 @@ describe(':drop', function()
:drop Xdrop_modified.txt |
]])
end)
+
+ it('jumps to line number when passed +line', function()
+ exec([[
+ edit Xdrop_line.txt
+ call append(0, "I just miss doing art. Don't you?")
+ call append(1, "It is not so hard as we have supposed.")
+ call append(2, "We are propelled by disaster. We are moving swiftly.")
+ ]])
+ feed_command('drop +2 Xdrop_line.txt')
+ screen:expect([[
+ I just miss doing art. Don't you? |
+ ^It is not so hard as we have suppos|
+ ed. |
+ We are propelled by disaster. We ar|
+ e moving swiftly. |
+ |
+ {0:~ }|*2
+ {1:Xdrop_line.txt [+] }|
+ :drop +2 Xdrop_line.txt |
+ ]])
+ end)
end)