mirror of
https://github.com/tmux/tmux.git
synced 2026-03-13 03:32:54 +00:00
Add next/previous variables for windows in W: loop, from Conor Taylor in
GitHub issue 4856.
This commit is contained in:
42
format.c
42
format.c
@@ -4473,6 +4473,37 @@ format_window_name(struct format_expand_state *es, const char *fmt)
|
||||
return (xstrdup("0"));
|
||||
}
|
||||
|
||||
/* Add neighbor window variables to the format tree. */
|
||||
static void
|
||||
format_add_window_neighbor(struct format_tree *nft, struct winlink *wl,
|
||||
struct session *s, const char *prefix)
|
||||
{
|
||||
struct options_entry *o;
|
||||
const char *oname;
|
||||
char *key, *prefixed, *oval;
|
||||
|
||||
xasprintf(&key, "%s_window_index", prefix);
|
||||
format_add(nft, key, "%u", wl->idx);
|
||||
free(key);
|
||||
|
||||
xasprintf(&key, "%s_window_active", prefix);
|
||||
format_add(nft, key, "%d", wl == s->curw);
|
||||
free(key);
|
||||
|
||||
o = options_first(wl->window->options);
|
||||
while (o != NULL) {
|
||||
oname = options_name(o);
|
||||
if (*oname == '@') {
|
||||
xasprintf(&prefixed, "%s_%s", prefix, oname);
|
||||
oval = options_to_string(o, -1, 1);
|
||||
format_add(nft, prefixed, "%s", oval);
|
||||
free(oval);
|
||||
free(prefixed);
|
||||
}
|
||||
o = options_next(o);
|
||||
}
|
||||
}
|
||||
|
||||
/* Loop over windows. */
|
||||
static char *
|
||||
format_loop_windows(struct format_expand_state *es, const char *fmt)
|
||||
@@ -4516,6 +4547,17 @@ format_loop_windows(struct format_expand_state *es, const char *fmt)
|
||||
nft = format_create(c, item, FORMAT_WINDOW|w->id,
|
||||
ft->flags|last);
|
||||
format_defaults(nft, ft->c, ft->s, wl, NULL);
|
||||
|
||||
/* Add neighbor window data to the format tree. */
|
||||
format_add(nft, "window_after_active", "%d",
|
||||
i > 0 && l[i - 1] == ft->s->curw);
|
||||
format_add(nft, "window_before_active", "%d",
|
||||
i + 1 < n && l[i + 1] == ft->s->curw);
|
||||
if (i + 1 < n)
|
||||
format_add_window_neighbor(nft, l[i + 1], ft->s, "next");
|
||||
if (i > 0)
|
||||
format_add_window_neighbor(nft, l[i - 1], ft->s, "prev");
|
||||
|
||||
format_copy_state(&next, es, 0);
|
||||
next.ft = nft;
|
||||
expanded = format_expand1(&next, use);
|
||||
|
||||
Reference in New Issue
Block a user