Reputation: 1057
I use Doxygen's triple-slash syntax to markup my C++ code. There are two important cases which arise:
1) block markup comments which are the sole element on the line and may or may not begin flush left; e.g.
class foo
/// A one sentence brief description of foo. The elaboration can
/// continue on for many lines.
{
...
};
void foo::bar
/// A one sentence brief description of bar. The elaboration can
/// continue on for many lines.
() const
{
...
}
2) trailing markup comments which always follow some number of C++ tokens earlier on the first line but may still spill over onto subsequent lines; e.g.
class foo
{
int _var1; ///< A brief description of _var1.
int _var2; ///< A brief description of _var2
///< requiring additional lines.
}
void foo::bar
( int arg1 ///< A brief description of arg1.
, int arg2 ///< A brief description of arg2
///< requiring additional lines.
) const
{
...
}
I wonder what hide/show support exists to deal with these conventions. The most important cases are the block markup comments. Ideally I would like to be able to eliminate these altogether, meaning that I would prefer not to waste a line simply to indicate presence of a folded block markup comment, preferring a fringe marker, a la hideshowvis.el.
Upvotes: 5
Views: 1033
Reputation: 5198
Maybe, as a partial answer the following snippet of code would do the trick. Press M-s M-s in C++-mode and it hides all comments of the kind you described. Again pressing M-s M-s reveals the comments again. I know that the short code has its limitations:
It would be nice if one could hide/show each special comment separately.
Since all special comments are hidden you would need M-s M-s quite often. Therefore, hs1-mode
should be more effective on large C++-files (maybe, it should be implmented via jit-font-lock
).
Consecutive lines of special comments should be joined to one hidden block.
(defvar hs1-regexp
"\\(\n[[:blank:]]*///\\|///<\\).*$"
"List of regular expressions of blocks to be hidden.")
(define-minor-mode hs1-mode
"Hide/show predefined blocks."
:lighter " hs1"
(if hs1-mode
(let (ol)
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp hs1-regexp nil 'noErr)
(when (eq (syntax-ppss-context (syntax-ppss (match-end 1))) 'comment)
(setq ol (make-overlay (match-beginning 0) (match-end 0)))
(overlay-put ol 'hs1 t)
(overlay-put ol 'invisible t)
))))
(remove-overlays (point-min) (point-max) 'hs1 t)
))
(add-hook 'c++-mode-hook '(lambda () (local-set-key (kbd "M-s M-s") 'hs1-mode)))
Upvotes: 3