Formatting javadoc style comments in emacs

We need to comment on our C ++ code using javadoc formatted doxygen comments, and I'm looking for something in emacs that can support the javadoc style as you type.

So, if I start writing a comment as follows:

/**
 * This function does the following:

When I press enter, I would like the cursor to be automatically indented and insert "*", so I can continue to type without formatting manually. Therefore, when I press "return", the comment should now look like this (without me type "[TAB] *"):

/**
 * This function does the following:
 * 
+4
source share
3 answers

c-block-comment-prefix, /*...*/.

(setq c-block-comment-prefix "* ")

- - (| )

1. /|* */
2. /*| */
3. /* |*/
4. /* *|/

M-j (c-indent-new-comment-line), :

/*
 * */

23, 24 Emacsen.

+2

: http://www.frankmeffert.de/2010/09/emacs-doxygen-doxymacs/ 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 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)))
+2

IIUC, clicking M-jinstead RETshould give you the behavior you want.

+2
source

All Articles