evergarden/nvim

comfy neovim colorscheme for cozy morning coding

git clone https://git.robinwobin.dev/evergarden/nvim

robinfeat: add vimdoc generator5dc6e2f

main
1.9 KiB91 linesraw
1local minidoc = require 'mini.doc'
2
3if _G.MiniDoc == nil then
4  minidoc.setup()
5end
6
7local current = {}
8
9local hooks = vim.deepcopy(MiniDoc.default_hooks)
10
11hooks.write_pre = function(lines)
12  -- Remove first two lines with `======` and `------` delimiters to comply
13  -- with `:h local-additions` template
14  table.remove(lines, 1)
15  table.remove(lines, 1)
16  return lines
17end
18
19local function module_register(s)
20  if #s == 0 then
21    return
22  end
23
24  -- Remove first word (with bits of surrounding whitespace) while capturing it
25  local modname
26  s[1] = s[1]:gsub('%s*\'(%S+)\' ?', function(x)
27    modname = x
28    return ''
29  end, 1)
30  if modname == nil then return end
31
32  local f = vim.tbl_get(s, 'parent', 'parent')
33  if not f then return end
34
35  current.modules = current.modules or {}
36  current.modules[f.info.path] = modname
37end
38
39local function modpattern(name)
40  return "%f[%w_]" .. name .. "%f[^%w_]"
41end
42
43local function module_replace(s)
44  if current.modules == nil then return end
45
46  local f = vim.tbl_get(s, 'parent', 'parent')
47  if not f then return end
48
49  local modname = current.modules[f.info.path]
50  if modname == nil then return end
51
52  s[1] = string.gsub(s[1], modpattern('M'), modname)
53end
54
55hooks.sections['@module'] = function(s)
56  module_register(s)
57end
58
59hooks.section_pre = function(s)
60  MiniDoc.default_hooks.section_pre(s)
61
62  module_replace(s)
63end
64
65hooks.file = function(f)
66  MiniDoc.default_hooks.file(f)
67
68  current.modules[f.info.path] = {}
69end
70
71-- init
72
73local init_base = 'lua/evergarden'
74
75local init_mods = vim
76  .iter(vim.fs.dir(init_base))
77  :map(function(modfile, ftype)
78    if ftype == 'file' then
79      return {
80        name = string.gsub(vim.fs.basename(modfile), '%.lua$', ''),
81        path = vim.fs.joinpath(init_base, modfile),
82      }
83    end
84  end)
85  :each(function(mod)
86    local name = 'evergarden'
87    if name ~= 'init' then
88      name = name .. '-' .. mod.name
89    end
90    minidoc.generate({ mod.path }, 'doc/' .. name .. '.txt', { hooks = hooks })
91  end)