Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comment blocks with stars in emacs

Tags:

comments

emacs

What settings and commands does one need to perform to make comments like this in emacs:

  /**
   * 
   * something here
   */

Thanks.

like image 213
ajmartin Avatar asked Jul 05 '11 05:07

ajmartin


3 Answers

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 
 */
like image 62
Ralph Avatar answered Nov 06 '22 20:11

Ralph


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.

like image 38
Moe Matar Avatar answered Nov 06 '22 20:11

Moe Matar


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.

like image 21
CodyChan Avatar answered Nov 06 '22 22:11

CodyChan