Subject: Re: bug#16493: 24.3.50; (setq search-invisible t) is useless, let's allow to turn visible-mode temporarily on

From: Bastien <[email-masked]>
Date: Sun, 29 Apr 2018 11:50:58 +0200

Hi Stefan,

Stefan Monnier <[email-masked]> writes:

>>> Removing just the text property seems cleaner.
>> I guess this solution, though nice, is tricky to implement.
>
> Why do you think so?

I looked at the way isearch does the temporary opening of overlays,
and it looks complex to add another mechanism to temporarily ignore
the 'invisible text property.  At least I don't know how to do this.

Also, I tried a preliminary patches (attached) which I find quite
convenient and seems to do what I expected first when setting
(setq search-invisible t): turning on visible-mode.

The patch is not fully tested and incomplete, as query-replace is
not handled, but that's a start.

Let me know what you think.

Thanks,

-- 
 Bastien
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 3725779..53958cc 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -665,6 +665,8 @@ isearch-input-method-local-p
 
 (defvar isearch--saved-overriding-local-map nil)
 
+(defvar isearch-initial-visibility-state nil)
+
 ;; Minor-mode-alist changes - kind of redundant with the
 ;; echo area, but if isearching in multiple windows, it can be useful.
 
@@ -936,6 +938,8 @@ isearch-mode
       (if minibuffer-auto-raise
 	  (raise-frame frame))))
 
+  (setq isearch-initial-visibility-state (or visible-mode -1))
+  (when (eq isearch-invisible t) (visible-mode 1))
   (setq	isearch-mode " Isearch")  ;; forward? regexp?
   (force-mode-line-update)
 
@@ -1054,6 +1058,7 @@ isearch-done
   (remove-hook 'post-command-hook 'isearch-post-command-hook)
   (remove-hook 'mouse-leave-buffer-hook 'isearch-done)
   (remove-hook 'kbd-macro-termination-hook 'isearch-done)
+  (visible-mode isearch-initial-visibility-state)
   (setq isearch-lazy-highlight-start nil)
   (when (buffer-live-p isearch--current-buffer)
     (with-current-buffer isearch--current-buffer
@@ -1608,7 +1613,9 @@ isearch--momentary-message
   (isearch--momentary-message
    (if (setq isearch-invisible
              (if isearch-invisible
-                 nil (or search-invisible 'open)))
+                 (and (visible-mode -1) nil)
+               (visible-mode 1)
+               (or search-invisible 'open)))
        "match invisible text"
      "match visible text")))