Initial version of VimtexWordCount (#166)

It has some more potential for improvement, both in how the count is
displayed after `:VimtexWordCount` and in adding some options.
This commit is contained in:
Karl Yngve Lervåg 2015-05-10 11:00:31 +02:00
parent 188fd8ed37
commit 62236ee002
3 changed files with 21 additions and 0 deletions

View File

@ -24,6 +24,7 @@ disabled if desired.
- Document navigation through - Document navigation through
- table of content - table of content
- table of labels - table of labels
- Word count (through `texcount`)
- Motions - Motions
- Move between sections with `[[`, `[]`, `][`, `]]` - Move between sections with `[[`, `[]`, `][`, `]]`
- Move between matching delimiters with `%` - Move between matching delimiters with `%`

View File

@ -51,6 +51,7 @@ function! vimtex#info() " {{{1
for f in ['aux', 'out', 'log'] for f in ['aux', 'out', 'log']
silent execute 'let d.' . f . ' = data.' . f . '()' silent execute 'let d.' . f . ' = data.' . f . '()'
endfor endfor
let d.words = data.words()
" Print data blob title line " Print data blob title line
call vimtex#echo#formatted([ call vimtex#echo#formatted([
@ -90,6 +91,7 @@ function! s:init_environment() " {{{1
function data.out() dict function data.out() dict
return s:get_main_ext(self, 'pdf') return s:get_main_ext(self, 'pdf')
endfunction endfunction
let data.words = function('s:get_wordcount')
call add(g:vimtex#data, data) call add(g:vimtex#data, data)
let b:vimtex.id = len(g:vimtex#data) - 1 let b:vimtex.id = len(g:vimtex#data) - 1
@ -97,6 +99,8 @@ function! s:init_environment() " {{{1
" Define commands " Define commands
command! -buffer VimtexInfo call vimtex#info() command! -buffer VimtexInfo call vimtex#info()
command! -buffer VimtexWordCount
\ echo g:vimtex#data[b:vimtex.id].words()
" Define mappings " Define mappings
nnoremap <buffer> <plug>(vimtex-info) :call vimtex#info()<cr> nnoremap <buffer> <plug>(vimtex-info) :call vimtex#info()<cr>
@ -291,6 +295,14 @@ function! s:get_main_ext(self, ext) " {{{1
return '' return ''
endfunction endfunction
" }}}1
function! s:get_wordcount() dict " {{{1
let cmd = 'cd ' . vimtex#util#fnameescape(self.root)
let cmd .= '; texcount -sum -brief -merge '
\ . vimtex#util#fnameescape(self.base)
return str2nr(matchstr(system(cmd), '^\d\+'))
endfunction
" }}}1 " }}}1
function! s:print_dict(dict, ...) " {{{1 function! s:print_dict(dict, ...) " {{{1

View File

@ -78,6 +78,7 @@ Feature overview~
- Document navigation through - Document navigation through
- table of content - table of content
- table of labels - table of labels
- Word count (through `texcount`)
- Motions - Motions
- Move between sections with `[[`, `[]`, `][`, `]]` - Move between sections with `[[`, `[]`, `][`, `]]`
- Move between matching delimiters with `%` - Move between matching delimiters with `%`
@ -729,6 +730,13 @@ Commands~
*<plug>(vimtex-reverse-search)* *<plug>(vimtex-reverse-search)*
:VimtexRSearch Do reverse search (only available for MuPDF viewer). :VimtexRSearch Do reverse search (only available for MuPDF viewer).
*VimtexWordCount*
:VimtexWordCount Shows the number of words in the current project.
The count is created with `texcount` through a call
on the main project file similar to: >
texcount -sum -brief -merge FILE
<
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
Map definitions~ Map definitions~
*vimtex-mappings* *vimtex-mappings*