On Mon, Apr 23, 2012 at 11:25:28PM +0100, Nicholas Marriott wrote:
> Do we need a command at all or is the option enough?
Well, I can already see people wanting both, and I see both as light-weight,
especially since both code-paths between a flag to move-window and a session
option call the same function.
> If a manual trigger is really useful, could this be a flag to
> move-window?
I've added it as a flag to move-window (-r). See patch attached.
-- Thomas Adam
--
"Deep in my heart I wish I was wrong. But deep in my heart I know I am
not." -- Morrissey ("Girl Least Likely To" -- off of Viva Hate.)
This adds a new flag (-r) to move-window, a new session option
renumber-windows, and updates the man page.
---
trunk/cmd-move-window.c | 17 ++++++++++++++---
trunk/options-table.c | 5 +++++
trunk/server-fn.c | 5 +++++
trunk/session.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
trunk/tmux.1 | 17 ++++++++++++++++-
trunk/tmux.h | 1 +
6 files changed, 86 insertions(+), 4 deletions(-)
diff --git a/trunk/cmd-move-window.c b/trunk/cmd-move-window.c
index 5c4dbbe..acb5044 100644
--- a/trunk/cmd-move-window.c
+++ b/trunk/cmd-move-window.c
@@ -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/trunk/options-table.c b/trunk/options-table.c
index c03295f..8ce838a 100644
--- a/trunk/options-table.c
+++ b/trunk/options-table.c
@@ -273,6 +273,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/trunk/server-fn.c b/trunk/server-fn.c
index 4136bbb..32407b8 100644
--- a/trunk/server-fn.c
+++ b/trunk/server-fn.c
@@ -263,6 +263,11 @@ server_kill_window(struct window *w)
} else
server_redraw_session_group(s);
}
+
+ /* Renumber all windows if we've been asked to. */
+ if (options_get_number(&s->options,
+ "renumber-windows"))
+ session_renumber_windows(s);
}
}
diff --git a/trunk/session.c b/trunk/session.c
index be86197..966de4c 100644
--- a/trunk/session.c
+++ b/trunk/session.c
@@ -590,3 +590,48 @@ session_group_synchronize1(struct session *target, struct session *s)
winlink_remove(&old_windows, wl);
}
}
+
+/* Renumber the windows across winlinks attached to a specific session. */
+int
+session_renumber_windows(struct session *s)
+{
+ struct winlink *wl, *wl_new;
+ struct winlinks old_wins;
+ struct winlink_stack old_lastw;
+ int new_idx = 0, new_curw_idx = 0;
+
+ if (s == NULL)
+ return (-1);
+
+ 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");
+
+ /* 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 that the IDs have changed. */
+ 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 per the new id. */
+ s->curw = winlink_find_by_index(&s->windows, new_curw_idx);
+
+ return (0);
+}
diff --git a/trunk/tmux.1 b/trunk/tmux.1
index 8e3ceda..66599ab 100644
--- a/trunk/tmux.1
+++ b/trunk/tmux.1
@@ -1262,7 +1262,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
@@ -1273,6 +1273,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
@@ -2126,6 +2132,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/trunk/tmux.h b/trunk/tmux.h
index 8aaf042..2f824ff 100644
--- a/trunk/tmux.h
+++ b/trunk/tmux.h
@@ -2106,6 +2106,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 *);
+int session_renumber_windows(struct session *);
/* utf8.c */
void utf8_build(void);
--
1.7.10
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users