Emacs隐藏/显示支持C ++三斜杠Doxygen标记? [英] Emacs hide/show support for C++ triple-slash Doxygen markup?

查看:145
本文介绍了Emacs隐藏/显示支持C ++三斜杠Doxygen标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

  class foo 
///一句简单的foo描述。详细说明可以
///继续许多行。
{
...
};

void foo :: bar
///一个句子简要描述吧。详细说明可以
///继续许多行。
()const
{
...
}



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

  class foo 
{
int _var1; ///< _var1的简要说明。
int _var2; ///< _var2
///<需要额外的线路。
}

void foo :: bar
(int arg1 ///< arg1的简要说明
,int arg2 ///< A brief描述arg2
///<需要额外的行
)const
{
...
}

我不知道处理这些约定存在什么隐藏/显示支持。
最重要的情况是块标记注释。理想情况下,我将
想要完全消除这些,这意味着我将
不想浪费一行只是为了表示存在折叠的
块标记注释,喜欢边缘标记, a hideshowvis.el

解决方案

也许,作为部分答案,以下代码片段将会做到这一点。
按C ++中的M-s M-s模式,它隐藏了您所描述的所有评论。再次按M-s M-s再次显示评论。我知道短代码有其局限性:


  1. 如果可以分别隐藏/显示每个特殊注释,这将是很好的。


  2. 由于所有特别评论都被隐藏,所以您经常需要Ms Ms女士。因此, hs1-mode 应该在大型C ++文件上更有效(也许应该通过 jit-font-lock


  3. 连续一行的特殊评论应加入一个隐藏的块。


  4. < $>




     (defvar hs1-regexp 
    \\(\ n [[:blank:]] * /// \\ | ///< \\)* $
    要隐藏的块的正则表达式列表)

    (define-minor-mode hs1-mode
    隐藏/显示预定义的块
    :更轻hs1
    (如果hs1-mode
    let(ol)
    (save-excursion
    (goto-char(point-min))
    (while(search-forward-regexp hs1-regexp nil'noErr)
    当(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 set-key(kbdMs Ms)'hs1-mode)))


    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.

    解决方案

    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:

    1. It would be nice if one could hide/show each special comment separately.

    2. 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).

    3. 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)))
    

    这篇关于Emacs隐藏/显示支持C ++三斜杠Doxygen标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆