lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.42k stars 389 forks source link

highlight TODOs labels in ToC #2410

Closed ja-mf closed 2 years ago

ja-mf commented 2 years ago

Hi, thanks a lot for developing and supporting this awesome plugin, it's extremely productive to me, that's why I've been tweaking it to adapt it for my needs, anyway some advice would be great.

Just a simple question, I'd like to highlight TODOs labels in g:vimtex_toc_todo_labels the same way they're highlighted in the main text. For example in the screenshot below, it would be perfect to have the TODOs in the TOC highlighted as orange as well:

Screen Shot 2022-06-06 at 5 59 19 pm

Digging into the code, it seems that it should be that way given this: https://github.com/lervag/vimtex/blob/7dfa2bdec5adeed522194117c0baab23629713eb/autoload/vimtex/toc.vim#L367-L370

But TODOs aren't highlighted in ToC. I've tried several alternatives but my vim tweaking isn't that good. I've seen this issue #2221 and solution but haven't figured out how to achieve it yet.

Any suggestion is welcome, thanks in advance.

lervag commented 2 years ago

Thanks for opening this issue. I noticed there was an error in the regex, and I believe the recent update should mostly fix this for you.

Notice that you can customize on your end with an autocommand, e.g.:

augroup vimtex_customization
  autocmd!
  autocmd User VimtexEventTocCreated call TocSyntax()
augroup END

function! TocSyntax()
  syntax keyword Error contained containedin=VimtexTocTodo FIXME
  syntax keyword Todo contained containedin=VimtexTocTitle TODO
endfunction

See :help syn-keyword and :help syn-match, as well as :help :highlight, to learn how to defined syntax groups/rules and highlight rules.

ja-mf commented 2 years ago

Thanks heaps for the commit fixing this issue and the explanation!

lervag commented 2 years ago

My pleasure :)