使用SRecode为现有C文件生成doxygen注释

时间:2013-10-08 22:31:44

标签: emacs emacs24

我一直在寻找一种方法来为现有源文件中的函数自动生成doxygen注释块。在查看备选方案时,我看到了对SRecode中现有机制的引用,该机制可以使用srecode-document-insert-function-comment生成正确的注释。使用M-x semantic-mode启用代码生成后,使用M-x srecode-minor-mode启用SRecode。一切似乎都在工作,模板和表似乎在使用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-03-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
    

3 个答案:

答案 0 :(得分:1)

看起来有人在某个时候将doc-c.srt移动到doc-cpp.srt而不是复制它(这是emacs 24.3.1)。
因此,srecode-document-insert-comment仅在c++-mode中有效(正如您所期望的那样) 为了使c-mode能够使用以下内容创建文件〜/ .srecode / doc-c.srt,它应该可以正常工作。

;; 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

doxygen评论生成的替代方法是doxymacs

答案 1 :(得分:0)

您应该与函数名称或函数定义位于同一行 - 然后,srecode-document-insert-commentC-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;
}

答案 2 :(得分:0)

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