mirror of
https://github.com/neovim/neovim.git
synced 2026-07-23 01:12:49 +00:00
Problem: :Man unloads hidden buffers, so reopening large pages reruns rendering even when the width is unchanged. Solution: keep regular man buffers loaded and refresh them only when the effective width changes.
51 lines
1.1 KiB
Lua
51 lines
1.1 KiB
Lua
if vim.g.loaded_man ~= nil then
|
|
return
|
|
end
|
|
vim.g.loaded_man = true
|
|
|
|
vim.api.nvim_create_user_command('Man', function(params)
|
|
local man = require('man')
|
|
if params.bang then
|
|
man.init_pager()
|
|
else
|
|
local _, err = pcall(man.open_page, params.count, params.smods, params.fargs)
|
|
if err then
|
|
vim.notify('man.lua: ' .. err, vim.log.levels.ERROR)
|
|
end
|
|
end
|
|
end, {
|
|
bang = true,
|
|
bar = true,
|
|
range = true,
|
|
addr = 'other',
|
|
nargs = '*',
|
|
complete = function(...)
|
|
return require('man').man_complete(...)
|
|
end,
|
|
})
|
|
|
|
local augroup = vim.api.nvim_create_augroup('nvim.man', {})
|
|
|
|
vim.api.nvim_create_autocmd('BufReadCmd', {
|
|
group = augroup,
|
|
pattern = 'man://*',
|
|
nested = true,
|
|
callback = function(params)
|
|
local err = require('man').read_page(assert(params.match:match('man://(.*)')))
|
|
if err then
|
|
vim.notify('man.lua: ' .. err, vim.log.levels.ERROR)
|
|
end
|
|
end,
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd('BufWinEnter', {
|
|
group = augroup,
|
|
pattern = 'man://*',
|
|
callback = function()
|
|
local err = require('man').refresh_page()
|
|
if err then
|
|
vim.notify('man.lua: ' .. err, vim.log.levels.ERROR)
|
|
end
|
|
end,
|
|
})
|