Modifies the wordcount to use the vimtex wordcount function when editing TeX files and the vimtex plugin is loaded.

With help from Karl Lervag's suggestion on how to reliably tell when the
above mentioned conditions are the case for the current buffer

Checked to work with other filetypes that use the wordcount in
vim-airline, and these seem to work as before.

Also checked that if two of these filetypes (one TeX and the other
another type, such as markdown) the two coexist peacefully, with TeX
using Karl's wordcount function, and the other using the (I assume)
native wordcount?

Fixed comment wording
This commit is contained in:
Dood of Distinction 2021-11-02 14:27:37 -07:00 committed by Christian Brabandt
parent 17f7dff748
commit e542f5e9d0
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
1 changed files with 7 additions and 2 deletions

View File

@ -9,8 +9,13 @@ if exists('*wordcount')
if get(g:, 'actual_curbuf', '') != bufnr('')
return
endif
let query = a:visual_mode_active ? 'visual_words' : 'words'
return get(wordcount(), query, 0)
if &filetype ==# 'tex' && exists('b:vimtex')
" We're in a TeX file and vimtex is a plugin, so use vimtex's wordcount...
return vimtex#misc#wordcount()
else
let query = a:visual_mode_active ? 'visual_words' : 'words'
return get(wordcount(), query, 0)
endif
endfunction
else " Pull wordcount from the g_ctrl-g stats
function! s:get_wordcount(visual_mode_active)