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