[PATCH] Default to last search string in search-forward/search-backward.

6 views
Skip to first unread message

Leah Neukirchen

unread,
Aug 8, 2019, 7:52:22 AM8/8/19
to tmux-...@googlegroups.com
This behaves similarily to POSIX vi and gives a nice way to reverse
search direction for search-again.

Signed-off-by: Leah Neukirchen <le...@vuxu.org>
---
window-copy.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/window-copy.c b/window-copy.c
index 5b197e65..99bb5be6 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -1638,9 +1638,11 @@ window_copy_cmd_search_backward(struct window_copy_cmd_state *cs)
const char *argument = cs->args->argv[1];

if (*argument != '\0') {
- data->searchtype = WINDOW_COPY_SEARCHUP;
free(data->searchstr);
data->searchstr = xstrdup(argument);
+ }
+ if (data->searchstr) {
+ data->searchtype = WINDOW_COPY_SEARCHUP;
for (; np != 0; np--)
window_copy_search_up(wme);
}
@@ -1656,9 +1658,11 @@ window_copy_cmd_search_forward(struct window_copy_cmd_state *cs)
const char *argument = cs->args->argv[1];

if (*argument != '\0') {
- data->searchtype = WINDOW_COPY_SEARCHDOWN;
free(data->searchstr);
data->searchstr = xstrdup(argument);
+ }
+ if (data->searchstr) {
+ data->searchtype = WINDOW_COPY_SEARCHDOWN;
for (; np != 0; np--)
window_copy_search_down(wme);
}
--
2.22.0

Nicholas Marriott

unread,
Aug 8, 2019, 8:03:58 AM8/8/19
to Leah Neukirchen, tmux-...@googlegroups.com
Hi

This will only work if you do search-forward '', it would be more useful
to also work without arguments (change window_copy_cmd_table and add an
argc check as well).
> --
> You received this message because you are subscribed to the Google Groups "tmux-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/20190808114507.14835-1-leah%40vuxu.org.

Leah Neukirchen

unread,
Aug 8, 2019, 9:27:35 AM8/8/19
to tmux-...@googlegroups.com
This behaves similarily to POSIX vi and gives a nice way to reverse
search direction for search-again.

Also allow these commands to be called without argument now.

Signed-off-by: Leah Neukirchen <le...@vuxu.org>
---
window-copy.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/window-copy.c b/window-copy.c
index 5b197e65..ecd7f89e 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -1635,12 +1635,16 @@ window_copy_cmd_search_backward(struct window_copy_cmd_state *cs)
struct window_mode_entry *wme = cs->wme;
struct window_copy_mode_data *data = wme->data;
u_int np = wme->prefix;
- const char *argument = cs->args->argv[1];

- if (*argument != '\0') {
+ if (cs->args->argc == 2) {
+ const char *argument = cs->args->argv[1];
+ if (*argument != '\0') {
+ free(data->searchstr);
+ data->searchstr = xstrdup(argument);
+ }
+ }
+ if (data->searchstr) {
data->searchtype = WINDOW_COPY_SEARCHUP;
- free(data->searchstr);
- data->searchstr = xstrdup(argument);
for (; np != 0; np--)
window_copy_search_up(wme);
}
@@ -1653,12 +1657,16 @@ window_copy_cmd_search_forward(struct window_copy_cmd_state *cs)
struct window_mode_entry *wme = cs->wme;
struct window_copy_mode_data *data = wme->data;
u_int np = wme->prefix;
- const char *argument = cs->args->argv[1];

- if (*argument != '\0') {
+ if (cs->args->argc == 2) {
+ const char *argument = cs->args->argv[1];
+ if (*argument != '\0') {
+ free(data->searchstr);
+ data->searchstr = xstrdup(argument);
+ }
+ }
+ if (data->searchstr) {
data->searchtype = WINDOW_COPY_SEARCHDOWN;
- free(data->searchstr);
- data->searchstr = xstrdup(argument);
for (; np != 0; np--)
window_copy_search_down(wme);
}
@@ -1872,11 +1880,11 @@ static const struct {
window_copy_cmd_scroll_up },
{ "search-again", 0, 0,
window_copy_cmd_search_again },
- { "search-backward", 1, 1,
+ { "search-backward", 0, 1,
window_copy_cmd_search_backward },
{ "search-backward-incremental", 1, 1,
window_copy_cmd_search_backward_incremental },
- { "search-forward", 1, 1,
+ { "search-forward", 0, 1,
window_copy_cmd_search_forward },
{ "search-forward-incremental", 1, 1,
window_copy_cmd_search_forward_incremental },
--
2.22.0

Nicholas Marriott

unread,
Aug 14, 2019, 6:02:47 AM8/14/19
to Leah Neukirchen, tmux-...@googlegroups.com
Applied to OpenBSD now, will be in GitHub later on, thanks!
> --
> You received this message because you are subscribed to the Google Groups "tmux-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/20190808123046.27250-1-leah%40vuxu.org.
Reply all
Reply to author
Forward
0 new messages