5

我们需要使用 javadoc 格式的 doxygen 注释来注释我们的 C++ 代码,我正在 emacs 中寻找可以在我键入时保持 javadoc 风格的东西。

所以如果我开始写这样的评论:

/**
 * This function does the following:

当我点击“输入”时,我希望光标自动缩进并插入一个“*”,这样我就可以继续输入而无需手动格式化。所以当我点击“return”时,评论现在应该是这样的(不用我输入“[TAB]*”):

/**
 * This function does the following:
 * 
4

3 回答 3

3

在这里找到了答案:http ://www.frankmeffert.de/2010/09/emacs-doxygen-doxymacs/ 我对 C 和 C++ 模式进行了微调,并在每个“*”之后添加了一个额外的空格

(defun my-javadoc-return () 
  "Advanced C-m for Javadoc multiline comments.   
Inserts `*' at the beggining of the new line if 
unless return was pressed outside the comment"
  (interactive)
  (setq last (point))
  (setq is-inside
        (if (search-backward "*/" nil t)
        ;; there are some comment endings - search forward
            (search-forward "/*" last t)
          ;; it's the only comment - search backward
          (goto-char last)
          (search-backward "/*" nil t)
      )
    )
  ;; go to last char position
  (goto-char last)
  ;; the point is inside some comment, insert `* '
  (if is-inside
      (progn 
    (insert "\n* ")
    (indent-for-tab-command))
    ;; else insert only new-line
    (insert "\n")))

(add-hook 'c-mode-common-hook (lambda () 
  (local-set-key "\r" 'my-javadoc-return)))
于 2013-10-24T13:26:57.597 回答
2

IIUC,打M-j而不是RET应该给你你想要的行为。

于 2013-10-24T17:35:40.313 回答
2

有一个变量可以控制-style 注释c-block-comment-prefix中续行的前缀。/*...*/

随着它被设置为

(setq c-block-comment-prefix "* ")

并且您的观点在完整 - 即关闭 - 评论块中(|是关键)

1. /|* */
2. /*| */
3. /* |*/
4. /* *|/

当你按下M-jc-indent-new-comment-line命令)时,你会得到以下结果:

/*
 * */

适用于 23 和 24 Emacsen。

于 2013-10-25T09:29:46.673 回答