Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doxygen-style comments in vim for C++

I'd like to automate inserting comment snippets for C++ files. Google search suggested c.vim plugin. I installed it. Now when I create a file, I get template like following.

 /* =====================================================================================
  *
  *       Filename:  Foo.h
  *
  *    Description:  :
  *
  *        Version:  1.0
  *        Created:  04/14/2014 08:35:44 PM
  *       Revision:  none
  *       Compiler:  gcc
  *
  *         Author:  YOUR NAME (), 
  *   Organization:  
  *
  * =====================================================================================
  */

From :h csupport I catch I can create my own templates for comments. Is there simpler way to get doxygen-style comments in project? Or maybe these templates are available somewhere?

like image 540
Loom Avatar asked Apr 14 '14 17:04

Loom


People also ask

What is doxygen style comments?

A special comment block is a C or C++ style comment block with some additional markings, so doxygen knows it is a piece of structured text that needs to end up in the generated documentation. The next section presents the various styles supported by doxygen.

How do you use doxygen C code?

To use Doxygen, you simply comment your source code in a syntax that Doxygen can read. Doxygen then walks through your source files and creates HTML or LaTeX documentation based on those special comments.

How do I create a doxygen comment?

Once specified, you can generate the comment stub by typing the respective “///” or “/**” above a function, or by using the (Ctrl+/) shortcut. To get started, you can have Visual Studio generate an . editorconfig file for you based on your existing setting for documentation by using the “Generate .

What is @brief in doxygen?

Putting the command @brief will generate a short description of the function when you generate the doxygen documentation. That short description can be extended if you want. Follow this answer to receive notifications.


3 Answers

If you only need these comments and not the other features of c.vim, I'd recommend you to use some snippets plugin, such as Snipmate or Ultisnips. Creating such snippets with these plugins is very easy and they are very powerful.

like image 182
artur.balabanov Avatar answered Oct 09 '22 02:10

artur.balabanov


You can use Doxygen plugin for vim. It's available here. Simply enter :Dox to add your comments.

For example,

/**
 * @brief 
 *  
 * @param list 
 * @param size
 * @param key
 * @param rec
 *
 * @return 
 */
bool jw_search ( int *list, int size, int key, int& rec )
{
    return true;
}
like image 41
sarath Avatar answered Oct 09 '22 03:10

sarath


lh-cpp & mu-template come with tunable project headers (the default is quite bad I have to admit). You'll have to override templates/c/internals/c-file-header.template to something like:

VimL: let s:filename = s:path_from_root(expand('%:p'))
VimL: let s:prj_dox_group = lh#option#get('my_prj_dox_group', lh#marker#txt('group'))
/**@file <+s:filename+>
 * @ingroup <+s:prj_dox_group+>
 * @author  <+Author()+>
 * <p>Licence:<p> Your Project Licence
 */

(All the other stuff is already taken care of: include guards will be added automatically in header files, and foo.h will be automatically included in foo.c(pp))

Then in a local_vimrc-like plugin, you'll have to set:

" File: /root/path/of/the/project/_vimrc_local.vim
:let b:my_prj_dox_group = "gMain" " you can override it in subfolders
:let b:sources_root = '/root/path/of/the/project' " for mu-template
:let b:includes = [b:sources_root . '/**'] " I can't remember which ftplugin uses b:includes
:let b:included_paths = [b:sources_root] " for ftplugin/c/c_AddInclude.vim
:let g:alternateSearchPath = 'sfr:.' " (or equivalent) for a.vim and for foo.cpp to include foo.h

BTW, lh-cpp also comes with the :DOX command that'll parse a function signature to automatically generate its doxygen caption (@param[in/out/0], @return, @ingroup, @throw (noexcept and the deprecated exception specifications are analysed), ... will be filled as automagically as possible)

If we take Saraht's example, it becomes:

/**
 * «brief explanation».
 * «details»
 * @param[«in,»out] list  «list-explanations»
 * @param[in] size  «size-explanations»
 * @param[in] key  «key-explanations»
 * @param[«in,»out] rec  «rec-explanations»
 *
 * @return «bool»
 * «@throw »
 * @pre <tt>list != NULL</tt>«»
 */
bool jw_search ( int* list, int size, int key, int& rec )

NB: «» occurrences mark placeholders

PS: I have no idea how it will behave if your keep c.vim as I don't use it.

like image 42
Luc Hermitte Avatar answered Oct 09 '22 01:10

Luc Hermitte