Add a base-index session option to specify the first index checked when looking

for an index for a new window.
This commit is contained in:
Nicholas Marriott 2009-08-13 20:11:58 +00:00
parent 3026118c70
commit 3ad4de6c8c
11 changed files with 40 additions and 20 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -118,7 +118,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) {
@ -216,7 +216,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);

View File

@ -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);

View File

@ -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 },

View File

@ -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);

4
tmux.1
View File

@ -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
tmux.c
View File

@ -342,6 +342,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", "");

5
tmux.h
View File

@ -1565,7 +1565,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 *);
@ -1670,7 +1670,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 *,

View File

@ -122,16 +122,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
@ -152,14 +156,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;