是否有一个Yasnippet产生预先填充的Doxygen评论?


10

对于以下C ++函数:

bool importantStuff(double a, double b);

它应该输出以下代码段,也许没有标签:

/**
 * <Insert description of importantStuff>
 *
 * @param a <Insert description of a>
 * @param b <Insert description of b>
 * @return <Insert description of the return value>
 */

我环顾四周,但是最接近答案的是这个旧的SO问题,答案取决于不再维护的doxymacs模式。


我认为c-sharp-mode可以做到这一点。
erikstokes

您要为新功能还是现有功能执行此操作?
itsjeyd

当问这个问题时,我想到的是从函数签名中生成的doxygen注释。
罗万尼(Rovanion)

Answers:


4

我使用以下内容,这是基于标准doxymacs和基于abo-abo的语义的一个混搭,已经提到了答案-这仅需要语义和yasnippet。与abo-abo的版本相比,这也预填充了更多具有相关信息的yasnippet占位符。


# -*- mode: snippet -*-
# name: dox
# key: dox
# type: command
# --
(unless (and (fboundp 'semantic-current-tag)
             semantic-mode)
  (error "Semantic required to use dox snippet"))
(let ((tag (senator-next-tag)))
  (while (or (null tag)
             (not (semantic-tag-of-class-p tag 'function)))
    (setq tag (senator-next-tag)))
  (let* ((name (semantic-tag-name tag))
         (attrs (semantic-tag-attributes tag))
         (args (plist-get attrs :arguments))
         (return-name (plist-get attrs :type))
         (idx 1))
    (if (listp return-name)
      (setq return-name (car return-name)))
    (yas/expand-snippet
     (format
      "/**
* @brief ${1:%s}
*
%s
%s*/
"
      name
      (mapconcat
       (lambda (x)
         (format "* @param %s ${%d:Description of %s}"
                 (car x) (incf idx) (car x)))
       args
       "\n")
      (if (and return-name (not (string-equal "void" return-name)))
          (format " * @return ${%d:%s}\n" (incf idx) return-name)
        "")))))


该解决方案绝对有效,但是必须等待语义模式遍历所有必需的代码,这有点麻烦。如果我在变量之前写dox <tab>,我也会陷入emacs陷入无限循环的困境。但是,这个世界上不可能拥有一切:D
罗凡尼翁

这应该被投高于上述,因为它比MOO-doxygen的更丰富
亚历埃里克森

3

刚刚将此功能添加到function-args

如果您有兴趣,这是代码。它使用CEDET:

(defun moo-doxygen ()
  "Generate a doxygen yasnippet and expand it with `aya-expand'.
The point should be on the top-level function name."
  (interactive)
  (move-beginning-of-line nil)
  (let ((tag (semantic-current-tag)))
    (unless (semantic-tag-of-class-p tag 'function)
      (error "Expected function, got %S" tag))
    (let* ((name (semantic-tag-name tag))
           (attrs (semantic-tag-attributes tag))
           (args (plist-get attrs :arguments))
           (ord 1))
      (setq aya-current
            (format
             "/**
* $1
*
%s
* @return $%d
*/
"
             (mapconcat
              (lambda (x)
                (format "* @param %s $%d"
                        (car x) (incf ord)))
              args
              "\n")
             (incf ord)))
      (aya-expand))))

您还需要auto-yasnippet。两种软件包都可以在MELPA中获得。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.