diff options
Diffstat (limited to 'autoload/latex_wordcount.vim')
| -rw-r--r-- | autoload/latex_wordcount.vim | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/autoload/latex_wordcount.vim b/autoload/latex_wordcount.vim new file mode 100644 index 0000000..c60a4d0 --- /dev/null +++ b/autoload/latex_wordcount.vim @@ -0,0 +1,38 @@ +" autoload/latex_wordcount.vim + +function! latex_wordcount#GetWordCountSingle() abort +lua << EOF + local wc = require("latex_wordcount") + local config = wc.default_config() + local json_path = vim.g.json_path + if json_path and json_path ~= "" then + local ok, err = pcall(wc.load_config, config, vim.fn.expand(json_path)) + if not ok then + vim.notify(tostring(err), vim.log.levels.ERROR) + return + end + end + local count = wc.count_buffer(0, config, { follow_includes = false }) + vim.notify(string.format("Real words (this file only): %d", count)) +EOF +endfunction + +function! latex_wordcount#GetWordCountMulti() abort +lua << EOF + local wc = require("latex_wordcount") + local config = wc.default_config() + local json_path = vim.g.json_path + if json_path and json_path ~= "" then + local ok, err = pcall(wc.load_config, config, vim.fn.expand(json_path)) + if not ok then + vim.notify(tostring(err), vim.log.levels.ERROR) + return + end + end + local count, _, _, warnings = wc.count_buffer(0, config, { follow_includes = true }) + vim.notify(string.format("Real words (including \\input/\\include): %d", count)) + if warnings and #warnings > 0 then + vim.notify("include warnings:\n" .. table.concat(warnings, "\n"), vim.log.levels.WARN) + end +EOF +endfunction |
