1

我正在寻找一种为现有源文件中的函数自动生成 doxygen 注释块的方法。在查看替代方案时,我看到了对 SRecode 中现有机制的引用,该机制可以生成正确的注释srecode-document-insert-function-comment。在使用 启用标签生成M-x semantic-mode和使用 SRecode 之后M-x srecode-minor-mode。一切似乎都在工作,模板和表格似乎在使用 SRecode 调试功能时检测到了 c 模式。

但是,当我使用 SRecode->Generate 菜单选项,而不是 doxygen 函数注释时,我得到一个简单的注释,如下所示:

/** main --
* 
*/
void main(int argc, char **argv)

除了以下消息,我什么也没有收到C-h e

Adding srecode-insert-getset to srecode menu
Adding srecode-document-insert-comment to srecode menu

我已经在其他功能上尝试过,并尝试使用 edebug-defun 进行调试,但我无法理解输出。

有人可以建议需要哪些其他设置吗?

额外细节:

  • 2013 年 3 月 17 日在 MARVIN 上的 GNU Emacs 24.3.1 (i386-mingw-nt6.1.7601)
  • 语义 2.2
  • SRecode 1.2

更新 20131009:

  • 从不同的光标位置重试(例如在函数内部,在函数名称的开头)会产生相同的结果
  • 从菜单调用或直接调用函数会产生相同的结果
  • 我在 .emacs 中没有针对语义或 SRemote 的特殊自定义,并且在我按上述具体调用它们之前不会启用这些模式(也许这实际上是缺少的;是否需要某种全局设置?)

更新 20131012:

  • 使用不同的 PC(具有不同的配置)重试,并使用 -q 启动选项忽略 .emacs 文件。在这两种情况下,输出都是相同的。

更新 20131013:

  • 第一次运行 generate 后,我在 *messages* 缓冲区中注意到以下内容。也许里面有暗示。

    Adding srecode-insert-getset to srecode menu
    Adding srecode-document-insert-comment to srecode menu
    Adding srecode-insert-getset to srecode menu
    Adding srecode-document-insert-comment to srecode menu
    Compiling template default.srt...
    2 templates compiled for default
    Templates default.srt has estimated priority of 80
    Compiling template c.srt...
    17 templates compiled for c-mode
    Templates c.srt has estimated priority of 90
    Compiling template c.srt...
    14 templates compiled for c-mode
    Templates c.srt has estimated priority of 90
    Compiling template doc-default.srt...
    7 templates compiled for default
    Templates doc-default.srt has estimated priority of 80
    Auto-saving...done
    
4

3 回答 3

1

Looks like someone at some point moved doc-c.srt to doc-cpp.srt instead of copying it (this is emacs 24.3.1).
As a result srecode-document-insert-comment works (as you expect it to) only in c++-mode.
In order to enable it for c-mode create a file ~/.srecode/doc-c.srt with the following content and it should work fine.

;; doc-c.srt --- SRecode templates for "document" applications

;; Copyright (C) 2008-2013 Free Software Foundation, Inc.

;; Author: Eric M. Ludlam <eric@siege-engine.com>

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

set mode "c-mode"

set application "document"
context declaration

;;; Notes on the DOCUMENT templates.
;;
;; These templates recycle existing templates for doxygen in the
;; more general C template set.

template section-comment :indent :blank
"A comment separating major sections of a file."
----
{{>:declaration:doxygen-section-comment}}
----

template function-comment :tag :indent :blank
"A comment occurring in front of a function.
Recycle doxygen comment code from the more general template set."
----
{{>:declaration:doxygen-function}}
----

template variable-same-line-comment :tag
"A comment occurring after a variable declaration.
Recycle doxygen comment code from the more general template set."
----
{{>:declaration:doxygen-variable-same-line}}
----

;; These happen to be the same as in a classdecl.
template group-comment-start :blank :indent
"A comment occurring in front of a group of declarations.
Recycle doxygen comment code from the more general template set."
----
{{>:classdecl:doxygen-function-group-start}}
----

template group-comment-end :blank :indent
"A comment occurring at the end of a group of declarations.
Recycle doxygen comment code from the more general template set."
----
{{>:classdecl:doxygen-function-group-end}}
----

;; end

An alternative for doxygen comment generation would be doxymacs

于 2013-10-24T15:35:09.720 回答
0

您的光标应该在左括号之前。如果您在参数列表中,则不会插入任何内容。

于 2013-10-09T18:04:03.240 回答
0

您应该与函数名在同一行,或者在函数的定义中 - 然后,srecode-document-insert-comment( C-c / C) 将插入正确的注释。这是我的 CEDET 安装中此命令的结果(来自 bzr,尽管在 24.3.1 中它应该是相同的):

/**
 * @name main - 
 * @param argc - Number of arguments
 * @param argv - Argument vector
 * @return int
 */
int main(int argc, char **argv) {

    return 0;
}
于 2013-10-09T07:30:07.590 回答