summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-new-window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-06-17 16:50:29 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-06-17 16:50:29 +0000
commitd599f43b521fb4c67be15bf2a2e218eb959f711d (patch)
tree5fa8300b7be0d0f7f8e3ef91afdaffbf259dbb02 /usr.bin/tmux/cmd-new-window.c
parent6ce537927c04b37a29c1663e0c5aa82be57bca95 (diff)
Move the shuffle code from new-window -a into a function and add a -a
flag for move-window too. From Thomas Adam.
Diffstat (limited to 'usr.bin/tmux/cmd-new-window.c')
-rw-r--r--usr.bin/tmux/cmd-new-window.c20
1 files changed, 3 insertions, 17 deletions
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index fc6cb36da22..154ef57d37c 100644
--- a/usr.bin/tmux/cmd-new-window.c
+++ b/usr.bin/tmux/cmd-new-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-window.c,v 1.45 2015/02/05 10:32:39 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.46 2015/06/17 16:50:28 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -51,7 +51,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
struct winlink *wl;
const char *cmd, *path, *template;
char **argv, *cause, *cp;
- int argc, idx, last, detached, cwd, fd = -1;
+ int argc, idx, detached, cwd, fd = -1;
struct format_tree *ft;
struct environ_entry *envent;
@@ -59,24 +59,10 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
if (wl == NULL)
return (CMD_RETURN_ERROR);
- idx = wl->idx + 1;
-
- /* Find the next free index. */
- for (last = idx; last < INT_MAX; last++) {
- if (winlink_find_by_index(&s->windows, last) == NULL)
- break;
- }
- if (last == INT_MAX) {
+ if ((idx = winlink_shuffle_up(s, wl)) == -1) {
cmdq_error(cmdq, "no free window indexes");
return (CMD_RETURN_ERROR);
}
-
- /* Move everything from last - 1 to idx up a bit. */
- for (; last > idx; last--) {
- wl = winlink_find_by_index(&s->windows, last - 1);
- server_link_window(s, wl, s, last, 0, 0, NULL);
- server_unlink_window(s, wl);
- }
} else {
idx = cmd_find_index(cmdq, args_get(args, 't'), &s);
if (idx == -2)