emacs中带有星号的评论块



需要执行哪些设置和命令才能在emacs:中做出这样的评论

  /**
   * 
   * something here
   */

谢谢。

一个简单的方法是定义自己的命令来插入议论将其添加到.emacs文件中:

(defun insert-doc-comment () (interactive)
   (insert "/**n * Brief description. Long description. n * @param n * @return n * @exception n * @see n * @author n */"))

然后将新命令绑定到您喜欢的密钥:

(define-key global-map [(S-f1)] 'insert-doc-comment)

现在按下Shift-F1将插入如下注释块:

/**
 * Brief description. Long description. 
 * @param 
 * @return 
 * @exception 
 * @see 
 * @author 
 */

您可以使用emacs构建模板。模板是文件结构的骨架,可以绑定到具有特定扩展名的文件。例如,您可以制作一个java模板,该模板适用于您创建的任何扩展名为.java的新文件,还可以制作C++模板,该模版适用于您使用.cpp扩展名创建的任何文件(如果需要,还可以为.h文件制作另一个(。

这个wiki有更多的例子可以帮助你开始使用C++类模板。

使用yasnippet狙击,如果你还没有使用,请尝试。

把这个放在你的代码段/**-模式/

# -*- mode: snippet -*-
# name: dock
# key: /*
# --
/*
 * $1
 */
$0

或者另一个版本:

# -*- mode: snippet -*-
# name: docblock
# key: /**
# --
/**
 * ${1:name} - ${2:short description}
 * @${3:argv1}: $4
 * @${5:argv2}: $6
 *
 * ${7:long description}
 */
$0

我在我的代码段中得到了这两个/,顺便说一句,你应该把yasnippets-xx/snippets复制到另一个地方,比如~/.emacs.d/snippets,并把它放在你的.emacs:中

(setq yas-snippet-dirs '("~/.emacs.d/snippets"))

每次更新yasnippet时,yasnippetxx/sippets都会被作者的snippets替换,您可以在~/.emacs.d/snippetsadd/delete/modify自己的snippet以满足自己的需求。

M-x customize-group RET comment

查看"注释样式"变量的"值菜单"。

(然后您可以使用"注释dwim"或"注释或取消注释区域"来切换所选块中的注释(

如果您希望当前行注释入/出,如果没有活动区域,也可以使用此选项:

(defun px-toggle-comments ()
  "If region is set, [un]comments it. Otherwise [un]comments current line."
  (interactive)
  (if (eq mark-active nil)
      (progn 
                (beginning-of-line 1)
                (set-mark (point))
                (forward-line)
                (comment-dwim nil))
    (comment-dwim nil))
  (deactivate-mark))

我通常将其绑定到M-d:

(global-set-key (kbd "M-d") 'px-toggle-comments)

您正在为您的特定模式寻找M-x评论区域及其好友。

您可以定义一个键盘宏来完成这项工作并运行它。对于您的情况,请键入开头的/*,然后键入C-x (,再键入C-n M-m *C-x )。执行C-x e,直到您要注释掉的最后一行为止。在最后一行时,以/结束。

我知道它看起来很难看,等等,但FWIW,它对我有用。当我不得不评论大块时,我会使用这种方法。

最新更新