diff --git a/format.c b/format.c index 4a94df8a..fd5aebcc 100644 --- a/format.c +++ b/format.c @@ -1856,15 +1856,6 @@ format_cb_keypad_flag(struct format_tree *ft) return (NULL); } -/* Callback for loop_last_flag. */ -static void * -format_cb_loop_last_flag(struct format_tree *ft) -{ - if (ft->flags & FORMAT_LAST) - return (xstrdup("1")); - return (xstrdup("0")); -} - /* Callback for mouse_all_flag. */ static void * format_cb_mouse_all_flag(struct format_tree *ft) @@ -3349,9 +3340,6 @@ static const struct format_table_entry format_table[] = { { "last_window_index", FORMAT_TABLE_STRING, format_cb_last_window_index }, - { "loop_last_flag", FORMAT_TABLE_STRING, - format_cb_loop_last_flag - }, { "mouse_all_flag", FORMAT_TABLE_STRING, format_cb_mouse_all_flag }, @@ -4686,7 +4674,7 @@ format_loop_sessions(struct format_expand_state *es, const char *fmt) struct evbuffer *buffer; size_t size; struct session *s, **l; - int i, n, last = 0; + int i, n; if (format_choose(es, fmt, &all, &active, 0) != 0) { all = xstrdup(fmt); @@ -4707,9 +4695,9 @@ format_loop_sessions(struct format_expand_state *es, const char *fmt) use = active; else use = all; - if (i == n - 1) - last = FORMAT_LAST; - nft = format_create(c, item, FORMAT_NONE, ft->flags|last); + nft = format_create(c, item, FORMAT_NONE, ft->flags); + format_add(nft, "loop_index", "%d", i); + format_add(nft, "loop_last_flag", "%d", i == n - 1); format_defaults(nft, ft->c, s, NULL, NULL); format_copy_state(&next, es, 0); next.ft = nft; @@ -4801,7 +4789,7 @@ format_loop_windows(struct format_expand_state *es, const char *fmt) size_t size; struct winlink *wl, **l; struct window *w; - int i, n, last = 0; + int i, n; if (ft->s == NULL) { format_log(es, "window loop but no session"); @@ -4826,10 +4814,10 @@ format_loop_windows(struct format_expand_state *es, const char *fmt) use = active; else use = all; - if (i == n - 1) - last = FORMAT_LAST; nft = format_create(c, item, FORMAT_WINDOW|w->id, - ft->flags|last); + ft->flags); + format_add(nft, "loop_index", "%d", i); + format_add(nft, "loop_last_flag", "%d", i == n - 1); format_defaults(nft, ft->c, ft->s, wl, NULL); /* Add neighbor window data to the format tree. */ @@ -4876,7 +4864,7 @@ format_loop_panes(struct format_expand_state *es, const char *fmt) struct evbuffer *buffer; size_t size; struct window_pane *wp, **l; - int i, n, last = 0; + int i, n; if (ft->w == NULL) { format_log(es, "pane loop but no window"); @@ -4900,10 +4888,10 @@ format_loop_panes(struct format_expand_state *es, const char *fmt) use = active; else use = all; - if (i == n - 1) - last = FORMAT_LAST; nft = format_create(c, item, FORMAT_PANE|wp->id, - ft->flags|last); + ft->flags); + format_add(nft, "loop_index", "%d", i); + format_add(nft, "loop_last_flag", "%d", i == n - 1); format_defaults(nft, ft->c, ft->s, ft->wl, wp); format_copy_state(&next, es, 0); next.ft = nft; @@ -4938,7 +4926,7 @@ format_loop_clients(struct format_expand_state *es, const char *fmt) char *expanded, *value; struct evbuffer *buffer; size_t size; - int i, n, last = 0; + int i, n; buffer = evbuffer_new(); if (buffer == NULL) @@ -4948,9 +4936,9 @@ format_loop_clients(struct format_expand_state *es, const char *fmt) for (i = 0; i < n; i++) { c = l[i]; format_log(es, "client loop: %s", c->name); - if (i == n - 1) - last = FORMAT_LAST; - nft = format_create(c, item, 0, ft->flags|last); + nft = format_create(c, item, 0, ft->flags); + format_add(nft, "loop_index", "%d", i); + format_add(nft, "loop_last_flag", "%d", i == n - 1); format_defaults(nft, c, ft->s, ft->wl, ft->wp); format_copy_state(&next, es, 0); next.ft = nft; diff --git a/key-bindings.c b/key-bindings.c index e8fff304..5a2c3d96 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -25,11 +25,10 @@ #include "tmux.h" #define DEFAULT_SESSION_MENU \ - " 'Next' 'n' {switch-client -n}" \ - " 'Previous' 'p' {switch-client -p}" \ + " #{S/t:#{?#{&&:#{<:#{loop_index},6},#{!:#{session_active}}},'Switch To #[underscore]#{session_name}' '' {switch-client -t=#{session_id}#} ,}}" \ " ''" \ " 'Renumber' 'N' {move-window -r}" \ - " 'Rename' 'r' {command-prompt -I \"#S\" {rename-session -- '%%'}}" \ + " 'Rename' 'r' {command-prompt -I '#S' {rename-session -- '%%'}}" \ " 'Detach' 'd' {detach-client}" \ " ''" \ " 'New Session' 's' {new-session}" \ @@ -486,8 +485,8 @@ key_bindings_init(void) "bind -n WheelUpStatus { previous-window }", /* Mouse button 3 down on status left. */ - "bind -n MouseDown3StatusLeft { display-menu -t= -xM -yW -T '#[align=centre]#{session_name}' " DEFAULT_SESSION_MENU " }", - "bind -n M-MouseDown3StatusLeft { display-menu -t= -xM -yW -T '#[align=centre]#{session_name}' " DEFAULT_SESSION_MENU " }", + "bind -n MouseDown3StatusLeft { run -C \"display-menu -t= -xM -yW -T '#[align=centre]#{session_name}' " DEFAULT_SESSION_MENU "\" }", + "bind -n M-MouseDown3StatusLeft { run -C \"display-menu -t= -xM -yW -T '#[align=centre]#{session_name}' " DEFAULT_SESSION_MENU "\" }", /* Mouse button 3 down on status line. */ "bind -n MouseDown3Status { display-menu -t= -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU "}", diff --git a/tmux.1 b/tmux.1 index 7d9455e2..84ac0dbe 100644 --- a/tmux.1 +++ b/tmux.1 @@ -6776,6 +6776,7 @@ The following variables are available, where appropriate: .It Li "keypad_flag" Ta "" Ta "Pane keypad flag" .It Li "last_window_index" Ta "" Ta "Index of last window in session" .It Li "line" Ta "" Ta "Line number in the list" +.It Li "loop_index" Ta "" Ta "Index of item in the W:, P:, S:, or L: loop" .It Li "loop_last_flag" Ta "" Ta "1 if last window, pane, session, client in the W:, P:, S:, or L: loop" .It Li "mouse_all_flag" Ta "" Ta "Pane mouse all flag" .It Li "mouse_any_flag" Ta "" Ta "Pane mouse any flag"