gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:42:02 27 4
gpt4 key购买 nike

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

1) block 标记注释,它是行中唯一的元素,可能 或者可能不会开始向左齐平;例如

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) 始终跟在一定数量的 C++ 后面的尾随标记注释 第一行较早的 token ,但仍可能溢出 后续行;例如

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
{
...
}

我想知道存在哪些隐藏/显示支持来处理这些约定。最重要的情况是 block 标记注释。理想情况下我会希望能够完全消除这些,这意味着我会不想仅仅为了表示折叠的存在而浪费一行 block 标记评论,更喜欢边缘标记,la hideshowvis.el .

最佳答案

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

  1. 如果能分别隐藏/显示每个特殊评论就好了。

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

  3. 特殊评论的连续行应合并到一个隐藏 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)))

关于c++ - Emacs 隐藏/显示对 C++ 三斜杠 Doxygen 标记的支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2936111/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com