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: Sat, 10 Dec 2022 19:51:39 +0200 Organization: LINKOV.NET Message-ID: <86cz8rgn9w.fsf@mail.linkov.net> References: <868rp4hmto.fsf@mail.linkov.net> 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="22859"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) To: 40808@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 10 18:55:30 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 1p444P-0005h2-2h for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Dec 2022 18:55:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4441-0004NA-OW; Sat, 10 Dec 2022 12:55:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p443y-0004Mg-Kk for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2022 12:55:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p443y-0008It-6v for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2022 12:55:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p443x-0001gC-Sa for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2022 12:55:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Dec 2022 17:55: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.16706948636434 (code B ref 40808); Sat, 10 Dec 2022 17:55:01 +0000 Original-Received: (at 40808) by debbugs.gnu.org; 10 Dec 2022 17:54:23 +0000 Original-Received: from localhost ([127.0.0.1]:44229 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p443K-0001ff-HL for submit@debbugs.gnu.org; Sat, 10 Dec 2022 12:54:23 -0500 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:37979) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p443I-0001fY-Hh for 40808@debbugs.gnu.org; Sat, 10 Dec 2022 12:54:21 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 7DB581C0003 for <40808@debbugs.gnu.org>; Sat, 10 Dec 2022 17:54:13 +0000 (UTC) In-Reply-To: <868rp4hmto.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 07 Jul 2022 20:09:07 +0300") 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:250541 Archived-At: --=-=-= Content-Type: text/plain > 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. Here are more fixes with tests: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=isearch-lazy-highlight-invisible.patch diff --git a/lisp/isearch.el b/lisp/isearch.el index bc3697deb0a..529676042a2 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -2525,10 +2525,11 @@ isearch-delete-char (ding) (isearch-pop-state)) ;; When going back to the hidden match, reopen it and close other overlays. - (when (and (eq search-invisible 'open) isearch-hide-immediately) + (when (and (eq isearch-invisible 'open) isearch-hide-immediately) (if isearch-other-end - (isearch-range-invisible (min (point) isearch-other-end) - (max (point) isearch-other-end)) + (let ((search-invisible isearch-invisible)) + (isearch-range-invisible (min (point) isearch-other-end) + (max (point) isearch-other-end))) (isearch-close-unnecessary-overlays (point) (point)))) (isearch-update)) @@ -4008,6 +4009,7 @@ isearch-lazy-highlight-point-min (defvar isearch-lazy-highlight-point-max nil) (defvar isearch-lazy-highlight-buffer nil) (defvar isearch-lazy-highlight-case-fold-search nil) +(defvar isearch-lazy-highlight-invisible nil) (defvar isearch-lazy-highlight-regexp nil) (defvar isearch-lazy-highlight-lax-whitespace nil) (defvar isearch-lazy-highlight-regexp-lax-whitespace nil) @@ -4053,6 +4055,8 @@ isearch-lazy-highlight-new-loop isearch-lazy-highlight-window-group)) (not (eq isearch-lazy-highlight-case-fold-search isearch-case-fold-search)) + (not (eq isearch-lazy-highlight-invisible + isearch-invisible)) (not (eq isearch-lazy-highlight-regexp isearch-regexp)) (not (eq isearch-lazy-highlight-regexp-function @@ -4131,6 +4135,7 @@ isearch-lazy-highlight-new-loop isearch-lazy-highlight-wrapped nil isearch-lazy-highlight-last-string isearch-string isearch-lazy-highlight-case-fold-search isearch-case-fold-search + isearch-lazy-highlight-invisible isearch-invisible isearch-lazy-highlight-regexp isearch-regexp isearch-lazy-highlight-lax-whitespace isearch-lax-whitespace isearch-lazy-highlight-regexp-lax-whitespace isearch-regexp-lax-whitespace @@ -4180,8 +4185,10 @@ isearch-lazy-highlight-search (isearch-forward isearch-lazy-highlight-forward) ;; 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)) + (search-invisible + (or (not (null isearch-lazy-count)) + (and (eq isearch-lazy-highlight-invisible 'open) + 'can-be-opened))) (retry t) (success nil)) ;; Use a loop like in `isearch-search'. @@ -4201,7 +4208,9 @@ isearch-lazy-highlight-match (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)) + (let ((search-invisible + (and (eq isearch-lazy-highlight-invisible 'open) + 'can-be-opened))) (funcall isearch-filter-predicate mb me))) (let ((ov (make-overlay mb me))) (push ov isearch-lazy-highlight-overlays) @@ -4350,9 +4359,9 @@ isearch-lazy-highlight-buffer-update ;; value `open' since then lazy-highlight ;; will open all overlays with matches. (if (not (let ((search-invisible - (if (eq search-invisible 'open) + (if (eq isearch-lazy-highlight-invisible 'open) 'can-be-opened - search-invisible))) + isearch-lazy-highlight-invisible))) (funcall isearch-filter-predicate mb me))) (setq isearch-lazy-count-invisible (1+ (or isearch-lazy-count-invisible 0))) diff --git a/lisp/replace.el b/lisp/replace.el index c7ae77d128b..11e30e62a9e 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2744,6 +2744,7 @@ replace-highlight (isearch-regexp-lax-whitespace replace-regexp-lax-whitespace) (isearch-case-fold-search case-fold) + (isearch-invisible search-invisible) (isearch-forward (not backward)) (isearch-other-end match-beg) (isearch-error nil) diff --git a/test/lisp/isearch-tests.el b/test/lisp/isearch-tests.el index 8cb5e5e4542..37a0ba8579c 100644 --- a/test/lisp/isearch-tests.el +++ b/test/lisp/isearch-tests.el @@ -38,6 +38,157 @@ isearch--test-done ;; Bug #21091: let `isearch-done' work without `isearch-update'. (isearch-done)) + +;; Search invisible. + +(declare-function outline-hide-sublevels "outline") + +(ert-deftest isearch--test-invisible () + (require 'outline) + (with-temp-buffer + (set-window-buffer nil (current-buffer)) + (insert "\n1\n" + (propertize "2" 'invisible t) + (propertize "3" 'inhibit-isearch t) + "\n* h\n4\n\n") + (outline-mode) + (outline-hide-sublevels 1) + (goto-char (point-min)) + + (let ((isearch-lazy-count nil) + (search-invisible t) + (inhibit-message t)) + + (isearch-forward-regexp nil 1) + (isearch-process-search-string "[0-9]" "[0-9]") + (should (eq (point) 3)) + + (isearch-lazy-highlight-start) + (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) + '(2))) + + (isearch-repeat-forward) + (should (eq (point) 5)) + (should (get-char-property 4 'invisible)) + (isearch-repeat-forward) + (should (eq (point) 12)) + (should (get-char-property 11 'invisible)) + + (goto-char isearch-opoint) + (isearch-done t) + + (isearch-forward-regexp nil 1) + (setq isearch-invisible nil) ;; isearch-toggle-invisible + (isearch-process-search-string "[0-9]" "[0-9]") + + (isearch-lazy-highlight-start) + (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) + '(2))) + + (goto-char isearch-opoint) + (isearch-done t) + + (isearch-forward-regexp nil 1) + (setq isearch-invisible 'open) ;; isearch-toggle-invisible + (isearch-process-search-string "[0-9]" "[0-9]") + (should (eq (point) 3)) + + (isearch-lazy-highlight-start) + (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) + '(2 11))) + + (let ((isearch-hide-immediately t)) + (isearch-repeat-forward) + (should (eq (point) 12)) + (should-not (get-char-property 11 'invisible)) + (isearch-delete-char) + (should (get-char-property 11 'invisible))) + + (let ((isearch-hide-immediately nil)) + (isearch-repeat-forward) + (should (eq (point) 12)) + (should-not (get-char-property 11 'invisible)) + (isearch-delete-char) + (should-not (get-char-property 11 'invisible))) + + (goto-char isearch-opoint) + (isearch-done t) + (isearch-clean-overlays) + (should (get-char-property 11 'invisible))) + + (let ((isearch-lazy-count t) + (search-invisible t) + (inhibit-message t)) + + (isearch-forward-regexp nil 1) + (isearch-process-search-string "[0-9]" "[0-9]") + (should (eq (point) 3)) + + (setq isearch-lazy-count-invisible nil isearch-lazy-count-total nil) + (isearch-lazy-highlight-start) + (isearch-lazy-highlight-buffer-update) + (should (eq isearch-lazy-count-invisible nil)) + (should (eq isearch-lazy-count-total 3)) + (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) + '(2))) + + (isearch-repeat-forward) + (should (eq (point) 5)) + (should (get-char-property 4 'invisible)) + (isearch-repeat-forward) + (should (eq (point) 12)) + (should (get-char-property 11 'invisible)) + + (goto-char isearch-opoint) + (isearch-done t) + + (isearch-forward-regexp nil 1) + (setq isearch-invisible nil) ;; isearch-toggle-invisible + (isearch-process-search-string "[0-9]" "[0-9]") + + (setq isearch-lazy-count-invisible nil isearch-lazy-count-total nil) + (isearch-lazy-highlight-start) + (isearch-lazy-highlight-buffer-update) + (should (eq isearch-lazy-count-invisible 2)) + (should (eq isearch-lazy-count-total 1)) + (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) + '(2))) + + (goto-char isearch-opoint) + (isearch-done t) + + (isearch-forward-regexp nil 1) + (setq isearch-invisible 'open) ;; isearch-toggle-invisible + (isearch-process-search-string "[0-9]" "[0-9]") + (should (eq (point) 3)) + + (setq isearch-lazy-count-invisible nil isearch-lazy-count-total nil) + (isearch-lazy-highlight-start) + (isearch-lazy-highlight-buffer-update) + (should (eq isearch-lazy-count-invisible 1)) + (should (eq isearch-lazy-count-total 2)) + (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) + '(2 11))) + + (let ((isearch-hide-immediately t)) + (isearch-repeat-forward) + (should (eq (point) 12)) + (should-not (get-char-property 11 'invisible)) + (isearch-delete-char) + (should (get-char-property 11 'invisible))) + + (let ((isearch-hide-immediately nil)) + (isearch-repeat-forward) + (should (eq (point) 12)) + (should-not (get-char-property 11 'invisible)) + (isearch-delete-char) + (should-not (get-char-property 11 'invisible))) + + (goto-char isearch-opoint) + (isearch-done t) + (isearch-clean-overlays) + (should (get-char-property 11 'invisible))))) + ;; Search functions. --=-=-=--