threads / patch / 17521

patchtreat empty '/' as "find next"

Subject: [tig PATCH] treat empty '/' as "find next"

## tl;dr

2 messages between Feb 3, 2009 and Feb 4, 2009. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Jeff King· Feb 3, 2009, 05:49 UTC · lore

When the user requests a forward or backwards search, if they provide no search string then we just abort the search. However, many other programs (such as less and vi) treat this as "repeat the last search", so users may have their fingers trained to do this rather than use the explicit "find next" feature.

This patch causes tig, if there was a previous search, to find the next (or previous, if "?" was used) match in such a case.

Signed-off-by: Jeff King <peff@peff.net>
---
I tried retraining my fingers, but they just won't do it. :)

Related is the fact that searching for "foo", followed by another search for "foo" will find the same line. That is, the second search won't move at all, which is not the case for "less". I'm not sure what is the right mental model for that behavior:

  1. Searches always start at line n+1
  2. There is a special case for searching for the thing we last
     matched, which by definition we already know is on the current
     line.
"less" seems to implement (1). That is, if you do this:
 for i in one two three; do echo $i line; done | less

entering "/two" will take you the second line. Entering "/line" after that will take you to the _third_ line. This is mostly intuitive, since you have already looked at the current line and want to search forward. But it is confusing if you try "/one" on the first line: you get "pattern not found" since it is not in any line after the first (but you are searching because you haven't even looked at the first line).

So in some ways tig's behavior is better, and in some ways worse. And I have to admit, my main reason for "/foo" followed by "/foo" was that just using "/" for the second one didn't work. Which the patch below should deal with.

 tig.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Show changes to tig.c +4 −0
diff --git a/tig.c b/tig.c
index b4e4b59..c02f71b 100644
--- a/tig.c
+++ b/tig.c
@@ -6812,6 +6812,10 @@ main(int argc, const char *argv[])
 
 			if (search)
 				string_ncopy(opt_search, search, strlen(search));
+			else if (*opt_search)
+				request = request == REQ_SEARCH ?
+					REQ_FIND_NEXT :
+					REQ_FIND_PREV;
 			else
 				request = REQ_NONE;
 			break;
-- 
1.6.1.2.465.g1dfd1
Jonas Fonseca· Feb 4, 2009, 09:02 UTC · re: Jeff King · lore

Re: [tig PATCH] treat empty '/' as "find next"

On Tue, Feb 3, 2009 at 06:49, Jeff King <peff@peff.net> wrote:
> This patch causes tig, if there was a previous search, to
> find the next (or previous, if "?" was used) match in such a
> case.
Thanks, makes sense.
-- 
Jonas Fonseca

← back to recent threads