From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#40808: 27.0.91; inaccuracy in isearch-lazy-count Date: Thu, 07 Jul 2022 20:09:07 +0300 Organization: LINKOV.NET Message-ID: <868rp4hmto.fsf@mail.linkov.net> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29474"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: Eli Zaretskii , "40808@debbugs.gnu.org" <40808@debbugs.gnu.org>, "abdullah@net-c.com" To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 07 19:35:22 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o9VPN-0007T3-9P for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 Jul 2022 19:35:21 +0200 Original-Received: from localhost ([::1]:59756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9VPL-0000H0-Qn for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 Jul 2022 13:35:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9VP4-0000Fz-LG for bug-gnu-emacs@gnu.org; Thu, 07 Jul 2022 13:35:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35648) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o9VP4-0001pO-BX for bug-gnu-emacs@gnu.org; Thu, 07 Jul 2022 13:35:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o9VP4-0003Pk-1k for bug-gnu-emacs@gnu.org; Thu, 07 Jul 2022 13:35:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Jul 2022 17:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40808 X-GNU-PR-Package: emacs Original-Received: via spool by 40808-submit@debbugs.gnu.org id=B40808.165721528313083 (code B ref 40808); Thu, 07 Jul 2022 17:35:01 +0000 Original-Received: (at 40808) by debbugs.gnu.org; 7 Jul 2022 17:34:43 +0000 Original-Received: from localhost ([127.0.0.1]:57775 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o9VOl-0003Ox-7H for submit@debbugs.gnu.org; Thu, 07 Jul 2022 13:34:43 -0400 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:55269) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o9VOk-0003Oj-1h for 40808@debbugs.gnu.org; Thu, 07 Jul 2022 13:34:42 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 8C74F40002; Thu, 7 Jul 2022 17:34:34 +0000 (UTC) In-Reply-To: (Drew Adams's message of "Mon, 12 Jul 2021 01:58:14 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:236397 Archived-At: --=-=-= Content-Type: text/plain > What's the status of this bug? Apart from the request > by Juri for changes to be made to Org mode, is the code > Juri prescribed for this bug fix going to be applied, > or has it been applied? > > Is fixing this bug (e.g. with Juri's code) somehow > dependent on also fixing some Org-mode code? Fortunately, the isearch fix doesn't depend on org-mode. So here is the complete implementation that was made possible thanks to the suggestions in https://lists.gnu.org/archive/html/emacs-devel/2022-06/msg01208.html For example, searching for the word "nongnu" in etc/ORG-NEWS when all outlines are collapsed with isearch-lazy-count=t will show such prompts: search-invisible = t 1/4 I-search: search-invisible = open 1/2 (invisible 2) I-search: search-invisible = nil 0/0 (invisible 4) I-search: where such numbers as "1/2" show the matches that can be visited by isearch, and "(invisible 2)" are the rest of matches unreachable by isearch. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=lazy-count-invisible.patch diff --git a/lisp/isearch.el b/lisp/isearch.el index db7b53c014..945dce029a 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -466,6 +466,12 @@ lazy-count-suffix-format :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 @@ isearch-mode 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-lazy-count-format (- 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 @@ isearch-range-invisible (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 @@ isearch-range-invisible (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 @@ isearch-lazy-highlight-forward (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 @@ isearch-lazy-highlight-new-loop ;; 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,11 +4182,13 @@ isearch-lazy-highlight-search (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))) - (retry t) + ;; Count all invisible matches, but highlight only + ;; according to search-invisible without opening overlays. + (search-invisible (or isearch-lazy-count + (if (eq search-invisible 'open) + 'can-be-opened + search-invisible))) + (retry t) (success nil)) ;; Use a loop like in `isearch-search'. (while retry @@ -4186,15 +4204,23 @@ isearch-lazy-highlight-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))))) + (unless (and isearch-lazy-count + ;; Recheck the match that possibly was intended + ;; for counting only, but not for highlighting + (not (let ((search-invisible + (if (eq search-invisible 'open) + 'can-be-opened + search-invisible))) + (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 +4354,19 @@ isearch-lazy-highlight-buffer-update (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 + (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 --=-=-=--