robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Barrett Ruthfix(man.lua): cache pages until width changes #40607a6827be98f

master
1.1 KiB50 linesraw
1if vim.g.loaded_man ~= nil then
2  return
3end
4vim.g.loaded_man = true
5
6vim.api.nvim_create_user_command('Man', function(params)
7  local man = require('man')
8  if params.bang then
9    man.init_pager()
10  else
11    local _, err = pcall(man.open_page, params.count, params.smods, params.fargs)
12    if err then
13      vim.notify('man.lua: ' .. err, vim.log.levels.ERROR)
14    end
15  end
16end, {
17  bang = true,
18  bar = true,
19  range = true,
20  addr = 'other',
21  nargs = '*',
22  complete = function(...)
23    return require('man').man_complete(...)
24  end,
25})
26
27local augroup = vim.api.nvim_create_augroup('nvim.man', {})
28
29vim.api.nvim_create_autocmd('BufReadCmd', {
30  group = augroup,
31  pattern = 'man://*',
32  nested = true,
33  callback = function(params)
34    local err = require('man').read_page(assert(params.match:match('man://(.*)')))
35    if err then
36      vim.notify('man.lua: ' .. err, vim.log.levels.ERROR)
37    end
38  end,
39})
40
41vim.api.nvim_create_autocmd('BufWinEnter', {
42  group = augroup,
43  pattern = 'man://*',
44  callback = function()
45    local err = require('man').refresh_page()
46    if err then
47      vim.notify('man.lua: ' .. err, vim.log.levels.ERROR)
48    end
49  end,
50})