What settings and commands does one need to perform to make comments like this in emacs:
/**
*
* something here
开发者_如何学Python */
Thanks.
An easy way is to define your own command for inserting this comment. Add this to your .emacs file:
(defun insert-doc-comment () (interactive)
(insert "/**\n * Brief description. Long description. \n * @param \n * @return \n * @exception \n * @see \n * @author \n */"))
Then bind the new command to a key of your liking:
(define-key global-map [(S-f1)] 'insert-doc-comment)
Now pressing Shift-F1 will insert a comment block like this:
/**
* Brief description. Long description.
* @param
* @return
* @exception
* @see
* @author
*/
You can build templates with emacs. Templates are skeletons for a file structure, and can be tied to files with specific extensions. For example, you can make a java template that applies to any new file you create with a .java extension, and you can make a C++ template that applies to any file you create with a .cpp extension (and another one for .h files if needed).
This wiki has more examples to help you get started with a C++ class template.
Use yasnippet snipept, if you're not using it yet, try it.
Put this in you snippets/**-mode/
# -*- mode: snippet -*-
# name: dock
# key: /*
# --
/*
* $1
*/
$0
or another version:
# -*- mode: snippet -*-
# name: docblock
# key: /**
# --
/**
* ${1:name} - ${2:short description}
* @${3:argv1}: $4
* @${5:argv2}: $6
*
* ${7:long description}
*/
$0
I got both two in my snippets/, by the way you should copy yasnippets-xx/snippets
to another place like ~/.emacs.d/snippets
, and put this in your .emacs
:
(setq yas-snippet-dirs '("~/.emacs.d/snippets"))
become every time you update yasnippet, the yasnippet-xx/snippets will replaced by the author's snippets, you can add/delete/modify
your own snippets in ~/.emacs.d/snippets
for your own needs.
M-x customize-group RET comment
Look at the "Value Menu" of the "Comment Style" variable.
(Then you can use both "comment-dwim" or "comment-or-uncomment-region" to toggle comments in and out of selected blocks)
You can also use this if you want the current line commented in/out if there is no region active :
(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))
I usually bind it to M-d :
(global-set-key (kbd "M-d") 'px-toggle-comments)
You are looking for M-x comment-region and its friends for your particular mode.
You could define a keyboard macro to do the work, and run it. For your situation, type out the beginning /*
, then do C-x (
then, C-n M-m *
and, C-x )
. Do C-x e
until the last line that you want to comment out. When on the last line, end it with a /
.
I know it looks very ugly, and such, but FWIW, it works for me. When I have to comment out big blocks, I use this approach.
精彩评论