aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_cmds2.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-12-19 01:06:40 -0500
committerJustin M. Keyes <justinkz@gmail.com>2014-12-19 01:06:40 -0500
commite47105c47dd8436149ad38cbea0587a331490db4 (patch)
treee8132f1167ae14c11c0b4d9d1b015f728ea105e8 /src/nvim/ex_cmds2.c
parentb1cd16ab8def3828ace87339c5117e8b9e6f4fed (diff)
parent4a3b3d2913ea1d3268f15fe5d72022ed10c85166 (diff)
downloadrneovim-e47105c47dd8436149ad38cbea0587a331490db4.tar.gz
rneovim-e47105c47dd8436149ad38cbea0587a331490db4.tar.bz2
rneovim-e47105c47dd8436149ad38cbea0587a331490db4.zip
Merge pull request #1638 from Grimy/ex-drop
Reimplement :drop
Diffstat (limited to 'src/nvim/ex_cmds2.c')
-rw-r--r--src/nvim/ex_cmds2.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index fa78047a46..072972d24e 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -3291,3 +3291,79 @@ static void script_host_do_range(char *name, exarg_T *eap)
(void)eval_call_provider(name, "do_range", args);
}
+/*
+ * ":drop"
+ * Opens the first argument in a window. When there are two or more arguments
+ * the argument list is redefined.
+ */
+void ex_drop(exarg_T *eap)
+{
+ int split = FALSE;
+ buf_T *buf;
+
+ /*
+ * Check if the first argument is already being edited in a window. If
+ * so, jump to that window.
+ * We would actually need to check all arguments, but that's complicated
+ * and mostly only one file is dropped.
+ * This also ignores wildcards, since it is very unlikely the user is
+ * editing a file name with a wildcard character.
+ */
+ do_arglist(eap->arg, AL_SET, 0);
+
+ /*
+ * Expanding wildcards may result in an empty argument list. E.g. when
+ * editing "foo.pyc" and ".pyc" is in 'wildignore'. Assume that we
+ * already did an error message for this.
+ */
+ if (ARGCOUNT == 0)
+ return;
+
+ if (cmdmod.tab)
+ {
+ /* ":tab drop file ...": open a tab for each argument that isn't
+ * edited in a window yet. It's like ":tab all" but without closing
+ * windows or tabs. */
+ ex_all(eap);
+ }
+ else
+ {
+ /* ":drop file ...": Edit the first argument. Jump to an existing
+ * window if possible, edit in current window if the current buffer
+ * can be abandoned, otherwise open a new window. */
+ buf = buflist_findnr(ARGLIST[0].ae_fnum);
+
+ FOR_ALL_TAB_WINDOWS(tp, wp)
+ {
+ if (wp->w_buffer == buf)
+ {
+ goto_tabpage_win(tp, wp);
+ curwin->w_arg_idx = 0;
+ return;
+ }
+ }
+
+ /*
+ * Check whether the current buffer is changed. If so, we will need
+ * to split the current window or data could be lost.
+ * Skip the check if the 'hidden' option is set, as in this case the
+ * buffer won't be lost.
+ */
+ if (!P_HID(curbuf))
+ {
+ ++emsg_off;
+ split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD);
+ --emsg_off;
+ }
+
+ /* Fake a ":sfirst" or ":first" command edit the first argument. */
+ if (split)
+ {
+ eap->cmdidx = CMD_sfirst;
+ eap->cmd[0] = 's';
+ }
+ else
+ eap->cmdidx = CMD_first;
+ ex_rewind(eap);
+ }
+}