diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-04-29 17:20:02 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-04-29 17:20:02 +0000 |
commit | b8dfd6d443fe0eb19bd5b597571bc54cfe18f7b3 (patch) | |
tree | 85735d408e3d2345056badccfd85fd43f3b2c19f /usr.bin | |
parent | 2b04d517c44102b6892069ec986f7d932eebd253 (diff) |
Add a flag to move-window to renumber the windows in a session (closing
any gaps) and add an option to do this automatically each time a window
is killed. From Thomas Adam.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-move-window.c | 19 | ||||
-rw-r--r-- | usr.bin/tmux/options-table.c | 7 | ||||
-rw-r--r-- | usr.bin/tmux/server-fn.c | 5 | ||||
-rw-r--r-- | usr.bin/tmux/session.c | 48 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 21 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 |
6 files changed, 92 insertions, 11 deletions
diff --git a/usr.bin/tmux/cmd-move-window.c b/usr.bin/tmux/cmd-move-window.c index be71f0c10b3..070e548b5b2 100644 --- a/usr.bin/tmux/cmd-move-window.c +++ b/usr.bin/tmux/cmd-move-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-move-window.c,v 1.10 2011/01/04 00:42:47 nicm Exp $ */ +/* $OpenBSD: cmd-move-window.c,v 1.11 2012/04/29 17:20:01 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -30,8 +30,8 @@ int cmd_move_window_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_move_window_entry = { "move-window", "movew", - "dks:t:", 0, 0, - "[-dk] " CMD_SRCDST_WINDOW_USAGE, + "dkrs:t:", 0, 0, + "[-dkr] " CMD_SRCDST_WINDOW_USAGE, 0, NULL, NULL, @@ -42,11 +42,22 @@ int cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; - struct session *src, *dst; + struct session *src, *dst, *s; struct winlink *wl; char *cause; int idx, kflag, dflag; + if ((s = ctx->curclient->session) == NULL) + return (-1); + + if (args_has(args, 'r')) + { + session_renumber_windows(s); + recalculate_sizes(); + + return (0); + } + if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL) return (-1); if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2) diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c index c7bacdf9287..79a3ad60279 100644 --- a/usr.bin/tmux/options-table.c +++ b/usr.bin/tmux/options-table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-table.c,v 1.28 2012/04/23 22:23:14 nicm Exp $ */ +/* $OpenBSD: options-table.c,v 1.29 2012/04/29 17:20:01 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net> @@ -274,6 +274,11 @@ const struct options_table_entry session_options_table[] = { .default_num = KEYC_NONE, }, + { .name = "renumber-windows", + .type = OPTIONS_TABLE_FLAG, + .default_num = 0 + }, + { .name = "repeat-time", .type = OPTIONS_TABLE_NUMBER, .minimum = 0, diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index 3715df94bdc..d4406e261b3 100644 --- a/usr.bin/tmux/server-fn.c +++ b/usr.bin/tmux/server-fn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-fn.c,v 1.55 2012/03/17 22:35:09 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.56 2012/04/29 17:20:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -263,6 +263,9 @@ server_kill_window(struct window *w) } else server_redraw_session_group(s); } + + if (options_get_number(&s->options, "renumber-windows")) + session_renumber_windows(s); } } diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 2476a9ae249..e4882e35dcf 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.33 2012/03/17 22:35:09 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.34 2012/04/29 17:20:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -591,3 +591,49 @@ session_group_synchronize1(struct session *target, struct session *s) winlink_remove(&old_windows, wl); } } + +/* Renumber the windows across winlinks attached to a specific session. */ +void +session_renumber_windows(struct session *s) +{ + struct winlink *wl, *wl1, *wl_new; + struct winlinks old_wins; + struct winlink_stack old_lastw; + int new_idx, new_curw_idx; + + /* Save and replace old window list. */ + memcpy(&old_wins, &s->windows, sizeof old_wins); + RB_INIT(&s->windows); + + /* Start renumbering from the base-index if it's set. */ + new_idx = options_get_number(&s->options, "base-index"); + new_curw_idx = 0; + + /* Go through the winlinks and assign new indexes. */ + RB_FOREACH(wl, winlinks, &old_wins) { + wl_new = winlink_add(&s->windows, new_idx); + winlink_set_window(wl_new, wl->window); + wl_new->flags |= wl->flags & WINLINK_ALERTFLAGS; + + if (wl == s->curw) + new_curw_idx = wl_new->idx; + + new_idx++; + } + + /* Fix the stack of last windows now. */ + memcpy(&old_lastw, &s->lastw, sizeof old_lastw); + TAILQ_INIT(&s->lastw); + TAILQ_FOREACH(wl, &old_lastw, sentry) { + wl_new = winlink_find_by_index(&s->windows, wl->idx); + if (wl_new != NULL) + TAILQ_INSERT_TAIL(&s->lastw, wl_new, sentry); + } + + /* Set the current window. */ + s->curw = winlink_find_by_index(&s->windows, new_curw_idx); + + /* Free the old winlinks (reducing window references too). */ + RB_FOREACH_SAFE(wl, winlinks, &old_wins, wl1) + winlink_remove(&old_wins, wl); +} diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 1b86de9bbf4..4a8fa047937 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.290 2012/04/23 22:23:14 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.291 2012/04/29 17:20:01 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 23 2012 $ +.Dd $Mdocdate: April 29 2012 $ .Dt TMUX 1 .Os .Sh NAME @@ -1258,7 +1258,7 @@ and .Ar dst-pane may belong to the same window. .It Xo Ic move-window -.Op Fl dk +.Op Fl rdk .Op Fl s Ar src-window .Op Fl t Ar dst-window .Xc @@ -1269,6 +1269,12 @@ except the window at .Ar src-window is moved to .Ar dst-window . +With +.Fl r , +all windows in the session are renumbered in sequential order, respecting +the +.Ic base-index +option. .It Xo Ic new-window .Op Fl adkP .Op Fl c Ar start-directory @@ -2122,6 +2128,15 @@ Set the pane border colour for panes aside from the active pane. Set the key accepted as a prefix key. .It Ic prefix2 Ar key Set a secondary key accepted as a prefix key. +.It Xo Ic renumber-windows +.Op Ic on | off +.Xc +If on, when a window is closed in a session, automatically renumber the other +windows in numerical order. +This respects the +.Ic base-index +option if it has been set. +If off, do not renumber the windows. .It Ic repeat-time Ar time Allow multiple commands to be entered without pressing the prefix-key again in the specified diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 70b10baf7fa..dda6c1968e8 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.329 2012/04/25 21:12:49 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.330 2012/04/29 17:20:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -2116,6 +2116,7 @@ void session_group_remove(struct session *); void session_group_synchronize_to(struct session *); void session_group_synchronize_from(struct session *); void session_group_synchronize1(struct session *, struct session *); +void session_renumber_windows(struct session *); /* utf8.c */ void utf8_build(void); |