summaryrefslogtreecommitdiff
path: root/lisp/isearch.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2021-09-13 21:18:30 +0300
committerJuri Linkov <juri@linkov.net>2021-09-13 21:18:30 +0300
commita17bea6d63c23a943a6bae28e699398c4002c2a8 (patch)
treeaae55405db00559b86783c9e66c630a8e44258b4 /lisp/isearch.el
parent4cf6d03d04ecadfd74fa4998fde14dcc79fd6daf (diff)
downloademacs-a17bea6d63c23a943a6bae28e699398c4002c2a8.tar.gz
emacs-a17bea6d63c23a943a6bae28e699398c4002c2a8.tar.bz2
emacs-a17bea6d63c23a943a6bae28e699398c4002c2a8.zip
* lisp/isearch.el: Improve 'isearch-allow-motion' feature (bug#50466)
* lisp/isearch.el: Add recenter to 'isearch-motion' property of 'end-of-buffer' to maximize the number of search hits on the screen. In 'isearch-motion' property of 'scroll-up-command' use 'recenter 0' for the first line of the screen. (isearch-beginning-of-buffer) (isearch-end-of-buffer): Sync logic from 'isearch-allow-motion' part of isearch-pre-command-hook. Direct users to isearch-allow-motion in the docstrings. (isearch-pre-command-hook): Don't override shifted 'isearch-yank-on-move' in 'isearch-allow-motion'.
Diffstat (limited to 'lisp/isearch.el')
-rw-r--r--lisp/isearch.el29
1 files changed, 20 insertions, 9 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el
index bebc80adb30..3f5e642fd28 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -2003,7 +2003,8 @@ Move point to the beginning of the buffer and search forwards from the top.
\\<isearch-mode-map>
With a numeric argument, go to the ARGth absolute occurrence counting from
the beginning of the buffer. To find the next relative occurrence forwards,
-type \\[isearch-repeat-forward] with a numeric argument."
+type \\[isearch-repeat-forward] with a numeric argument.
+You might want to use `isearch-allow-motion' instead of this command."
(interactive "p")
(if (and arg (< arg 0))
(isearch-end-of-buffer (abs arg))
@@ -2011,8 +2012,11 @@ type \\[isearch-repeat-forward] with a numeric argument."
;; don't forward char in isearch-repeat
(setq isearch-just-started t)
(goto-char (point-min))
- (let ((isearch-repeat-on-direction-change nil))
- (isearch-repeat 'forward arg))))
+ (let ((current-direction (if isearch-forward 'forward 'backward))
+ (isearch-repeat-on-direction-change nil))
+ (isearch-repeat 'forward arg)
+ (unless (eq current-direction (if isearch-forward 'forward 'backward))
+ (isearch-repeat current-direction)))))
(defun isearch-end-of-buffer (&optional arg)
"Go to the last occurrence of the current search string.
@@ -2020,14 +2024,18 @@ Move point to the end of the buffer and search backwards from the bottom.
\\<isearch-mode-map>
With a numeric argument, go to the ARGth absolute occurrence counting from
the end of the buffer. To find the next relative occurrence backwards,
-type \\[isearch-repeat-backward] with a numeric argument."
+type \\[isearch-repeat-backward] with a numeric argument.
+You might want to use `isearch-allow-motion' instead of this command."
(interactive "p")
(if (and arg (< arg 0))
(isearch-beginning-of-buffer (abs arg))
(setq isearch-just-started t)
(goto-char (point-max))
- (let ((isearch-repeat-on-direction-change nil))
- (isearch-repeat 'backward arg))))
+ (let ((current-direction (if isearch-forward 'forward 'backward))
+ (isearch-repeat-on-direction-change nil))
+ (isearch-repeat 'backward arg)
+ (unless (eq current-direction (if isearch-forward 'forward 'backward))
+ (isearch-repeat current-direction)))))
;;; Toggles for `isearch-regexp-function' and `search-default-mode'.
@@ -2939,9 +2947,9 @@ See also the related option `isearch-allow-motion'."
(put 'beginning-of-buffer 'isearch-motion
'((lambda () (goto-char (point-min))) . forward))
(put 'end-of-buffer 'isearch-motion
- '((lambda () (goto-char (point-max))) . backward))
+ '((lambda () (goto-char (point-max)) (recenter -1 t)) . backward))
(put 'scroll-up-command 'isearch-motion
- '((lambda () (goto-char (window-end)) (recenter 1 t)) . forward))
+ '((lambda () (goto-char (window-end)) (recenter 0 t)) . forward))
(put 'scroll-down-command 'isearch-motion
'((lambda () (goto-char (window-start)) (recenter -1 t)) . backward))
@@ -3076,7 +3084,10 @@ See more for options in `search-exit-option'."
;; Handle motion command functions.
((and isearch-allow-motion
(symbolp this-command)
- (get this-command 'isearch-motion))
+ (get this-command 'isearch-motion)
+ ;; Don't override `isearch-yank-on-move' used below.
+ (not (and (eq isearch-yank-on-move 'shift)
+ this-command-keys-shift-translated)))
(let* ((property (get this-command 'isearch-motion))
(function (car property))
(current-direction (if isearch-forward 'forward 'backward))