: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.")
+
\f
;; Define isearch help map.
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.
(- 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 "?")))
"")))
\f
(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.
(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)))))))
(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.")
;; 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))
(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'.
(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."
(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