caw.vim icon indicating copy to clipboard operation
caw.vim copied to clipboard

Fix: failed to uncomment when highlight link is nested

Open uplus opened this issue 4 years ago • 0 comments

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').

uplus avatar Jan 18 '22 07:01 uplus