DoxyMacs

Doxygen is a system for extracting documentation from source code. It supports a variety of programming languages, human languages and output formats. You can find it at http://www.doxygen.org.

Doxymacs, authored by RyanTSammartino, is a minor-mode for (X)Emacs to edit files containing Doxygen documentation. You can find it at http://doxymacs.sourceforge.net.

With the doxymacs minor-mode, you can insert doxygen tempo templates, start a browser to see a symbol’s documentation etc. It also provides syntax highlight.

To generate the doxygen ‘tags file’ needed by doxymacs, put something like:

  GENERATE_TAGFILE = ~/.tmp/doxy.tag

in your doxygen config file.


From August 2004, CVS version of GnuEmacs require patching DoxyMacs in order to avoid conflicts in font-lock management: the ‘doxymacs-font-lock’ function should be implemented as follows (or at leat I think so 😊):

(defun doxymacs-font-lock ()
  (interactive)
  (font-lock-add-keywords nil doxymacs-doxygen-keywords))

YannHodique


I made a small function that is inspired by Eclipse editing of the Java files. When the point is inside a multiline comment it automatically adds an asterisk when you enter a newline. There may be some minor glitches if you have “/*”’ or “*/” inside your strings but it works fine in general. There is a piece of code at the end that binds the function to return key, use it if you want.

JakubHozak

(defun my-javadoc-return () 
  "Advanced `newline' command for Javadoc multiline comments.   
Insert a `*' at the beggining of the new line if inside of a comment."
  (interactive "*")
  (let* ((last (point))
         (is-inside
          (if (search-backward "*/" nil t)
              ;; there are some comment endings - search forward
              (search-forward "/*" last t)
            ;; it's 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
          (newline-and-indent)
          (insert "*"))
      ;; else insert only new-line
      (newline-and-indent))))

(add-hook 'c++-mode-hook
          (lambda ()
            (local-set-key (kbd "<RET>") 'my-javadoc-return)))

You can use M-j (c-indent-new-comment-line) within comments to get the same effect.

— Pradeep


I extend the JakubHozak’s solution to work with other one-line comment as well. However, it does not work for lisp-mode. I have no idea why. There is also some bug fix – old code will not indent properly in the code after pressing Enter; extra space after the comment symbol.

— Shuai Li

;; Advanced return for programming.
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun advanced-return ()
  "Advanced `newline' command for comment.  This function redefine <Enter> to
provide a corrent comment symbol at each newline plus a space when you press
<Enter> in the comment.  It also support JavaDoc style comment -- insert a `*'
at the beggining of the new line if inside of a comment."
  (interactive "*")
  (let* ((last (point))
         (line-beginning (progn (beginning-of-line) (point)))
         (is-inside-java-doc
          (progn
            (goto-char last)
            (if (search-backward "*/" nil t)
                ;; there are some comment endings - search forward
                (search-forward "/*" last t)
              ;; it's the only comment - search backward
              (goto-char last)
              (search-backward "/*" nil t)
              )
            )
          )
         (is-inside-oneline-comment
          (progn
            (goto-char last)
            (search-backward comment-start line-beginning t)
            )
          )
         )

    ;; go to last char position
    (goto-char last)

    ;; the point is inside one line comment, insert the comment-start.
    (if is-inside-oneline-comment
        (progn
          (newline-and-indent)
          (insert comment-start)
          )
      ;; else we check if it is java-doc style comment.
      (if is-inside-java-doc
          (progn
            (newline-and-indent)
            (insert "* ")
            )
        ;; else insert only new-line
        (newline-and-indent)
        )
      )
      )
  )

;; TODO(Shuai) I have no idea why the hook does not work for lisp-mode, even if
;; advanced-return is added to the lisp-mode-hook directly.  However, I will
;; just settle for the moment since it works fine for almost all the remaining
;; prog modes.  What's more, it does not conflict with the autopair-newline
;; command that is binded to <RET>.  Though I am not sure why, maybe (newline)
;; is rebinded.
(add-hook 'prog-mode-hook
          (lambda ()
            (local-set-key (kbd "<RET>") 'advanced-return)))

Nov 2017. This package hasn’t been updated in a while. If you just want Doxygen special command syntax highlighting, see https://emacs.stackexchange.com/questions/31392/syntax-highlight-doxygen-comments-in-c-c-c-doc-comment-style/36637#36637


See also

DoxyMacsYard can be used to create YARD comments in Ruby buffers and highlight them to the extent the YARD tags match with the Doxygen ones.


CategoryProgrammerUtils