From ca6a121e63c61eb45a81dc7318ed290b8dca45e6 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 3 May 2017 05:53:34 +0000 Subject: [PATCH] Add a format for the last search string in copy mode and fix the prompt so it can work when in -I, suggested by Suraj N Kurapati. --- format.c | 2 ++ status.c | 8 +++++++- tmux.1 | 1 + tmux.h | 1 + window-copy.c | 13 +++++++++++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/format.c b/format.c index baece4b0..133ab779 100644 --- a/format.c +++ b/format.c @@ -1346,6 +1346,8 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base); format_add(ft, "pane_synchronized", "%d", !!options_get_number(wp->window->options, "synchronize-panes")); + format_add(ft, "pane_search_string", "%s", + window_copy_search_string(wp)); format_add(ft, "pane_tty", "%s", wp->tty); format_add(ft, "pane_pid", "%ld", (long) wp->pid); diff --git a/status.c b/status.c index 077c2bf1..6a35529d 100644 --- a/status.c +++ b/status.c @@ -661,7 +661,7 @@ status_prompt_set(struct client *c, const char *msg, const char *input, { struct format_tree *ft; time_t t; - char *tmp; + char *tmp, *cp; ft = format_create(c, NULL, FORMAT_NONE, 0); format_defaults(ft, c, NULL, NULL, NULL); @@ -690,6 +690,12 @@ status_prompt_set(struct client *c, const char *msg, const char *input, c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE); c->flags |= CLIENT_STATUS; + if ((flags & PROMPT_INCREMENTAL) && *tmp != '\0') { + xasprintf(&cp, "=%s", tmp); + c->prompt_callbackfn(c->prompt_data, cp, 0); + free(cp); + } + free(tmp); format_free(ft); } diff --git a/tmux.1 b/tmux.1 index fe251802..1258c6d3 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3563,6 +3563,7 @@ The following variables are available, where appropriate: .It Li "pane_left" Ta "" Ta "Left of pane" .It Li "pane_pid" Ta "" Ta "PID of first process in pane" .It Li "pane_right" Ta "" Ta "Right of pane" +.It Li "pane_search_string" Ta "" Ta "Last search string in copy mode" .It Li "pane_start_command" Ta "" Ta "Command pane started with" .It Li "pane_synchronized" Ta "" Ta "If pane is synchronized" .It Li "pane_tabs" Ta "" Ta "Pane tab positions" diff --git a/tmux.h b/tmux.h index 276636e8..65b22284 100644 --- a/tmux.h +++ b/tmux.h @@ -2171,6 +2171,7 @@ void window_copy_vadd(struct window_pane *, const char *, va_list); void window_copy_pageup(struct window_pane *, int); void window_copy_start_drag(struct client *, struct mouse_event *); int window_copy_scroll_position(struct window_pane *); +const char *window_copy_search_string(struct window_pane *); /* window-choose.c */ extern const struct window_mode window_choose_mode; diff --git a/window-copy.c b/window-copy.c index 0896479a..7def63db 100644 --- a/window-copy.c +++ b/window-copy.c @@ -2480,3 +2480,16 @@ window_copy_drag_update(__unused struct client *c, struct mouse_event *m) if (window_copy_update_selection(wp, 1)) window_copy_redraw_selection(wp, old_cy); } + +const char * +window_copy_search_string(struct window_pane *wp) +{ + struct window_copy_mode_data *data; + + if (wp->mode != &window_copy_mode) + return (""); + data = wp->modedata; + if (data->searchtype == WINDOW_COPY_OFF || data->searchstr == NULL) + return (""); + return (data->searchstr); +}