In hs-mode, is there a way to only hide the comments (C-style, delimited by /* ...*/
), and no other blocks of code?
(there was nothing obvious in M-x customize-group hideshow)
You can just set hs-hide-all-non-comment-function
to #'ignore
.
If you want to do that globally put the following in your init file:
(setq hs-hide-all-non-comment-function #'ignore)
If you want to do that only for certain major modes replace my-major-mode
with the major mode of your choice and put the modified line in your init file:
(add-hook 'mine-major-mode (lambda () (setq-local hs-hide-all-non-comment-function #'ignore)))
This does not directly answer your question, but it might be an alternative to consider.
Library hide-comnt.el
is designed to let you hide or ignore comments.
There are commands to hide, show, and toggle showing comments.
There is a macro, with-comments-hidden
, that you can use to wrap code that you want to ignore text in comments.
You can set or bind option ignore-comments-flag
to nil
to inhibit ignoring comments by the macro.
You can use option hide-whitespace-before-comment-flag
to hide also the whitespace preceding a comment (other than empty lines).
You can use option show-invisible-comments-shows-all
to cause all invisible text to reappear when you turn off hiding comments. (By default, only the hidden comments reappear.)
I can't speak to how well hide-comnt.el
might play with hs-mode
. An untested guess is that it will work just fine. It uses a specific value (hide-comment
) for text property invisible
, so I don't expect any conflict.