Files
nuwiki/scripts/syntax-diag.vim
T
gffranco c66431cde3 chore(scripts): add syntax-diag helper for debugging highlight issues
Drop-in script that dumps the syntax/highlight state of the current
buffer to /tmp/nuwiki-syndiag.log: filetype, b:current_syntax, every
syntax/vimwiki.vim found in &runtimepath (to spot duplicates from
other plugins), the resolved attributes of our highlight groups +
the colorscheme groups they link to, a per-segment synID walk over
the buffer, and the filtered scriptnames list. Useful when a user
reports broken highlighting and we need to know whether the patterns
aren't matching, the colorscheme is the culprit, or another plugin's
syntax/vimwiki.vim is winning the runtimepath race.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 22:04:03 -03:00

76 lines
2.2 KiB
VimL

" scripts/syntax-diag.vim — dump highlighting state to /tmp/nuwiki-syndiag.log
"
" Usage: open a .wiki file with VARIED markup (heading, *bold*, _italic_,
" `code`), then:
" :source scripts/syntax-diag.vim
" Then paste /tmp/nuwiki-syndiag.log back.
redir! > /tmp/nuwiki-syndiag.log
echo '=== state ==='
echo 'filetype=' . &filetype
echo 'syntax=' . &syntax
echo 'b:current_syntax=' . get(b:, 'current_syntax', '<unset>')
echo 'syntax_on=' . exists('g:syntax_on')
echo 'colors_name=' . get(g:, 'colors_name', '<unset>')
echo 'background=' . &background
echo 'termguicolors=' . &termguicolors
echo 't_Co=' . &t_Co
echo 'has(nvim)=' . has('nvim')
echo 'g:loaded_nuwiki=' . get(g:, 'loaded_nuwiki', '<unset>')
echo 'g:loaded_vimwiki=' . get(g:, 'loaded_vimwiki', '<unset>')
echo ''
echo '=== every syntax/vimwiki.vim in runtimepath (first wins) ==='
for s:p in split(&runtimepath, ',')
let s:f = s:p . '/syntax/vimwiki.vim'
if filereadable(s:f)
echo s:f
endif
endfor
echo ''
echo '=== :hi for our groups (NO silent — capture into redir) ==='
for s:g in ['nuwikiHeading', 'nuwikiBold', 'nuwikiItalic', 'nuwikiCode',
\ 'nuwikiPlaceholder', 'nuwikiCommentLine', 'nuwikiWikilink',
\ 'Title', 'PreProc', 'String', 'Comment', 'Underlined', 'Normal']
execute 'highlight ' . s:g
endfor
echo ''
echo '=== synID walk over current buffer (first 30 lines) ==='
for s:ln in range(1, min([line('$'), 30]))
let s:l = getline(s:ln)
let s:segs = []
let s:last = ''
let s:start = 1
for s:c in range(1, len(s:l) + 1)
let s:g = s:c <= len(s:l) ? synIDattr(synIDtrans(synID(s:ln, s:c, 1)), 'name') : ''
if s:g != s:last
if s:start <= s:c - 1
let s:txt = strpart(s:l, s:start - 1, s:c - s:start)
call add(s:segs, s:last . ':' . s:txt)
endif
let s:last = s:g
let s:start = s:c
endif
endfor
echo printf('L%d %s', s:ln, join(s:segs, ' | '))
endfor
echo ''
echo '=== :syntax list (full) ==='
syntax list
echo ''
echo '=== :scriptnames (filtered) ==='
let s:sn = execute('scriptnames')
for s:line in split(s:sn, '\n')
if s:line =~? 'vimwiki\|nuwiki\|syntax\|colors'
echo s:line
endif
endfor
redir END
echo 'Wrote /tmp/nuwiki-syndiag.log'