emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9d292262f55: Improve invisibility handling in isearch-lazy-highli


From: Juri Linkov
Subject: master 9d292262f55: Improve invisibility handling in isearch-lazy-highlight (bug#40808)
Date: Mon, 20 Nov 2023 12:59:00 -0500 (EST)

branch: master
commit 9d292262f55cd016a1a59f4d4ef31446bb2ba9c6
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    Improve invisibility handling in isearch-lazy-highlight (bug#40808)
    
    * lisp/isearch.el (isearch-lazy-highlight-invisible): New variable.
    (isearch-lazy-highlight-new-loop, isearch-lazy-highlight-search)
    (isearch-lazy-highlight-match, isearch-lazy-highlight-buffer-update): Use 
it.
    
    * lisp/replace.el (replace-highlight): Let-bind isearch-invisible
    to search-invisible.
    
    * test/lisp/isearch-tests.el (isearch--test-invisible): New test.
---
 lisp/isearch.el            |  18 ++++--
 lisp/replace.el            |   1 +
 test/lisp/isearch-tests.el | 151 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 165 insertions(+), 5 deletions(-)

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 4d231fba469..4672440bdff 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -4054,6 +4054,7 @@ since they have special meaning in a regexp."
 (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)
@@ -4099,6 +4100,8 @@ by other Emacs features."
                             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
@@ -4177,6 +4180,7 @@ by other Emacs features."
          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
@@ -4226,8 +4230,10 @@ Attempt to do the search exactly the way the pending 
Isearch would."
            (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'.
@@ -4247,7 +4253,9 @@ Attempt to do the search exactly the way the pending 
Isearch would."
   (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)
@@ -4396,9 +4404,9 @@ Attempt to do the search exactly the way the pending 
Isearch would."
                          ;; 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 ac677db2feb..ff7ca1145b8 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2755,6 +2755,7 @@ to a regexp that is actually used for the search.")
            (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 e71f0a5785f..693f15336f2 100644
--- a/test/lisp/isearch-tests.el
+++ b/test/lisp/isearch-tests.el
@@ -39,6 +39,157 @@
   (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.
 
 (defun isearch--test-search-within-boundaries (pairs)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]