summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/window-copy.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-06-11 19:43:35 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-06-11 19:43:35 +0000
commit8ded41f4dce6cca9ba06b21d71a5d91a207dc45e (patch)
tree853c006863e290cababda6eaee1bece7b0e9a6ef /usr.bin/tmux/window-copy.c
parent96fe3476dc8d86b7171b8a0b8b3f55d7acb58cf2 (diff)
Add some formats for search in copy mode (search_present, search_match).
GitHub issue 2268.
Diffstat (limited to 'usr.bin/tmux/window-copy.c')
-rw-r--r--usr.bin/tmux/window-copy.c63
1 files changed, 43 insertions, 20 deletions
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index 2e5552e47ed..0b15007665b 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.298 2020/06/05 07:44:42 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.299 2020/06/11 19:43:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -26,6 +26,8 @@
#include "tmux.h"
+struct window_copy_mode_data;
+
static const char *window_copy_key_table(struct window_mode_entry *);
static void window_copy_command(struct window_mode_entry *, struct client *,
struct session *, struct winlink *, struct args *,
@@ -42,7 +44,6 @@ static void window_copy_pageup1(struct window_mode_entry *, int);
static int window_copy_pagedown(struct window_mode_entry *, int, int);
static void window_copy_next_paragraph(struct window_mode_entry *);
static void window_copy_previous_paragraph(struct window_mode_entry *);
-
static void window_copy_redraw_selection(struct window_mode_entry *, u_int);
static void window_copy_redraw_lines(struct window_mode_entry *, u_int,
u_int);
@@ -51,7 +52,7 @@ static void window_copy_write_line(struct window_mode_entry *,
struct screen_write_ctx *, u_int);
static void window_copy_write_lines(struct window_mode_entry *,
struct screen_write_ctx *, u_int, u_int);
-
+static char *window_copy_match_at_cursor(struct window_copy_mode_data *);
static void window_copy_scroll_to(struct window_mode_entry *, u_int, u_int,
int);
static int window_copy_search_compare(struct grid *, u_int, u_int,
@@ -60,13 +61,13 @@ static int window_copy_search_lr(struct grid *, struct grid *, u_int *,
u_int, u_int, u_int, int);
static int window_copy_search_rl(struct grid *, struct grid *, u_int *,
u_int, u_int, u_int, int);
-static int window_copy_last_regex(struct grid *gd, u_int py, u_int first,
- u_int last, u_int len, u_int *ppx, u_int *psx,
- const char *buf, const regex_t *preg, int eflags);
+static int window_copy_last_regex(struct grid *, u_int, u_int, u_int,
+ u_int, u_int *, u_int *, const char *, const regex_t *,
+ int);
static char *window_copy_stringify(struct grid *, u_int, u_int, u_int,
char *, u_int *);
-static void window_copy_cstrtocellpos(struct grid *, u_int, u_int *, u_int *,
- const char *str);
+static void window_copy_cstrtocellpos(struct grid *, u_int, u_int *,
+ u_int *, const char *);
static int window_copy_search_marks(struct window_mode_entry *,
struct screen *, int, int);
static void window_copy_clear_marks(struct window_mode_entry *);
@@ -702,12 +703,40 @@ window_copy_get_line(struct window_pane *wp, u_int y)
return (format_grid_line(gd, gd->hsize + y));
}
+static char *
+window_copy_cursor_word_cb(struct format_tree *ft)
+{
+ struct window_pane *wp = format_get_pane(ft);
+ struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
+ struct window_copy_mode_data *data = wme->data;
+
+ return (window_copy_get_word(wp, data->cx, data->cy));
+}
+
+static char *
+window_copy_cursor_line_cb(struct format_tree *ft)
+{
+ struct window_pane *wp = format_get_pane(ft);
+ struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
+ struct window_copy_mode_data *data = wme->data;
+
+ return (window_copy_get_line(wp, data->cy));
+}
+
+static char *
+window_copy_search_match_cb(struct format_tree *ft)
+{
+ struct window_pane *wp = format_get_pane(ft);
+ struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
+ struct window_copy_mode_data *data = wme->data;
+
+ return (window_copy_match_at_cursor(data));
+}
+
static void
window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft)
{
struct window_copy_mode_data *data = wme->data;
- struct grid *gd = data->screen.grid;
- char *s;
format_add(ft, "scroll_position", "%d", data->oy);
format_add(ft, "rectangle_toggle", "%d", data->rectflag);
@@ -726,17 +755,11 @@ window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft)
} else
format_add(ft, "selection_active", "%d", 0);
- s = format_grid_word(gd, data->cx, gd->hsize + data->cy);
- if (s != NULL) {
- format_add(ft, "copy_cursor_word", "%s", s);
- free(s);
- }
+ format_add(ft, "search_present", "%d", data->searchmark != NULL);
+ format_add_cb(ft, "search_match", window_copy_search_match_cb);
- s = format_grid_line(gd, gd->hsize + data->cy);
- if (s != NULL) {
- format_add(ft, "copy_cursor_line", "%s", s);
- free(s);
- }
+ format_add_cb(ft, "copy_cursor_word", window_copy_cursor_word_cb);
+ format_add_cb(ft, "copy_cursor_line", window_copy_cursor_line_cb);
}
static void