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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
---
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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux