From: Juri Linkov <juri@linkov.net>
To: charles@aurox.ch (Charles A. Roelli)
Cc: 29321@debbugs.gnu.org
Subject: bug#29321: Isearch hit count
Date: Thu, 15 Nov 2018 00:36:37 +0200 [thread overview]
Message-ID: <87va4zmglm.fsf@mail.linkov.net> (raw)
In-Reply-To: <m2ineavxaz.fsf@aurox.ch> (Charles A. Roelli's message of "Thu, 16 Nov 2017 20:27:32 +0100")
[-- Attachment #1: Type: text/plain, Size: 1082 bytes --]
> Isearch could show in the mode line how many matches follow or precede
> the currently highlighted one (or we could write "3 of 4 matches", as,
> e.g., Firefox does). For big files, it could be helpful to calculate
> this information either lazily or in another thread.
Lazy-counting is now pushed to master.
> If we had this, it would also be convenient to say "go forward n
> matches", so that typing "M-3 C-s" during a search would be the
> equivalent of typing C-s three times. To do this we could add numeric
> prefix arg handling to C-s/C-r/C-M-s/C-M-r, if that isn't already
> taken for some other behavior.
Adding a numeric prefix arg to C-s/C-r is implemented in
https://debbugs.gnu.org/29321#86
But this implementation causes flicker because it updates
isearch highlighting on every search hit while traversing
all found matches COUNT times until it reaches COUNT-th match.
Attached is a better approach that adds the COUNT arg to
isearch functions down to the lowest-level isearch function,
thus making it compatible with the COUNT arg of re-search-forward:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: isearch-repeat-count.2.patch --]
[-- Type: text/x-diff, Size: 3595 bytes --]
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 035ff69327..3e6e696a74 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1547,7 +1547,7 @@ isearch-abort
(isearch-pop-state))
(isearch-update)))
-(defun isearch-repeat (direction)
+(defun isearch-repeat (direction &optional count)
;; Utility for isearch-repeat-forward and -backward.
(if (eq isearch-forward (eq direction 'forward))
;; C-s in forward or C-r in reverse.
@@ -1590,21 +1590,29 @@ isearch-repeat
(setq isearch-success nil)
(ding))
(forward-char (if isearch-forward 1 -1))
- (isearch-search))
- (isearch-search)))
+ (isearch-search count))
+ (isearch-search count)))
(isearch-push-state)
(isearch-update))
-(defun isearch-repeat-forward ()
- "Repeat incremental search forwards."
- (interactive)
- (isearch-repeat 'forward))
-
-(defun isearch-repeat-backward ()
- "Repeat incremental search backwards."
- (interactive)
- (isearch-repeat 'backward))
+(defun isearch-repeat-forward (&optional arg)
+ "Repeat incremental search forwards.
+With a prefix argument, repeat a search ARG times."
+ (interactive "P")
+ (let ((count (and arg (abs (prefix-numeric-value arg)))))
+ ;; Take into account one search iteration to reverse direction.
+ (when (and count (not isearch-forward)) (setq count (1+ count)))
+ (isearch-repeat 'forward count)))
+
+(defun isearch-repeat-backward (&optional arg)
+ "Repeat incremental search backwards.
+With a prefix argument, repeat a search ARG times."
+ (interactive "P")
+ (let ((count (and arg (abs (prefix-numeric-value arg)))))
+ ;; Take into account one search iteration to reverse direction.
+ (when (and count isearch-forward) (setq count (1+ count)))
+ (isearch-repeat 'backward count)))
\f
;;; Toggles for `isearch-regexp-function' and `search-default-mode'.
@@ -2910,7 +2918,7 @@ isearch-search-fun-default
(t (regexp-quote string)))
bound noerror count))))
-(defun isearch-search-string (string bound noerror)
+(defun isearch-search-string (string bound noerror &optional count)
"Search for the first occurrence of STRING or its translation.
STRING's characters are translated using `translation-table-for-input'
if that is non-nil.
@@ -2921,7 +2929,10 @@ isearch-search-string
Optional third argument, if t, means if fail just return nil (no error).
If not nil and not t, move to limit of search and return nil."
(let* ((func (isearch-search-fun))
- (pos1 (save-excursion (funcall func string bound noerror)))
+ (pos1 (save-excursion (if count
+ (funcall func string bound noerror count)
+ ;; Backward-compatibility for functions that don't support count arg
+ (funcall func string bound noerror))))
pos2)
(when (and
;; Avoid "obsolete" warnings for translation-table-for-input.
@@ -2960,7 +2971,7 @@ isearch-search-string
(goto-char pos1)
pos1)))
-(defun isearch-search ()
+(defun isearch-search (&optional count)
;; Do the search with the current search string.
(if (and (eq isearch-case-fold-search t) search-upper-case)
(setq isearch-case-fold-search
@@ -2974,7 +2985,7 @@ isearch-search
(setq isearch-error nil)
(while retry
(setq isearch-success
- (isearch-search-string isearch-string nil t))
+ (isearch-search-string isearch-string nil t count))
;; Clear RETRY unless the search predicate says
;; to skip this search hit.
(if (or (not isearch-success)
next prev parent reply other threads:[~2018-11-14 22:36 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-16 19:27 bug#29321: Isearch hit count Charles A. Roelli
2018-10-27 20:55 ` Juri Linkov
2018-10-27 21:31 ` Drew Adams
2018-10-27 22:25 ` Drew Adams
2018-10-27 22:58 ` Drew Adams
2018-10-27 23:23 ` Drew Adams
2018-10-28 0:02 ` Drew Adams
2018-10-28 0:35 ` bug#29360: " Drew Adams
2018-10-28 22:34 ` bug#29360: Add full-buffer choice for `isearch-lazy-highlight' Juri Linkov
2018-10-28 22:57 ` Drew Adams
2018-10-28 3:35 ` bug#29321: Isearch hit count Drew Adams
2018-10-28 22:38 ` Juri Linkov
2018-10-29 0:22 ` Drew Adams
2018-10-29 23:31 ` Juri Linkov
2018-10-30 2:43 ` Drew Adams
2018-10-30 3:19 ` Drew Adams
2018-10-30 3:47 ` Drew Adams
2018-10-30 4:02 ` Drew Adams
2018-10-30 23:07 ` Juri Linkov
2018-10-30 23:35 ` Drew Adams
2018-10-30 23:43 ` Drew Adams
2018-10-31 21:30 ` Juri Linkov
2018-10-31 22:07 ` Drew Adams
2018-11-01 22:22 ` Juri Linkov
2018-11-01 23:46 ` Drew Adams
2018-11-02 12:51 ` Live System User
2018-11-04 0:04 ` Juri Linkov
2018-11-04 0:11 ` Juri Linkov
2018-11-04 1:22 ` Drew Adams
2018-11-04 22:50 ` Juri Linkov
2018-11-05 3:09 ` Drew Adams
2018-11-04 19:13 ` Live System User
2018-11-22 22:03 ` Juri Linkov
2018-11-24 12:55 ` Charles A. Roelli
2018-11-04 16:47 ` Drew Adams
2018-11-04 22:59 ` Juri Linkov
2018-11-05 2:41 ` Drew Adams
2018-11-10 14:27 ` Charles A. Roelli
2018-11-10 20:45 ` Juri Linkov
2018-11-11 9:49 ` Charles A. Roelli
2018-11-11 20:02 ` Juri Linkov
2018-11-13 21:48 ` Drew Adams
2018-11-14 22:36 ` Juri Linkov [this message]
2018-11-15 8:02 ` Live System User
2018-11-15 21:16 ` Juri Linkov
2018-11-20 23:43 ` Juri Linkov
2018-11-15 21:15 ` Charles A. Roelli
2018-11-15 21:58 ` Juri Linkov
2018-11-16 20:03 ` Charles A. Roelli
2018-11-17 21:59 ` Juri Linkov
2018-11-20 23:52 ` Juri Linkov
[not found] <<m2ineavxaz.fsf@aurox.ch>
2017-11-16 22:25 ` Drew Adams
2017-11-19 17:12 ` Charles A. Roelli
[not found] <<<m2ineavxaz.fsf@aurox.ch>
[not found] ` <<1585f8e7-72a7-497c-9879-8bf1dda3f28f@default>
[not found] ` <<m2a7ziw5uf.fsf@aurox.ch>
2017-11-19 19:06 ` Drew Adams
2017-11-20 19:25 ` Charles A. Roelli
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=87va4zmglm.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=29321@debbugs.gnu.org \
--cc=charles@aurox.ch \
/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).