=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-find.c,v retrieving revision 1.26 retrieving revision 1.27 diff -c -r1.26 -r1.27 *** src/usr.bin/tmux/cmd-find.c 2015/12/15 14:32:55 1.26 --- src/usr.bin/tmux/cmd-find.c 2015/12/16 21:50:37 1.27 *************** *** 1,4 **** ! /* $OpenBSD: cmd-find.c,v 1.26 2015/12/15 14:32:55 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd-find.c,v 1.27 2015/12/16 21:50:37 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott *************** *** 190,196 **** u_int ssize; struct session *s; ! if (fs->cmdq->client != NULL) { fs->s = cmd_find_try_TMUX(fs->cmdq->client, fs->w); if (fs->s != NULL) return (cmd_find_best_winlink_with_window(fs)); --- 190,196 ---- u_int ssize; struct session *s; ! if (fs->cmdq != NULL && fs->cmdq->client != NULL) { fs->s = cmd_find_try_TMUX(fs->cmdq->client, fs->w); if (fs->s != NULL) return (cmd_find_best_winlink_with_window(fs)); *************** *** 254,260 **** * sessions to those containing that pane (we still use the current * window in the best session). */ ! if (fs->cmdq->client->tty.path != NULL) { RB_FOREACH(wp, window_pane_tree, &all_window_panes) { if (strcmp(wp->tty, fs->cmdq->client->tty.path) == 0) break; --- 254,260 ---- * sessions to those containing that pane (we still use the current * window in the best session). */ ! if (fs->cmdq != NULL && fs->cmdq->client->tty.path != NULL) { RB_FOREACH(wp, window_pane_tree, &all_window_panes) { if (strcmp(wp->tty, fs->cmdq->client->tty.path) == 0) break; *************** *** 289,295 **** return (0); unknown_pane: ! fs->s = cmd_find_try_TMUX(fs->cmdq->client, NULL); if (fs->s == NULL) fs->s = cmd_find_best_session(NULL, 0, fs->flags); if (fs->s == NULL) --- 289,297 ---- return (0); unknown_pane: ! fs->s = NULL; ! if (fs->cmdq != NULL) ! fs->s = cmd_find_try_TMUX(fs->cmdq->client, NULL); if (fs->s == NULL) fs->s = cmd_find_best_session(NULL, 0, fs->flags); if (fs->s == NULL) *************** *** 310,316 **** cmd_find_current_session(struct cmd_find_state *fs) { /* If we know the current client, use it. */ ! if (fs->cmdq->client != NULL) { log_debug("%s: have client %p%s", __func__, fs->cmdq->client, fs->cmdq->client->session == NULL ? "" : " (with session)"); if (fs->cmdq->client->session == NULL) --- 312,318 ---- cmd_find_current_session(struct cmd_find_state *fs) { /* If we know the current client, use it. */ ! if (fs->cmdq != NULL && fs->cmdq->client != NULL) { log_debug("%s: have client %p%s", __func__, fs->cmdq->client, fs->cmdq->client->session == NULL ? "" : " (with session)"); if (fs->cmdq->client->session == NULL) *************** *** 860,865 **** --- 862,910 ---- log_debug("%s: idx=%d", prefix, fs->idx); else log_debug("%s: idx=none", prefix); + } + + /* Find state from a session. */ + int + cmd_find_from_session(struct cmd_find_state *fs, struct session *s) + { + cmd_find_clear_state(fs, NULL, 0); + + fs->s = s; + fs->wl = fs->s->curw; + fs->w = fs->wl->window; + fs->wp = fs->w->active; + + cmd_find_log_state(__func__, fs); + return (0); + } + + /* Find state from a window. */ + int + cmd_find_from_window(struct cmd_find_state *fs, struct window *w) + { + cmd_find_clear_state(fs, NULL, 0); + + fs->w = w; + if (cmd_find_best_session_with_window(fs) != 0) + return (-1); + if (cmd_find_best_winlink_with_window(fs) != 0) + return (-1); + + cmd_find_log_state(__func__, fs); + return (0); + } + + /* Find state from a pane. */ + int + cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp) + { + if (cmd_find_from_window(fs, wp->window) != 0) + return (-1); + fs->wp = wp; + + cmd_find_log_state(__func__, fs); + return (0); } /*