git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [tig PATCH] treat empty '/' as "find next"
@ 2009-02-03  5:49 Jeff King
  2009-02-04  9:02 ` Jonas Fonseca
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff King @ 2009-02-03  5:49 UTC (permalink / raw)
  To: Jonas Fonseca; +Cc: git

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [tig PATCH] treat empty '/' as "find next"
  2009-02-03  5:49 [tig PATCH] treat empty '/' as "find next" Jeff King
@ 2009-02-04  9:02 ` Jonas Fonseca
  0 siblings, 0 replies; 2+ messages in thread
From: Jonas Fonseca @ 2009-02-04  9:02 UTC (permalink / raw)
  To: Jeff King; +Cc: git

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-02-04  9:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-03  5:49 [tig PATCH] treat empty '/' as "find next" Jeff King
2009-02-04  9:02 ` Jonas Fonseca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).