This is actually two questions:
Does anybody know an emacs feature that can hide (and maybe indicates that it has done so) selected forms in lisp code ? I've written some performance oriented common lisp and the key functions do contain lots of (declare (type ...))
forms that clutter the code.
If not, does anybody have suggestions on where to be inspired / steal something that would enable me to write it myself ?
Cheers and thanks!
Write a function that finds the start and end positions of the text you want to make invisible. Then use (put-text-property START END 'invisible t)
to make the text invisible.
For a quick-and-dirty example, use (search-forward "(declare (type " nil t)
. (match-beginning 0)
is the start position of that sexp, so (goto-char (match-beginning 0))
, then do (forward-sexp 1)
to get to its end position. Then use put-text-property
as above, to hide the text from the start of the declare
sexp until its end. Do that in a loop, to hide all such sexps.
To be more careful, you would use a regexp that allows variable whitespace (including newlines) in the sexp, etc. But just the above should get you started.
(To make invisible text visible again, just use (put-text-property START END 'invisible nil)
.)