tyru / caw.vim

Vim comment plugin: supported operator/non-operator mappings, repeatable by dot-command, 300+ filetypes
379 stars 48 forks source link

Fix: failed to uncomment when highlight link is nested #176

Open uplus opened 2 years ago

uplus commented 2 years ago

Problem

When highlight link is nested, caw.vim fails to uncomment.

Cause

In the current implementation, s:comment_detectable.has_syntax uses synIDtrans to get the terminal syntax name. If the terminal syntax name does not contain Comment, s:comment_detectable.has_syntax will return 0.

https://github.com/tyru/caw.vim/blob/3aefcb5a752a599a9200dd801d6bcb0b7606bf29/autoload/caw/actions/traits/comment_detectable.vim#L70

For exacmple.

hi! link vimLineComment Comment
hi! link Comment hogeColor
hi! hogeColor ctermfg=8

let id = hlID('vimLineComment')
echo synIDattr(synIDtrans(id), 'name') " 'hogeColor'

For example, it will succeed if the highlight settings are as follows.

hi! link vimLineComment Comment
hi! Comment ctermfg=8

let id = hlID('vimLineComment')
echo synIDattr(synIDtrans(id), 'name') " 'Comment'

Solution

Use both synIDattr(id, 'name') and synIDattr(synIDtrans(id), 'name').