Suppose I have a function like my-make-invisible
, where my-re
is some regexp:
(defun my-make-invisible ()
(save-excursion
(goto-char (point-min))
(while (re-search-forward my-re nil t)
(add-text-properties (match-beginning 0)
(match-end 0)
'(invisible t)))))
This function just makes each portion of buffer content that matches my-re
invisible: it works in all major modes I've tried, but not in org-mode.
Is there an easy way to achieve the same in org-mode?
(Note: adding other properties, like faces or displays, with a function like the one above does work in org-mode. It seems that the problem is only adding invisibility)
I have the same problem if I try to make things invisible by adding them to buffer-invisibility-spec
. Except for when the buffer is in org-mode, the following makes the first three characters in the buffer invisible:
(progn (add-text-properties 1 3 '(invisible hide-this-stuff))
(add-to-invisibility-spec '(hide-this-stuff)))
If I do it in org-mode, hide-this-stuff
will show up in the value of buffer-invisibility-spec
but this has no effect whatsoever as far as the visibility of those first three characters.
font-lock-mode
does and since the latter runs in the background, it wins. You can see that that is the case by toggling it off:M-x font-lock-mode
. I would guess that you need to do search-based fontification in this case, instead of search based text-property setting. See theFont lock
section in the Emacs manual and references therein, particularly the reference toSearch-based fontification
in the Elisp manual. You can start withC-h i g(emacs)Font lock
and go from there.