mirror of
https://github.com/neovim/neovim.git
synced 2026-04-21 23:05:41 +00:00
fix(man.lua): E95 when piping to :Man #33068
Problem: When piping raw manpage content into `:Man!`, buf name is set to 'man://.. ref', but the check only matches the prefix. Allows duplicate buffers to be created, triggering E95. Solution: Match full buf name instead of only 'man://' prefix. If the buffer already exists, generate a unique name with 'man://' .. 'ref' .. '?new=' format. Refs: #30132
This commit is contained in:
@@ -646,8 +646,21 @@ function M.init_pager()
|
||||
local _, sect, err = pcall(parse_ref, ref)
|
||||
vim.b.man_sect = err ~= nil and sect or ''
|
||||
|
||||
if not fn.bufname('%'):match('man://') then -- Avoid duplicate buffers, E95.
|
||||
vim.cmd.file({ 'man://' .. fn.fnameescape(ref):lower(), mods = { silent = true } })
|
||||
local man_bufname = 'man://' .. fn.fnameescape(ref):lower()
|
||||
|
||||
-- Raw manpage into (:Man!) overlooks `match('man://')` condition,
|
||||
-- so if the buffer already exists, create new with a non existing name.
|
||||
if vim.fn.bufexists(man_bufname) == 1 then
|
||||
local new_bufname = man_bufname
|
||||
for i = 1, 100 do
|
||||
if vim.fn.bufexists(new_bufname) == 0 then
|
||||
break
|
||||
end
|
||||
new_bufname = ('%s?new=%s'):format(man_bufname, i)
|
||||
end
|
||||
vim.cmd.file({ new_bufname, mods = { silent = true } })
|
||||
elseif not fn.bufname('%'):match('man://') then -- Avoid duplicate buffers, E95.
|
||||
vim.cmd.file({ man_bufname, mods = { silent = true } })
|
||||
end
|
||||
|
||||
set_options()
|
||||
|
||||
Reference in New Issue
Block a user