From: Gregory Heytings <gregory@heytings.org>
To: Juri Linkov <juri@linkov.net>
Cc: Ergus <spacibba@aol.com>, emacs-devel@gnu.org
Subject: Re: Simple isearch concerns
Date: Tue, 06 Apr 2021 00:44:19 +0000 [thread overview]
Message-ID: <acf6f0cd7e407df0e4f5@heytings.org> (raw)
In-Reply-To: <acf6f0cd7e9d21e6c35b@heytings.org>
[-- Attachment #1: Type: text/plain, Size: 1039 bytes --]
>>> 1) Are there any option to move the cursor to the start of the
>>> candidate after the search? I see that there is an isearch-other-end.
>>> But it is not a custom but an internal variable. Now I am using a hook
>>> but it seems a bit hacky.
>>
>> As you see from the discussion, adding a defcustom makes little sense,
>> because this feature might be needed only occasionally, so better to be
>> bound to a special key, e.g. C-RET to exit and move to other-end, S-RET
>> to exit and mark the found string as a region.
>
> Note that neither C-RET nor S-RET are available in a terminal.
>
> What I consider to be the most useful feature of CTRLF, namely the
> possibility to scroll among the matches, has not much been discussed so
> far, alas. I attach a short patch which implements that feature in
> isearch. I've been using it for a day, and I'm convinced it's a
> must-have, it makes navigating among the search matches much faster.
> WDYT?
>
Sorry, there was a typo in the previous patch, I attach a corrected one.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff; name=0001-New-user-option-to-scroll-isearch-matches.patch, Size: 6087 bytes --]
From a1dd7f1f93f0a2b74c7f9e43d97f5b5f09e16b69 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Tue, 6 Apr 2021 00:17:39 +0000
Subject: [PATCH] New user option to scroll isearch matches
* lisp/isearch.el (isearch-allow-match-scroll): New user option.
(isearch-scroll-up, isearch-scroll-down): New commands to scroll
the current search match, that complement the existing
isearch-beginning-of-buffer and isearch-end-of-buffer commands.
(isearch-pre-command-hook): Handle the new option and commands.
* etc/NEWS: Mention the new user option.
* doc/emacs/search.texi: Document the new user option.
---
doc/emacs/search.texi | 8 ++++++++
etc/NEWS | 8 ++++++++
lisp/isearch.el | 47 ++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index f3c42bcea7..6c161d4c58 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -587,6 +587,14 @@ Not Exiting Isearch
an incremental search. This feature is disabled if
@code{isearch-allow-scroll} is @code{nil} (which it is by default).
+@vindex isearch-allow-match-scroll
+ Likewise, if you change the variable @code{isearch-allow-match-scroll}
+to a non-@code{nil} value, this enables the use of the keyboard scrolling
+commands @kbd{M-<}, @kbd{M->}, @kbd{C-v} and @kbd{M-v}, to move
+respectively to the first first occurrence of the current search
+string in the buffer, the last one, the first one after the current
+window, and the last one before the current window.
+
@item Motion Commands
@cindex motion commands, during incremental search
When @code{isearch-yank-on-move} is customized to @code{shift},
diff --git a/etc/NEWS b/etc/NEWS
index c8400ba8c2..411ea72e7c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -367,6 +367,14 @@ 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-allow-match-scroll'.
+When this option is set, the commands 'beginning-of-buffer',
+'end-of-buffer', 'scroll-up-command' and 'scroll-down-command' move
+respectively to the first first occurrence of the current search
+string in the buffer, the last one, the first one after the current
+window, and the last one before the current window.
+
** Outline
+++
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 943e24aa56..bdb2f147ab 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1942,6 +1942,23 @@ isearch-end-of-buffer
(goto-char (point-max))
(isearch-repeat 'backward arg)))
+(defun isearch-scroll-up ()
+ "Go to the first occurrence of the current search string after window.
+Move point to the end of the window, and search forward."
+ (interactive)
+ (setq isearch-just-started t)
+ (goto-char (window-end))
+ (isearch-repeat 'forward))
+
+(defun isearch-scroll-down ()
+ "Go to the first occurrence of the current search string before window.
+Move point to the beginning of the window, recenter it, and search backward."
+ (interactive)
+ (setq isearch-just-started t)
+ (goto-char (window-start))
+ (recenter nil t)
+ (isearch-repeat 'backward))
+
\f
;;; Toggles for `isearch-regexp-function' and `search-default-mode'.
(defmacro isearch-define-mode-toggle (mode key function &optional docstring &rest body)
@@ -2840,12 +2857,35 @@ isearch-allow-scroll
However, you cannot scroll far enough that the current match is
no longer visible (is off screen). But if the value is `unlimited'
that limitation is removed and you can scroll any distance off screen.
-If nil, scrolling commands exit Isearch mode."
+If nil, scrolling commands exit Isearch mode.
+See also the related option `isearch-allow-match-scroll'."
:type '(choice (const :tag "Scrolling exits Isearch" nil)
(const :tag "Scrolling with current match on screen" t)
(const :tag "Scrolling with current match off screen" unlimited))
:group 'isearch)
+(put 'beginning-of-buffer 'isearch-match-scroll t)
+(put 'end-of-buffer 'isearch-match-scroll t)
+(put 'scroll-up-command 'isearch-match-scroll t)
+(put 'scroll-down-command 'isearch-match-scroll t)
+
+(put 'beginning-of-buffer 'isearch-match-scroll-command 'isearch-beginning-of-buffer)
+(put 'end-of-buffer 'isearch-match-scroll-command 'isearch-end-of-buffer)
+(put 'scroll-up-command 'isearch-match-scroll-command 'isearch-scroll-up)
+(put 'scroll-down-command 'isearch-match-scroll-command 'isearch-scroll-down)
+
+(defcustom isearch-allow-match-scroll nil
+ "Whether scrolling to another match is allowed during incremental search.
+If non-nil, the four scrolling commands `beginning-of-buffer',
+`end-of-buffer', `scroll-up-command' and `scroll-down-command' move
+respectively to the first first occurrence of the current search string in
+the buffer, the last one, the first one after the current window, and the
+last one before the current window.
+See also the related option `isearch-allow-scroll'."
+ :type '(choice (const :tag "Off" nil)
+ (const tag "On" t))
+ :group 'isearch)
+
(defcustom isearch-allow-prefix t
"Whether prefix arguments are allowed during incremental search.
If non-nil, entering a prefix argument will not terminate the
@@ -2947,6 +2987,11 @@ isearch-pre-command-hook
;; Optionally edit the search string instead of exiting.
((eq search-exit-option 'edit)
(setq this-command 'isearch-edit-string))
+ ;; Handle match scrolling functions
+ ((and isearch-allow-match-scroll
+ (symbolp this-command)
+ (eq (get this-command 'isearch-match-scroll) t))
+ (setq this-command (get this-command 'isearch-match-scroll-command)))
;; Handle a scrolling function or prefix argument.
((or (and isearch-allow-prefix
(memq this-command '(universal-argument universal-argument-more
--
2.30.2
next prev parent reply other threads:[~2021-04-06 0:44 UTC|newest]
Thread overview: 143+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210403001539.x4rb55dvh46rmhb3.ref@Ergus>
2021-04-03 0:15 ` Simple isearch concerns Ergus
2021-04-03 5:56 ` Thierry Volpiatto
2021-04-03 6:33 ` Manuel Uberti
2021-04-03 10:37 ` Daniel Martín
2021-04-06 7:12 ` Zhiwei Chen
2021-04-06 13:04 ` Stefan Monnier
2021-04-06 13:18 ` Gregory Heytings
2021-04-06 14:17 ` Gregory Heytings
2021-04-06 18:56 ` Juri Linkov
2021-04-06 20:10 ` Gregory Heytings
2021-04-07 10:22 ` Gregory Heytings
2021-04-07 16:24 ` Juri Linkov
2021-04-07 17:03 ` Gregory Heytings
2021-04-08 19:08 ` Juri Linkov
2021-04-09 6:42 ` Zhiwei Chen
2021-04-21 17:51 ` Juri Linkov
2021-04-25 8:16 ` Zhiwei Chen
2021-04-03 11:28 ` Philip Kaludercic
2021-04-03 12:26 ` Gregory Heytings
2021-04-03 16:37 ` Philip Kaludercic
2021-04-03 17:31 ` Gregory Heytings
2021-04-03 18:36 ` Philip Kaludercic
2021-04-03 19:36 ` Dmitry Gutov
2021-04-05 2:18 ` Ergus
2021-04-05 8:39 ` Juri Linkov
2021-04-03 17:45 ` Ergus
2021-04-22 7:15 ` Augusto Stoffel
2021-04-22 22:24 ` Juri Linkov
2021-04-25 7:15 ` Augusto Stoffel
2021-04-25 17:24 ` Juri Linkov
2021-04-25 18:41 ` [External] : " Drew Adams
2021-04-26 5:39 ` Augusto Stoffel
2021-04-27 17:41 ` Juri Linkov
2021-04-29 16:29 ` Juri Linkov
2021-04-29 17:50 ` Augusto Stoffel
2021-04-29 23:00 ` Juri Linkov
2021-04-30 7:07 ` Augusto Stoffel
2021-04-30 16:41 ` Juri Linkov
2021-05-02 6:09 ` Augusto Stoffel
2021-05-02 22:18 ` Juri Linkov
2021-05-03 5:30 ` Augusto Stoffel
2021-05-03 16:51 ` Juri Linkov
2021-05-05 20:52 ` Juri Linkov
2021-05-07 17:14 ` Juri Linkov
2021-05-08 10:17 ` Augusto Stoffel
2021-05-09 19:12 ` Juri Linkov
2021-05-09 19:53 ` [External] : " Drew Adams
2021-05-10 21:11 ` Juri Linkov
2021-05-10 23:06 ` Drew Adams
2021-05-11 18:32 ` Juri Linkov
2021-05-11 20:01 ` Drew Adams
2021-05-11 6:20 ` Yuri Khan
2021-05-11 9:01 ` Augusto Stoffel
2021-05-11 18:37 ` Juri Linkov
2021-05-11 20:56 ` Juri Linkov
2021-04-03 12:29 ` Gregory Heytings
2021-04-03 13:02 ` Daniel Martín
2021-04-03 13:25 ` Gregory Heytings
2021-04-03 17:25 ` Ergus
2021-04-03 10:28 ` Daniel Martín
2021-04-04 22:48 ` Juri Linkov
2021-04-04 23:27 ` Stefan Monnier
2021-04-05 1:41 ` Ergus
2021-04-05 2:22 ` [External] : " Drew Adams
2021-04-05 8:34 ` Juri Linkov
2021-04-05 14:58 ` Drew Adams
2021-04-05 2:38 ` Stefan Monnier
2021-04-05 8:30 ` Juri Linkov
2021-04-05 9:52 ` Basil L. Contovounesios
2021-04-05 15:08 ` [External] : " Drew Adams
2021-04-05 2:08 ` Ergus
2021-04-05 20:37 ` Juri Linkov
2021-04-05 21:18 ` [External] : " Drew Adams
2021-04-05 21:35 ` Juri Linkov
2021-04-05 22:37 ` Ergus
2021-04-06 19:11 ` Juri Linkov
2021-04-06 19:30 ` Eli Zaretskii
2021-04-06 20:10 ` Gregory Heytings
2021-04-07 16:30 ` Juri Linkov
2021-04-07 17:14 ` Gregory Heytings
2021-04-07 20:12 ` Gregory Heytings
2021-04-05 23:06 ` Drew Adams
2021-04-05 22:16 ` Ergus
2021-04-06 19:17 ` Juri Linkov
2021-04-06 0:30 ` Gregory Heytings
2021-04-06 0:44 ` Gregory Heytings [this message]
2021-04-06 18:53 ` Juri Linkov
2021-04-06 20:10 ` Gregory Heytings
2021-04-07 16:36 ` Juri Linkov
2021-04-07 17:21 ` Gregory Heytings
2021-04-07 20:12 ` Juri Linkov
2021-04-07 21:09 ` Gregory Heytings
2021-04-08 8:08 ` Juri Linkov
2021-04-08 8:48 ` Gregory Heytings
2021-04-08 19:12 ` Juri Linkov
2021-04-08 19:27 ` Gregory Heytings
2021-04-08 20:05 ` Juri Linkov
2021-04-08 20:10 ` Gregory Heytings
2021-04-08 22:40 ` Gregory Heytings
2021-04-09 6:22 ` Eli Zaretskii
2021-04-09 7:20 ` Gregory Heytings
2021-04-09 8:37 ` Juri Linkov
2021-04-09 10:50 ` Eli Zaretskii
2021-04-09 16:49 ` Juri Linkov
2021-04-09 10:46 ` Eli Zaretskii
2021-04-09 11:27 ` Gregory Heytings
2021-04-09 12:45 ` Eli Zaretskii
2021-04-09 6:05 ` Eli Zaretskii
2021-04-09 8:39 ` Juri Linkov
2021-04-09 10:51 ` Eli Zaretskii
2021-04-09 11:48 ` Gregory Heytings
2021-04-09 12:48 ` Eli Zaretskii
2021-04-09 13:26 ` Gregory Heytings
2021-04-09 13:49 ` Eli Zaretskii
2021-04-09 14:36 ` Gregory Heytings
2021-04-09 14:56 ` Eli Zaretskii
2021-04-09 15:25 ` Gregory Heytings
2021-04-09 19:01 ` Eli Zaretskii
2021-04-09 19:04 ` [External] : " Drew Adams
2021-04-09 23:18 ` Gregory Heytings
2021-04-10 7:17 ` Eli Zaretskii
2021-04-10 10:36 ` Gregory Heytings
2021-04-10 10:46 ` Eli Zaretskii
2021-04-10 10:57 ` Gregory Heytings
2021-04-10 11:13 ` Eli Zaretskii
2021-04-10 19:02 ` Now branch isearch-vertical Ergus
2021-04-10 20:00 ` Gregory Heytings
2021-04-10 22:12 ` Simple isearch concerns Juri Linkov
2021-04-10 23:55 ` Gregory Heytings
2021-04-11 7:07 ` Eli Zaretskii
2021-04-11 8:49 ` Gregory Heytings
2021-04-11 10:16 ` Gregory Heytings
2021-04-11 22:09 ` Juri Linkov
2021-04-11 22:17 ` Juri Linkov
2021-04-11 23:06 ` Gregory Heytings
2021-04-11 22:05 ` Juri Linkov
2021-04-08 3:32 ` Ergus
2022-03-03 16:36 ` Augusto Stoffel
2022-03-03 17:50 ` Alan Mackenzie
2022-03-03 18:39 ` Augusto Stoffel
2022-03-03 18:46 ` Eli Zaretskii
2021-04-07 16:41 ` Howard Melman
2021-04-06 2:21 ` Ergus
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=acf6f0cd7e407df0e4f5@heytings.org \
--to=gregory@heytings.org \
--cc=emacs-devel@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).