summaryrefslogtreecommitdiff
path: root/src/ex_cmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r--src/ex_cmds.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 22bbd45dd..d86084bbd 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2962,6 +2962,7 @@ do_ecmd(fnum, ffname, sfname, eap, newlnum, flags)
int auto_buf = FALSE; /* TRUE if autocommands brought us
into the buffer unexpectedly */
char_u *new_name = NULL;
+ int did_set_swapcommand = FALSE;
#endif
buf_T *buf;
#if defined(FEAT_AUTOCMD) || defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
@@ -3082,6 +3083,32 @@ do_ecmd(fnum, ffname, sfname, eap, newlnum, flags)
reset_VIsual();
#endif
+#ifdef FEAT_AUTOCMD
+ if ((command != NULL || newlnum > (linenr_T)0)
+ && *get_vim_var_str(VV_SWAPCOMMAND) == NUL)
+ {
+ int len;
+ char_u *p;
+
+ /* Set v:swapcommand for the SwapExists autocommands. */
+ if (command != NULL)
+ len = STRLEN(command) + 3;
+ else
+ len = 30;
+ p = alloc((unsigned)len);
+ if (p != NULL)
+ {
+ if (command != NULL)
+ vim_snprintf((char *)p, len, ":%s\r", command);
+ else
+ vim_snprintf((char *)p, len, "%ldG", (long)newlnum);
+ set_vim_var_string(VV_SWAPCOMMAND, p, -1);
+ did_set_swapcommand = TRUE;
+ vim_free(p);
+ }
+ }
+#endif
+
/*
* If we are starting to edit another file, open a (new) buffer.
* Otherwise we re-use the current buffer.
@@ -3619,6 +3646,10 @@ do_ecmd(fnum, ffname, sfname, eap, newlnum, flags)
#endif
theend:
+#ifdef FEAT_AUTOCMD
+ if (did_set_swapcommand)
+ set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
+#endif
#ifdef FEAT_BROWSE
vim_free(browse_file);
#endif