I want to fold all special documentation comments, and only all special documentation comments.
To do that I created a new syntax,
doxygenComment and added highlighting (in red, just to test it).
The comments are getting highlighted correctly, but my
GetCppFold doesn't seem to work, since no comments are getting folded:
augroup filetype_cpp autocmd! " Create custom doxygen comment style autocmd FileType cpp syn region doxygenComment start="/\*\!" end="\*/" autocmd FileType cpp hi link doxygenComment cError " Fold comments. autocmd FileType cpp setlocal foldmethod=expr autocmd FileType cpp setlocal foldexpr=GetCppFold(v:lnum) " Close all folds. autocmd BufRead *.cxx,*.hxx,*.cpp,*.hpp normal zM augroup END
The following function simply checks whether the line is considered a
doxygenComment or not, and returns the appropriate fold level. Keep in mind, I don't want any additional indent/syntax folding. I only want the comments folded (technically, I would want to have the functions folded, too, but this seems to be quite hard, since the syntax can't decipher between function and namespace or classes).
function! GetCppFold(lnum) let line = getline(a:lnum) " Check whether the line is empty or whitespace only. if line =~? '\v^\s*$' return '-1' endif let a:data = join(map(synstack(a:lnum, 1), 'synIDattr(v:val, "name")')) if a:data =~? ".*omment.*" echo "match" return '=' endif return '-1' endfunction