diff options
author | Juri Linkov <juri@linkov.net> | 2022-07-08 20:47:11 +0300 |
---|---|---|
committer | Juri Linkov <juri@linkov.net> | 2022-07-08 20:47:11 +0300 |
commit | 3cfac1fe073815bdbba96e3a35a1c15626022c07 (patch) | |
tree | 6e78c7c8c9bca68e1efced581b91bf2c6f88d99a /lisp/isearch.el | |
parent | ef559dcd2ab3ec6e1f714180cbdf3b4e0965c13d (diff) | |
download | emacs-3cfac1fe073815bdbba96e3a35a1c15626022c07.tar.gz |
Display the number of invisible matches for isearch-lazy-count (bug#40808)
* lisp/isearch.el (lazy-count-invisible-format): New variable.
(isearch-mode): Set isearch-lazy-count-invisible to nil.
(isearch-lazy-count-format): Use lazy-count-invisible-format and
isearch-lazy-count-invisible.
(isearch-range-invisible): Handle the value 'can-be-opened' of
'search-invisible' and don't open overlays for it, just check
if these overlays can be opened.
(isearch-lazy-count-invisible): New variable.
(isearch-lazy-highlight-new-loop): Set isearch-lazy-count-invisible to nil.
(isearch-lazy-highlight-search): Let-bind search-invisible either to t
for non-nil isearch-lazy-count, or to 'can-be-opened'.
(isearch-lazy-highlight-match): Don't highlight matches intended
to be counted only, not highlighted.
(isearch-lazy-highlight-buffer-update): Separately count invisible
matches by isearch-lazy-count-invisible.
* lisp/info.el (Info-isearch-filter): Check if search-invisible is t.
Diffstat (limited to 'lisp/isearch.el')
-rw-r--r-- | lisp/isearch.el | 82 |
1 files changed, 57 insertions, 25 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el index db7b53c0147..ad8897dda2c 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -466,6 +466,12 @@ and doesn't remove full-buffer highlighting after a search." :group 'lazy-count :version "27.1") +(defvar lazy-count-invisible-format " (invisible %s)" + "Format of the number of invisible matches for the prompt. +When invisible matches exist, their number is appended +after the total number of matches. Display nothing when +this variable is nil.") + ;; Define isearch help map. @@ -1277,6 +1283,7 @@ used to set the value of `isearch-regexp-function'." isearch-lazy-count-current nil isearch-lazy-count-total nil + isearch-lazy-count-invisible nil ;; Save the original value of `minibuffer-message-timeout', and ;; set it to nil so that isearch's messages don't get timed out. @@ -3529,7 +3536,12 @@ isearch-message-suffix prompt. Otherwise, for isearch-message-prefix." (- isearch-lazy-count-total isearch-lazy-count-current -1))) - (or isearch-lazy-count-total "?")) + (if (and isearch-lazy-count-invisible + lazy-count-invisible-format) + (concat (format "%s" (or isearch-lazy-count-total "?")) + (format lazy-count-invisible-format + isearch-lazy-count-invisible)) + (or isearch-lazy-count-total "?"))) ""))) @@ -3780,10 +3792,11 @@ Optional third argument, if t, means if fail just return nil (no error). (save-excursion (goto-char beg) (let (;; can-be-opened keeps track if we can open some overlays. - (can-be-opened (eq search-invisible 'open)) + (can-be-opened (memq search-invisible '(open can-be-opened))) ;; the list of overlays that could be opened (crt-overlays nil)) - (when (and can-be-opened isearch-hide-immediately) + (when (and can-be-opened isearch-hide-immediately + (not (eq search-invisible 'can-be-opened))) (isearch-close-unnecessary-overlays beg end)) ;; If the following character is currently invisible, ;; skip all characters with that same `invisible' property value. @@ -3822,9 +3835,10 @@ Optional third argument, if t, means if fail just return nil (no error). (if (>= (point) end) (if (and can-be-opened (consp crt-overlays)) (progn - (setq isearch-opened-overlays - (append isearch-opened-overlays crt-overlays)) - (mapc 'isearch-open-overlay-temporary crt-overlays) + (unless (eq search-invisible 'can-be-opened) + (setq isearch-opened-overlays + (append isearch-opened-overlays crt-overlays)) + (mapc 'isearch-open-overlay-temporary crt-overlays)) nil) (setq isearch-hidden t))))))) @@ -4008,6 +4022,7 @@ since they have special meaning in a regexp." (defvar isearch-lazy-highlight-error nil) (defvar isearch-lazy-count-current nil) (defvar isearch-lazy-count-total nil) +(defvar isearch-lazy-count-invisible nil) (defvar isearch-lazy-count-hash (make-hash-table)) (defvar lazy-count-update-hook nil "Hook run after new lazy count results are computed.") @@ -4086,7 +4101,8 @@ by other Emacs features." ;; Reset old counter before going to count new numbers (clrhash isearch-lazy-count-hash) (setq isearch-lazy-count-current nil - isearch-lazy-count-total nil) + isearch-lazy-count-total nil + isearch-lazy-count-invisible nil) ;; Delay updating the message if possible, to avoid flicker (when (string-equal isearch-string "") (when (and isearch-mode (null isearch-message-function)) @@ -4166,10 +4182,10 @@ Attempt to do the search exactly the way the pending Isearch would." (isearch-regexp-lax-whitespace isearch-lazy-highlight-regexp-lax-whitespace) (isearch-forward isearch-lazy-highlight-forward) - ;; Don't match invisible text unless it can be opened - ;; or when counting matches and user can visit hidden matches - (search-invisible (or (eq search-invisible 'open) - (and isearch-lazy-count search-invisible))) + ;; Count all invisible matches, but highlight only + ;; matches that can be opened by visiting them later + (search-invisible (or (not (null isearch-lazy-count)) + 'can-be-opened)) (retry t) (success nil)) ;; Use a loop like in `isearch-search'. @@ -4186,15 +4202,20 @@ Attempt to do the search exactly the way the pending Isearch would." (error nil))) (defun isearch-lazy-highlight-match (mb me) - (let ((ov (make-overlay mb me))) - (push ov isearch-lazy-highlight-overlays) - ;; 1000 is higher than ediff's 100+, - ;; but lower than isearch main overlay's 1001 - (overlay-put ov 'priority 1000) - (overlay-put ov 'face 'lazy-highlight) - (unless (or (eq isearch-lazy-highlight 'all-windows) - isearch-lazy-highlight-buffer) - (overlay-put ov 'window (selected-window))))) + (when (or (not isearch-lazy-count) + ;; Recheck the match that possibly was intended + ;; for counting only, but not for highlighting + (let ((search-invisible 'can-be-opened)) + (funcall isearch-filter-predicate mb me))) + (let ((ov (make-overlay mb me))) + (push ov isearch-lazy-highlight-overlays) + ;; 1000 is higher than ediff's 100+, + ;; but lower than isearch main overlay's 1001 + (overlay-put ov 'priority 1000) + (overlay-put ov 'face 'lazy-highlight) + (unless (or (eq isearch-lazy-highlight 'all-windows) + isearch-lazy-highlight-buffer) + (overlay-put ov 'window (selected-window)))))) (defun isearch-lazy-highlight-start () "Start a new lazy-highlight updating loop." @@ -4328,11 +4349,22 @@ Attempt to do the search exactly the way the pending Isearch would." (setq found nil) (forward-char -1))) (when isearch-lazy-count - (setq isearch-lazy-count-total - (1+ (or isearch-lazy-count-total 0))) - (puthash (if isearch-lazy-highlight-forward me mb) - isearch-lazy-count-total - isearch-lazy-count-hash)) + ;; Count as invisible when can't open overlay, + ;; but don't leave search-invisible with the + ;; value `open' since then lazy-highlight + ;; will open all overlays with matches. + (if (not (let ((search-invisible + (if (eq search-invisible 'open) + 'can-be-opened + search-invisible))) + (funcall isearch-filter-predicate mb me))) + (setq isearch-lazy-count-invisible + (1+ (or isearch-lazy-count-invisible 0))) + (setq isearch-lazy-count-total + (1+ (or isearch-lazy-count-total 0))) + (puthash (if isearch-lazy-highlight-forward me mb) + isearch-lazy-count-total + isearch-lazy-count-hash))) ;; Don't highlight the match when this loop is used ;; only to count matches or when matches were already ;; highlighted within the current window boundaries |