commit a961bb71010b5579df9d05aae17fe224f8066e94
parent 057a5bc78d90db50caa85cdb34986fb186f0fd98
Author: zeertzjq <zeertzjq@outlook.com>
Date: Mon, 8 May 2023 16:09:33 +0800
Merge pull request #23486 from msva/patch-1
fix(man.lua): return support of all sections
Diffstat:
2 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua
@@ -583,7 +583,7 @@ local function get_paths(sect, name)
local mandirs = table.concat(vim.split(mandirs_raw, '[:\n]', { trimempty = true }), ',')
---@type string[]
- local paths = fn.globpath(mandirs, 'man?/' .. name .. '*.' .. sect .. '*', false, true)
+ local paths = fn.globpath(mandirs, 'man[^\\/]*/' .. name .. '*.' .. sect .. '*', false, true)
-- Prioritize the result from find_path as it obeys b:man_default_sects.
local first = M.find_path(sect, name)
@@ -739,7 +739,12 @@ function M.open_page(count, smods, args)
else
-- Combine the name and sect into a manpage reference so that all
-- verification/extraction can be kept in a single function.
- if tonumber(args[1]) then
+ if args[1]:match('^%d$') or args[1]:match('^%d%a') or args[1]:match('^%a$') then
+ -- NB: Valid sections are not only digits, but also:
+ -- - <digit><word> (see POSIX mans),
+ -- - and even <letter> and <word> (see, for example, by tcl/tk)
+ -- NB2: don't optimize to :match("^%d"), as it will match manpages like
+ -- 441toppm and others whose name starts with digit
local sect = args[1]
table.remove(args, 1)
local name = table.concat(args, ' ')
diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua
@@ -20,10 +20,10 @@ local function get_search_history(name)
local man = require('runtime.lua.man')
local res = {}
man.find_path = function(sect, name)
- table.insert(res, name)
+ table.insert(res, {sect, name})
return nil
end
- local ok, rv = pcall(man.open_page, 0, {tab = 0}, args)
+ local ok, rv = pcall(man.open_page, -1, {tab = 0}, args)
assert(not ok)
assert(rv and rv:match('no manual entry'))
return res
@@ -196,16 +196,32 @@ describe(':Man', function()
it('tries variants with spaces, underscores #22503', function()
eq({
- 'NAME WITH SPACES',
- 'NAME_WITH_SPACES',
+ {'', 'NAME WITH SPACES'},
+ {'', 'NAME_WITH_SPACES'},
}, get_search_history('NAME WITH SPACES'))
eq({
- 'some other man',
- 'some_other_man',
+ {'3', 'some other man'},
+ {'3', 'some_other_man'},
}, get_search_history('3 some other man'))
eq({
- 'other_man',
- 'other_man',
+ {'3x', 'some other man'},
+ {'3x', 'some_other_man'},
+ }, get_search_history('3X some other man'))
+ eq({
+ {'3tcl', 'some other man'},
+ {'3tcl', 'some_other_man'},
+ }, get_search_history('3tcl some other man'))
+ eq({
+ {'n', 'some other man'},
+ {'n', 'some_other_man'},
+ }, get_search_history('n some other man'))
+ eq({
+ {'', '123some other man'},
+ {'', '123some_other_man'},
+ }, get_search_history('123some other man'))
+ eq({
+ {'1', 'other_man'},
+ {'1', 'other_man'},
}, get_search_history('other_man(1)'))
end)
end)