Skip to content

Commit

Permalink
fix: detect treesitter in the correct buffer
Browse files Browse the repository at this point in the history
Problem:
Wrong treesitter detection error message when the user enters another
buffer right after opening a tex file.

Solution:
Detect in the buffer in which the ftplugin is loaded.
  • Loading branch information
tomtomjhj committed Oct 1, 2023
1 parent 7d453a6 commit 9710c17
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions autoload/vimtex/nvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
" Email: [email protected]
"

function! vimtex#nvim#check_treesitter(...) abort " {{{1
lua <<EOF
local highlighter = require "vim.treesitter.highlighter"
local bufnr = vim.api.nvim_get_current_buf()
if vim.bo[bufnr].syntax == "" and highlighter.active[bufnr] then
vim.fn['vimtex#log#error'](
'Syntax highlighting is controlled by Tree-sitter!'
)
end
EOF
function! vimtex#nvim#check_treesitter(buf, ...) abort " {{{1
if empty(getbufvar(a:buf, '&syntax')) && luaeval('require("vim.treesitter.highlighter").active[_A[1]] ~= nil', [a:buf])
call vimtex#log#error('Syntax highlighting is controlled by Tree-sitter!')
endif
endfunction

" }}}1
2 changes: 1 addition & 1 deletion ftplugin/tex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ call vimtex#init()
if has('nvim-0.5')
\ && g:vimtex_syntax_enabled
\ && !g:vimtex_syntax_conceal_disable
call timer_start(1000, 'vimtex#nvim#check_treesitter')
call timer_start(1000, function('vimtex#nvim#check_treesitter', [bufnr('%')]))
endif

0 comments on commit 9710c17

Please sign in to comment.