summaryrefslogtreecommitdiff
path: root/lisp/isearch.el
diff options
context:
space:
mode:
authorGregory Heytings <gregory@heytings.org>2021-04-07 17:51:30 +0000
committerJuri Linkov <juri@linkov.net>2021-04-08 22:04:08 +0300
commit972bab0981fb0cc0d992b4a195ebaf33c79858c3 (patch)
treea8f017cf4e78f92f832a7a7b34a9b394d254a15b /lisp/isearch.el
parentb4eb84d4afd1b847f6f4c272d04ffa1f4b36dc98 (diff)
downloademacs-972bab0981fb0cc0d992b4a195ebaf33c79858c3.tar.gz
emacs-972bab0981fb0cc0d992b4a195ebaf33c79858c3.tar.bz2
emacs-972bab0981fb0cc0d992b4a195ebaf33c79858c3.zip
User option to move to another match when changing direction in isearch.
* lisp/isearch.el (isearch-direction-change-changes-match): New user option (bug#47599). (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.
Diffstat (limited to 'lisp/isearch.el')
-rw-r--r--lisp/isearch.el24
1 files changed, 20 insertions, 4 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 4b4f44bdffd..1ac1e63a9b7 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))
@@ -1910,10 +1922,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)))
@@ -1931,10 +1945,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)))