From 7121983c45d92349a6532f32dcde9f425e30781e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 16 Dec 2024 16:16:57 +0000 Subject: refactor(man.lua): various changes - Replace all uses of vim.regex with simpler Lua patterns. - Replace all uses of vim.fn.substitute with string.gsub. - Rework error handling so expected errors are passed back via a return. - These get routed up an passed to `vim.notify()` - Any other errors will cause a stack trace. - Reworked the module initialization of `localfile_arg` - Updated all type annotations. - Refactored CLI completion by introduction a parse_cmdline() function. - Simplified `show_toc()` - Refactor highlighting - Inline some functions - Fix completion on MacOS 13 and earlier. - Prefer `manpath -q` over `man -w` - Make completion more efficient by avoiding vim.fn.sort and vim.fn.uniq - Reimplement using a single loop --- runtime/plugin/man.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'runtime/plugin') diff --git a/runtime/plugin/man.lua b/runtime/plugin/man.lua index 512b1f63e8..d6d90208a2 100644 --- a/runtime/plugin/man.lua +++ b/runtime/plugin/man.lua @@ -8,9 +8,9 @@ vim.api.nvim_create_user_command('Man', function(params) if params.bang then man.init_pager() else - local ok, err = pcall(man.open_page, params.count, params.smods, params.fargs) - if not ok then - vim.notify(man.errormsg or err, vim.log.levels.ERROR) + local err = man.open_page(params.count, params.smods, params.fargs) + if err then + vim.notify('man.lua: ' .. err, vim.log.levels.ERROR) end end end, { @@ -31,6 +31,9 @@ vim.api.nvim_create_autocmd('BufReadCmd', { pattern = 'man://*', nested = true, callback = function(params) - require('man').read_page(vim.fn.matchstr(params.match, 'man://\\zs.*')) + 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, }) -- cgit