在 emacs 中格式化 javadoc 样式注释
Formatting of javadoc style comments in emacs
我们需要使用 javadoc 格式的 doxygen 注释来注释我们的C++代码,我正在寻找可以在我键入时保持 javadoc 风格的东西。
因此,如果我开始写这样的评论:
/**
* This function does the following:
当我点击"输入"时,我希望光标自动缩进并插入"*",这样我就可以继续打字而无需手动格式化。因此,当我点击"返回"时,评论现在应该如下所示(无需我输入"[TAB]* "):
/**
* This function does the following:
*
在这里找到了答案: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)))
有一个
变量c-block-comment-prefix
控制/*...*/
样式注释中连续行的前缀。
将其设置为
(setq c-block-comment-prefix "* ")
和你的观点在完整的 - 即关闭的 - 评论块(|
是重点)
1. /|* */
2. /*| */
3. /* |*/
4. /* *|/
当您按 M-j(c-indent-new-comment-line
命令)时,最终会得到以下结果:
/*
* */
适用于 23 和 24 Emacsen。
IIUC,点击M-j
而不是RET
应该给你你想要的行为。