git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jeff King <peff@peff.net>
Date
Feb 3, 2009, 05:49 UTC
Message-ID
<20090203054907.GA21695@sigill.intra.peff.net>

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(-)
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
Next: Jonas Fonseca
Message 1 of 2 in “treat empty '/' as "find next"”
  1. treat empty '/' as "find next"Jeff King, Feb 3, 2009
  2. Jonas FonsecaFeb 4, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.