Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim syntax highlighting of doxygen style docstrings in Python

I started working with doxygen to generate the documentation of my Python code. I use doxypy filter to preprocess the Python docstrings. My goal is to have a nice syntax highlighting of doxygen comments in Python.

When writing my mainpage in a dedicated .dox file, I found that the doxygen comments can be highlighted in vim with the following command:

set syntax=c.doxygen

I tried the same command for Python but I got nothing: set syntax=python.doxygen

I also made some googling and couldn't find anything interesting

Here is a typical piece of code I'd like to highlight:

class CompilationTab:
    """
    The compilation tab of the verif GUI. It contains the layout description
    and the functions required to deal with specific behaviors of the tab
    """
    def __init__(self, notebook, tab_name):
        """
        The class constructor.

        @param notebook Notebook: The parent @c Notebook widget
        @param tab_name String: The display name of the tab
        """

Does anybody already fixed this issue? Thank you for help!

like image 932
Plouff Avatar asked Feb 16 '23 15:02

Plouff


1 Answers

If you look into syntax/doxygen.vim you can read in the preamble of the file that currently only

cpp, c, idl, doxygen and php

files are supported.

Since doxygen.vim works a lot with the syn region command i searched for the line that defines the multiline string in syntax/python.vim.

The interesting part of the command that defines this region is

syn region pythonString start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend

Derived from that what is in doxygen.vim and the above line you can add the following lines

"delete the following line if you don't want to have enhanced colors
let g:doxygen_enhanced_color=1
runtime! syntax/doxygen.vim
syn region doxygenComment matchgroup=pythonString start=+[uU]\=\z('''\|"""\)+ end="\z1" contains=doxygenSyncStart,doxygenStart,doxygenTODO keepend fold containedin=pythonString

to ~/.vim/after/syntax/python.vim or execute them by hand.

In addition you may have to customize the colors of the added doxygen highlighting groups by hand. At least i would do so since the resulting look doesn't conform with my taste.

Perhaps the fold argument of the syn command is of special interest for you. If you set foldmethod to syntax you can fold and unfold the multiline comments. That seems to be useful if you could no longer stand the view of those colors and are to lazy to adjust them :)


without doxygen highlighting:

enter image description here

with doxygen highlighting and g:doxygen_enhanced_color == 1:

enter image description here

like image 139
user1146332 Avatar answered Mar 23 '23 12:03

user1146332