summaryrefslogtreecommitdiff
path: root/dot-config/nvim/lua/wordcount.lua
blob: 77e141b52419c76c680ba86d0f34a28c9f383096 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- Wordcount in markdown
--
-- Credits
-- https://github.com/nvim-lualine/lualine.nvim/issues/328#issuecomment-982672253
-- https://github.com/skwee357/nvim-prose

local M = {}

local config = {
  filetypes = { "markdown", "text", "typst" },
}

function M.wordcount()
  local wc = vim.fn.wordcount()

  if not (wc.visual_words == nil) then
    return tostring(wc.visual_words) .. " words"
  end

  return tostring(wc.words) .. " words"
end

function M.is_available()
  for _, ft in ipairs(config.filetypes) do
    if ft == vim.bo.filetype then
      return true
    end
  end

  return false
end

return M