unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Gregory Heytings <gregory@heytings.org>
To: Juri Linkov <juri@linkov.net>
Cc: 47599@debbugs.gnu.org, Ergus <spacibba@aol.com>
Subject: bug#47599: 28.0.50; Feature request improve/update isearch
Date: Wed, 07 Apr 2021 17:58:13 +0000	[thread overview]
Message-ID: <3ec7e2e58adbe810caca@heytings.org> (raw)
In-Reply-To: <87k0pe49ny.fsf@mail.linkov.net>

[-- Attachment #1: Type: text/plain, Size: 1251 bytes --]


>
> Thanks, finally there is an option to avoid typing extra C-r.
>

:-)  And thanks for your feedback!

>
> Is it possible to find a clearer name?
> Maybe isearch-repeat-on-direction-change would be better with the prefix 
> 'isearch-repeat-' to hint that it applies to the commands 
> 'isearch-repeat-*'?
>

Done.

>
> This breaks the following feature:
>
> When isearch-forward is t:
> - C-1 C-r moves to the previous match (like your patch does without 'C-1')
> - C-2 C-r moves to the second previous match
> - C-u -1 C-r moves to the next match
> - C-u -2 C-r moves to the second next match
>
> This is due to these lines in isearch-repeat-backward:
>
>               ;; Reverse the direction back
>               (isearch-repeat 'backward))
>              (t
>               ;; Take into account one iteration to reverse direction
>               (when isearch-forward (setq count (1+ count)))
>
> When the new option is non-nil, there is no need to increment 'count'.
> Also the new option should be let-bound to nil around the call to
> '(isearch-repeat 'backward)' above to just change the direction back
> without moving to the next match.
>
> The same applies to isearch-repeat-forward and when isearch-forward is nil.
>

Fixed, thank you!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff; name=0001-User-option-to-move-to-another-match-when-changing-d.patch, Size: 4942 bytes --]

From a90d2447b448831f3f4ab8200769ef749612c02a Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Wed, 7 Apr 2021 17:51:30 +0000
Subject: [PATCH] User option to move to another match when changing direction
 in isearch.

* lisp/isearch.el (isearch-direction-change-changes-match): New
user option.
(isearch-repeat): Use the new option.
(isearch-repeat-forward, isearch-repeat-backward): Adapt to the
new option.

* etc/NEWS: Mention the new user option.

* doc/emacs/search.texi: Document the new user option.
---
 doc/emacs/search.texi |  8 ++++++++
 etc/NEWS              |  6 ++++++
 lisp/isearch.el       | 24 ++++++++++++++++++++----
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index f3c42bcea7..38430a2ab1 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -201,6 +201,14 @@ something before the starting point, type @kbd{C-r} to switch to a
 backward search, leaving the search string unchanged.  Similarly,
 @kbd{C-s} in a backward search switches to a forward search.
 
+@cindex search, changing direction
+@vindex isearch-repeat-on-direction-change
+  When you change the direction of a search, the first command you
+type will, by default, remain on the same match, and the cursor will
+move to the other end of the match.  To move to another match
+immediately, customize the variable
+@code{isearch-repeat-on-direction-change} to @code{t}.
+
 @cindex search, wrapping around
 @cindex search, overwrapped
 @cindex wrapped search
diff --git a/etc/NEWS b/etc/NEWS
index d3a8748ded..8d7b3a6c46 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -367,6 +367,12 @@ trying to be non-destructive.
 This command opens a new buffer called "*Memory Report*" and gives a
 summary of where Emacs is using memory currently.
 
++++
+** New user option 'isearch-repeat-on-direction-change'.
+When this option is set, direction changes in Isearch move to another
+search match, if there is one, instead of moving point to the other
+end of the current match.
+
 ** Outline
 
 +++
diff --git a/lisp/isearch.el b/lisp/isearch.el
index a828c569aa..a41827f9cd 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -185,6 +185,16 @@ When `nil', never wrap, just stop at the last match."
                  (const :tag "Disable wrapping" nil))
   :version "28.1")
 
+(defcustom isearch-repeat-on-direction-change nil
+  "Whether a direction change should move to another match.
+When `nil', the default, a direction change moves point to the other
+end of the current search match.
+When `t', a direction change moves to another search match, if there
+is one."
+  :type '(choice (const :tag "Remain on the same match" nil)
+                 (const :tag "Move to another match" t))
+  :version "28.1")
+
 (defvar isearch-mode-hook nil
   "Function(s) to call after starting up an incremental search.")
 
@@ -1847,6 +1857,8 @@ Use `isearch-exit' to quit without signaling."
 	      (funcall isearch-wrap-function)
 	    (goto-char (if isearch-forward (point-min) (point-max))))))
     ;; C-s in reverse or C-r in forward, change direction.
+    (if (and isearch-other-end isearch-repeat-on-direction-change)
+        (goto-char isearch-other-end))
     (setq isearch-forward (not isearch-forward)
 	  isearch-success t))
 
@@ -1912,10 +1924,12 @@ of the buffer, type \\[isearch-beginning-of-buffer] with a numeric argument."
         (cond ((< count 0)
                (isearch-repeat-backward (abs count))
                ;; Reverse the direction back
-               (isearch-repeat 'forward))
+               (let ((isearch-repeat-on-direction-change nil))
+                 (isearch-repeat 'forward)))
               (t
                ;; Take into account one iteration to reverse direction
-               (when (not isearch-forward) (setq count (1+ count)))
+               (unless isearch-repeat-on-direction-change
+                 (when (not isearch-forward) (setq count (1+ count))))
                (isearch-repeat 'forward count))))
     (isearch-repeat 'forward)))
 
@@ -1933,10 +1947,12 @@ of the buffer, type \\[isearch-end-of-buffer] with a numeric argument."
         (cond ((< count 0)
                (isearch-repeat-forward (abs count))
                ;; Reverse the direction back
-               (isearch-repeat 'backward))
+               (let ((isearch-repeat-on-direction-change nil))
+                 (isearch-repeat 'backward)))
               (t
                ;; Take into account one iteration to reverse direction
-               (when isearch-forward (setq count (1+ count)))
+               (unless isearch-repeat-on-direction-change
+                 (when isearch-forward (setq count (1+ count))))
                (isearch-repeat 'backward count))))
     (isearch-repeat 'backward)))
 
-- 
2.30.2


  reply	other threads:[~2021-04-07 17:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210405020725.ob7bewlin7cid4pa.ref@Ergus>
2021-04-05  2:07 ` bug#47599: 28.0.50; Feature request improve/update isearch Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-04-06 19:16   ` Juri Linkov
2021-04-06 20:38     ` Gregory Heytings
2021-04-06 21:01       ` Gregory Heytings
2021-04-06 21:32         ` Gregory Heytings
2021-04-06 22:39           ` bug#47599: [External] : " Drew Adams
2021-04-06 22:43             ` Gregory Heytings
2021-04-06 23:26               ` Gregory Heytings
2021-04-07 16:20                 ` Juri Linkov
2021-04-07 17:58                   ` Gregory Heytings [this message]
2021-04-08 19:05                     ` Juri Linkov
2021-04-07  2:29           ` Eli Zaretskii
2021-04-07 10:44       ` Gregory Heytings
2021-04-07 11:20         ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-04-07 11:33           ` Gregory Heytings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ec7e2e58adbe810caca@heytings.org \
    --to=gregory@heytings.org \
    --cc=47599@debbugs.gnu.org \
    --cc=juri@linkov.net \
    --cc=spacibba@aol.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).