diff options
-rw-r--r-- | cmd-break-pane.c | 6 | ||||
-rw-r--r-- | cmd-link-window.c | 4 | ||||
-rw-r--r-- | cmd-move-window.c | 4 | ||||
-rw-r--r-- | cmd-new-session.c | 8 | ||||
-rw-r--r-- | cmd-new-window.c | 4 | ||||
-rw-r--r-- | cmd-set-option.c | 3 | ||||
-rw-r--r-- | session.c | 9 | ||||
-rw-r--r-- | tmux.1 | 6 | ||||
-rw-r--r-- | tmux.c | 3 | ||||
-rw-r--r-- | tmux.h | 7 | ||||
-rw-r--r-- | window.c | 28 |
11 files changed, 51 insertions, 31 deletions
diff --git a/cmd-break-pane.c b/cmd-break-pane.c index e88378ca..63e4c6a9 100644 --- a/cmd-break-pane.c +++ b/cmd-break-pane.c @@ -1,4 +1,4 @@ -/* $Id: cmd-break-pane.c,v 1.7 2009-07-30 20:45:20 tcunha Exp $ */ +/* $Id: cmd-break-pane.c,v 1.8 2009-08-16 19:16:27 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -48,6 +48,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx) struct window_pane *wp; struct window *w; char *cause; + int base_idx; if ((wl = cmd_find_pane(ctx, data->target, &s, &wp)) == NULL) return (-1); @@ -71,7 +72,8 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx) w->name = default_window_name(w); layout_init(w); - wl = session_attach(s, w, -1, &cause); /* can't fail */ + base_idx = options_get_number(&s->options, "base-index"); + wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */ if (!(data->chflags & CMD_CHFLAG('d'))) session_select(s, wl->idx); diff --git a/cmd-link-window.c b/cmd-link-window.c index 39cb5d26..7ab2a5d9 100644 --- a/cmd-link-window.c +++ b/cmd-link-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-link-window.c,v 1.31 2009-07-28 22:12:16 tcunha Exp $ */ +/* $Id: cmd-link-window.c,v 1.32 2009-08-16 19:16:27 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -77,6 +77,8 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx) } } + if (idx == -1) + idx = -1 - options_get_number(&dst->options, "base-index"); wl_dst = session_attach(dst, wl_src->window, idx, &cause); if (wl_dst == NULL) { ctx->error(ctx, "create session failed: %s", cause); diff --git a/cmd-move-window.c b/cmd-move-window.c index c0ee7bdf..941ffd57 100644 --- a/cmd-move-window.c +++ b/cmd-move-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-move-window.c,v 1.8 2009-07-28 22:12:16 tcunha Exp $ */ +/* $Id: cmd-move-window.c,v 1.9 2009-08-16 19:16:27 tcunha Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -79,6 +79,8 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx) } } + if (idx == -1) + idx = -1 - options_get_number(&dst->options, "base-index"); wl_dst = session_attach(dst, wl_src->window, idx, &cause); if (wl_dst == NULL) { ctx->error(ctx, "attach window failed: %s", cause); diff --git a/cmd-new-session.c b/cmd-new-session.c index 6324030f..53800eda 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-new-session.c,v 1.54 2009-08-16 19:07:40 tcunha Exp $ */ +/* $Id: cmd-new-session.c,v 1.55 2009-08-16 19:16:27 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -119,7 +119,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) struct termios tio; const char *update; char *overrides, *cmd, *cwd, *cause; - int detached; + int detached, idx; u_int sx, sy; if (data->newname != NULL && session_find(data->newname) != NULL) { @@ -217,7 +217,9 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) tio.c_ospeed = TTYDEF_SPEED; /* Create the new session. */ - s = session_create(data->newname, cmd, cwd, &env, &tio, sx, sy, &cause); + idx = -1 - options_get_number(&global_s_options, "base-index"); + s = session_create( + data->newname, cmd, cwd, &env, &tio, idx, sx, sy, &cause); if (s == NULL) { ctx->error(ctx, "create session failed: %s", cause); xfree(cause); diff --git a/cmd-new-window.c b/cmd-new-window.c index 243ce990..7f304a59 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-new-window.c,v 1.36 2009-07-28 22:12:16 tcunha Exp $ */ +/* $Id: cmd-new-window.c,v 1.37 2009-08-16 19:16:27 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -154,6 +154,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) else cwd = ctx->cmdclient->cwd; + if (idx == -1) + idx = -1 - options_get_number(&s->options, "base-index"); wl = session_new(s, data->name, cmd, cwd, idx, &cause); if (wl == NULL) { ctx->error(ctx, "create window failed: %s", cause); diff --git a/cmd-set-option.c b/cmd-set-option.c index ec07ad25..d938d732 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.75 2009-08-11 14:42:59 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.76 2009-08-16 19:16:27 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -50,6 +50,7 @@ const char *set_option_bell_action_list[] = { "none", "any", "current", NULL }; const struct set_option_entry set_option_table[] = { + { "base-index", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, { "bell-action", SET_OPTION_CHOICE, 0, 0, set_option_bell_action_list }, { "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL }, { "default-command", SET_OPTION_STRING, 0, 0, NULL }, @@ -1,4 +1,4 @@ -/* $Id: session.c,v 1.61 2009-08-16 18:59:12 tcunha Exp $ */ +/* $Id: session.c,v 1.62 2009-08-16 19:16:27 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -113,7 +113,8 @@ session_find(const char *name) /* Create a new session. */ struct session * session_create(const char *name, const char *cmd, const char *cwd, - struct environ *env, struct termios *tio, u_int sx, u_int sy, char **cause) + struct environ *env, struct termios *tio, int idx, u_int sx, u_int sy, + char **cause) { struct session *s; u_int i; @@ -149,11 +150,11 @@ session_create(const char *name, const char *cmd, const char *cwd, s->name = xstrdup(name); else xasprintf(&s->name, "%u", i); - if (session_new(s, NULL, cmd, cwd, -1, cause) == NULL) { + if (session_new(s, NULL, cmd, cwd, idx, cause) == NULL) { session_destroy(s); return (NULL); } - session_select(s, 0); + session_select(s, RB_ROOT(&s->windows)->idx); log_debug("session %s created", s->name); @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.150 2009-08-16 18:59:12 tcunha Exp $ +.\" $Id: tmux.1,v 1.151 2009-08-16 19:16:27 tcunha Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -1064,6 +1064,10 @@ options - it is not possible to unset a global option. .Pp Available session options are: .Bl -tag -width Ds +.It Ic base-index Ar index +Set the base index from which an unused index should be searched when a new +window is created. +The default is zero. .It Xo Ic bell-action .Op Ic any | none | current .Xc @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.161 2009-08-14 21:28:00 tcunha Exp $ */ +/* $Id: tmux.c,v 1.162 2009-08-16 19:16:27 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -351,6 +351,7 @@ main(int argc, char **argv) } options_init(&global_s_options, NULL); + options_set_number(&global_s_options, "base-index", 0); options_set_number(&global_s_options, "bell-action", BELL_ANY); options_set_number(&global_s_options, "buffer-limit", 9); options_set_string(&global_s_options, "default-command", "%s", ""); @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.416 2009-08-16 18:59:12 tcunha Exp $ */ +/* $Id: tmux.h,v 1.417 2009-08-16 19:16:27 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1563,7 +1563,7 @@ RB_PROTOTYPE(windows, window, entry, window_cmp); RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp); struct winlink *winlink_find_by_index(struct winlinks *, int); struct winlink *winlink_find_by_window(struct winlinks *, struct window *); -int winlink_next_index(struct winlinks *); +int winlink_next_index(struct winlinks *, int); u_int winlink_count(struct winlinks *); struct winlink *winlink_add(struct winlinks *, struct window *, int); void winlink_remove(struct winlinks *, struct winlink *); @@ -1668,7 +1668,8 @@ int session_alert_has(struct session *, struct winlink *, int); int session_alert_has_window(struct session *, struct window *, int); struct session *session_find(const char *); struct session *session_create(const char *, const char *, const char *, - struct environ *, struct termios *, u_int, u_int, char **); + struct environ *, struct termios *, int, u_int, u_int, + char **); void session_destroy(struct session *); int session_index(struct session *, u_int *); struct winlink *session_new(struct session *, @@ -1,4 +1,4 @@ -/* $Id: window.c,v 1.103 2009-08-16 18:59:12 tcunha Exp $ */ +/* $Id: window.c,v 1.104 2009-08-16 19:16:27 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -120,16 +120,20 @@ winlink_find_by_index(struct winlinks *wwl, int idx) } int -winlink_next_index(struct winlinks *wwl) +winlink_next_index(struct winlinks *wwl, int idx) { - u_int i; + int i; - for (i = 0; i < INT_MAX; i++) { + i = idx; + do { if (winlink_find_by_index(wwl, i) == NULL) return (i); - } - - fatalx("no free indexes"); + if (i == INT_MAX) + i = 0; + else + i++; + } while (i != idx); + return (-1); } u_int @@ -150,14 +154,12 @@ winlink_add(struct winlinks *wwl, struct window *w, int idx) { struct winlink *wl; - if (idx == -1) - idx = winlink_next_index(wwl); - else if (winlink_find_by_index(wwl, idx) != NULL) + if (idx < 0) { + if ((idx = winlink_next_index(wwl, -idx - 1)) == -1) + return (NULL); + } else if (winlink_find_by_index(wwl, idx) != NULL) return (NULL); - if (idx < 0) - fatalx("bad index"); - wl = xcalloc(1, sizeof *wl); wl->idx = idx; wl->window = w; |