Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs + C/C++ + Doxygen: Alternative to doxymacs? With yasnippet?

Tags:

c++

c

emacs

doxygen

I would like to use doxygen to generate code documentation (of functions) in .c or .cc files with Emacs. I found doxymacs, but it seems not to be maintained anymore (latest version 2007) and I also did not find a way to update the documentation of a function if I change the name of one of the parameters of the function ("unfortunately", I'm used to the great Roxygen for .R scripts which can do all nice things, even inserting a documentation right before a function when the point is somewhere in the function).

I found this, but it seems not very useful. However, there is an example here how to use yasnippets. Has anyone written a yasnippet for doxygen headers? Still, it would not update the parameters if the function name changes. Is there any "better" way to work with doxygen in Emacs? I would assume there are quite a lot of C/C++ programmers that work with Emacs and I would guess that there should be a good tool/approach for code documentation.

Update

I also found this. It's purely based on yasnippet (haven't tried it yet, though).

like image 608
Marius Hofert Avatar asked Jul 04 '12 07:07

Marius Hofert


1 Answers

I use the following:

# -*- mode: snippet -*-
# name: cc-doxygen
# key: dox
# type: command
# contributor: Jonathan Kotta <[email protected]>
# --
(let* ((next-func-alist (doxymacs-find-next-func))
       (func-name (cdr (assoc 'func next-func-alist)))
       (params-list (cdr (assoc 'args next-func-alist)))
       (return-name (cdr (assoc 'return next-func-alist)))
       (snippet-text "")
       (idx 1))
  (setq snippet-text (format "/**\n * ${1:%s}\n * \n" func-name))
  (setq idx 2)
  (dolist (param params-list)
    (unless (string= param "this")
      (setq snippet-text (concat snippet-text
                                 (format " * \\param %s ${%d:}\n" param idx)))
      (setq idx (+ 1 idx))))
  (when (and return-name (not (string= return-name "void")))
    (setq snippet-text (concat snippet-text
                               (format " * \\return ${%d:%s}\n" idx return-name))))
  (setq snippet-text (concat snippet-text " */"))
  (yas/expand-snippet snippet-text))
like image 67
jpkotta Avatar answered Sep 28 '22 16:09

jpkotta