Q: how can I get isearch to understand invisible text properties, not just overlays?

I'm writing a major mode that uses text properties rather than overlays to toggle visibility. I'd like to use isearch to be able to find invisible text and make it visible, but don't know how to convince isearch to do so.

As an example, evaluate the following function in a buffer:

(defun try-me ()
  (let ((text (concat (propertize "Visible text" 'invisible nil)
                      (propertize "\nOtters" 'invisible t))))
    (insert text)))

It will insert one line of visible text "Visible text", and another line of invisible text "Otters" below it.

Using isearch to search for "Otters" results in no hits.

How can I get isearch a) to find text with the invisible text property, and b) get it to toggle the invisible text property so it's visible? (I imagine I'll need a custom function to do that, but don't know how to get isearch to use that function.)

  • 1
    Actually, Isearch does understand and respect text that is made invisible using text properties. Trying to search for matches in invisible text will not find them - the text is invisible to searching. I think what you want to ask is how to get Isearch to open invisible text, that is, to find matches in invisible text, rendering it temporarily visible. That, at that alone, is what Isearch does not do wrt text made invisible by text property instead of overlay. It does not respect an open value of search-invisible when the text is made invisible using text properties. – Drew May 17 '19 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.