Emacs隐藏/显示对C++三斜杠Doxygen标记的支持?

Joh*_*tes 5 c++ emacs doxygen

我使用Doxygen的三斜杠语法来标记我的C++代码.有两个重要案例出现:

1)阻止标记注释,这是线上唯一的元素,可能会或可能不会开始向左冲洗; 例如

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
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

2)尾随标记注释,它们在第一行之前总是遵循一定数量的C++标记,但仍可能溢出到后续行; 例如

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
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

我想知道有什么隐藏/显示支持来处理这些约定.最重要的情况是块标记注释.理想情况下,我希望能够完全消除这些,这意味着我不想简单地浪费一条线来表示存在折叠的块标记注释,而更喜欢边缘标记,la hideshowvis.el.

Tob*_*ias 3

也许,作为部分答案,以下代码片段可以解决问题。在 C++ 模式下按 Ms Ms,它会隐藏您所描述的所有注释。再次按下女士的按钮,女士再次露出评论。我知道短代码有其局限性:

  1. 如果可以单独隐藏/显示每个特殊评论,那就太好了。

  2. 由于所有特殊评论都是隐藏的,因此您会经常需要 Ms Ms。因此,hs1-mode对大型 C++ 文件应该更有效(也许,它应该通过 实现jit-font-lock)。

  3. 连续的特殊注释行应连接到一个隐藏块中。


(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)))
Run Code Online (Sandbox Code Playgroud)