在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)
/**
* Brief description. Long description.
* @param
* @return
* @exception
* @see
* @author
*/
如果你还没有使用过,可以尝试使用yasnippet代码片段工具。
将这段代码放在你的snippets/**-mode/文件夹中。
# -*- 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"))
~/.emacs.d/snippets
中添加/删除/修改自己的代码片段以满足个人需求。请注意保留HTML标签。M-x customize-group RET comment
查看“注释样式”变量的“值菜单”。
(然后您可以使用“comment-dwim”或“comment-or-uncomment-region”在选定的块中切换注释)
如果没有活动区域,您还可以使用此功能将当前行注释/取消注释:
(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 comment-region及其相关命令,以适用于你的特定模式。
你可以定义一个键盘宏来完成工作,并运行它。对于您的情况,先输入开头的/*
,然后按C-x(
,接着是C-n M-m *
和C-x)
。反复按C-x e
直到您要注释掉的最后一行。当您在最后一行时,以/
结尾。
我知道这看起来非常丑陋,但是无论如何,这对我很有效。当我需要注释大块代码时,我使用这种方法。
;2P
。您知道为什么吗? - ajmartinC-h k
然后按S-f1
,查看Emacs是否将这些键识别为S-f1
。 - sanityinc