4

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!

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you so much, it works just fine :)! I have an issue when using a ftplugin/python.vim. The syntax is not loaded, even if I have filetype plugin on and that :filetype gives my python. I temporarily solved it by adding the 3 lines you gave me in the syntax/python.vim. I fear that my setup is little bit buggy.
Btw, as you said the highlighting is not perfect. I may try to update it later on...
Indeed adding the commands to ftplugin/python.vim doesn't work. You should put them in ~/.vim/after/syntax/python.vim instead. I will correct that in my answer. Best regards
Thank you for the update. Indeed it works correctly inside after/syntax directory.
For those that got here, tried it and found that this changes their python syntax highlighting: there is a pythonAttribute syn match in the shipped highlighting and it has a contains=ALLBUT which will pull in the doxygen definitions. using "syn clear pythonAttribute" and then copying the exisintg and replacing ALLBUT with TOP should fix that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.