fix: man_pages previewer, respecting MANPATH and apropos output parsing (#1764)

- introducing putils writer and use it rather than using PAGER env var
- introducing env for lua/telescope/_.lua job interface
  - to respect MANPATH (and PATH just in case)
- fix for apropos output parsing might return e.g. `alacritty, Alacritty`
  We need to split on first `,`
This commit is contained in:
Simon Hauser
2022-03-10 13:48:40 +01:00
committed by GitHub
parent 1daf0917cf
commit 234066f875
7 changed files with 42 additions and 3 deletions

View File

@@ -610,7 +610,7 @@ end, {})
previewers.man = defaulter(function(opts)
local pager = utils.get_lazy_default(opts.PAGER, function()
return vim.fn.executable "col" == 1 and "col -bx" or ""
return vim.fn.executable "col" == 1 and { "col", "-bx" } or { "cat" }
end)
return previewers.new_buffer_previewer {
title = "Man Preview",
@@ -620,8 +620,9 @@ previewers.man = defaulter(function(opts)
define_preview = function(self, entry, status)
local win_width = vim.api.nvim_win_get_width(self.state.winid)
putils.job_maker({ "man", entry.section, entry.value }, self.state.bufnr, {
env = { ["PAGER"] = pager, ["MANWIDTH"] = win_width },
putils.job_maker(vim.deepcopy(pager), self.state.bufnr, {
writer = { "man", entry.section, entry.value },
env = { ["MANWIDTH"] = win_width, PATH = vim.env.PATH, MANPATH = vim.env.MANPATH },
value = entry.value .. "/" .. entry.section,
bufname = self.state.bufname,
})

View File

@@ -33,12 +33,25 @@ utils.job_maker = function(cmd, bufnr, opts)
-- if any of them are missing, cache will be skipped
if opts.bufname ~= opts.value or not opts.bufname or not opts.value then
local command = table.remove(cmd, 1)
local writer = (function()
if opts.writer ~= nil then
local wcommand = table.remove(opts.writer, 1)
return Job:new {
command = wcommand,
args = opts.writer,
env = opts.env,
cwd = opts.cwd,
}
end
end)()
Job
:new({
command = command,
args = cmd,
env = opts.env,
cwd = opts.cwd,
writer = writer,
on_exit = vim.schedule_wrap(function(j)
if not vim.api.nvim_buf_is_valid(bufnr) then
return