summaryrefslogtreecommitdiff
path: root/lua/telescope
diff options
context:
space:
mode:
authorJINNOUCHI Yasushi <me@delphinus.dev>2021-02-02 21:23:37 +0900
committerGitHub <noreply@github.com>2021-02-02 13:23:37 +0100
commitc422d86eb9c262606534754b5f4ee79bd01ae09a (patch)
tree9fb76bcebbddb1b234f4ba60c35f1458691b9f21 /lua/telescope
parent9e76b1613a25cc6f63d17eb73432523924662619 (diff)
feat: add sections opt for man_pages and fix for macos (#413)
:Telescope man_pages sections=3 will only show man pages from section 3 :Telescope man_pages sections=1,2,3 will show man pages from section 1, 2 and 3
Diffstat (limited to 'lua/telescope')
-rw-r--r--lua/telescope/builtin/internal.lua20
-rw-r--r--lua/telescope/make_entry.lua20
-rw-r--r--lua/telescope/previewers/buffer_previewer.lua9
3 files changed, 31 insertions, 18 deletions
diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua
index 3c34b8b..f932f48 100644
--- a/lua/telescope/builtin/internal.lua
+++ b/lua/telescope/builtin/internal.lua
@@ -429,27 +429,31 @@ internal.help_tags = function(opts)
end
internal.man_pages = function(opts)
- local pages = utils.get_os_command_output(opts.man_cmd or { 'apropos', '--sections=1', '' })
+ opts.sections = utils.get_default(opts.sections, {'1'})
+ assert(vim.tbl_islist(opts.sections), 'sections should be a list')
+ opts.man_cmd = utils.get_lazy_default(opts.man_cmd, function()
+ local is_darwin = vim.loop.os_uname().sysname == 'Darwin'
+ return is_darwin and {'apropos', ' '} or {'apropos', ''}
+ end)
+ opts.entry_maker = opts.entry_maker or make_entry.gen_from_apropos(opts)
pickers.new(opts, {
prompt_title = 'Man',
- finder = finders.new_table {
- results = pages,
- entry_maker = opts.entry_maker or make_entry.gen_from_apropos(opts),
- },
+ finder = finders.new_oneshot_job(opts.man_cmd, opts),
previewer = previewers.man.new(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions._goto_file_selection:replace(function(_, cmd)
local selection = actions.get_selected_entry()
+ local args = selection.section .. ' ' .. selection.value
actions.close(prompt_bufnr)
if cmd == 'edit' or cmd == 'new' then
- vim.cmd('Man ' .. selection.value)
+ vim.cmd('Man ' .. args)
elseif cmd == 'vnew' then
- vim.cmd('vert bo Man ' .. selection.value)
+ vim.cmd('vert bo Man ' .. args)
elseif cmd == 'tabedit' then
- vim.cmd('tab Man ' .. selection.value)
+ vim.cmd('tab Man ' .. args)
end
end)
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua
index d23dcb7..b0d8060 100644
--- a/lua/telescope/make_entry.lua
+++ b/lua/telescope/make_entry.lua
@@ -613,9 +613,14 @@ function make_entry.gen_from_packages(opts)
end
end
-function make_entry.gen_from_apropos()
+function make_entry.gen_from_apropos(opts)
+ local sections = {}
+ for _, section in ipairs(opts.sections) do
+ sections[section] = true
+ end
+
local displayer = entry_display.create {
- separator = "",
+ separator = ' ',
items = {
{ width = 30 },
{ remaining = true },
@@ -624,20 +629,21 @@ function make_entry.gen_from_apropos()
local make_display = function(entry)
return displayer {
- entry.value,
+ { entry.keyword, 'TelescopeResultsFunction' },
entry.description
}
end
return function(line)
- local cmd, _, desc = line:match("^(.*)%s+%((.*)%)%s+%-%s(.*)$")
-
- return {
+ local keyword, cmd, section, desc = line:match'^((.-)%s*%(([^)]+)%).-)%s+%-%s+(.*)$'
+ return keyword and sections[section] and {
value = cmd,
description = desc,
ordinal = cmd,
display = make_display,
- }
+ section = section,
+ keyword = keyword,
+ } or nil
end
end
diff --git a/lua/telescope/previewers/buffer_previewer.lua b/lua/telescope/previewers/buffer_previewer.lua
index ea11c18..0d097b9 100644
--- a/lua/telescope/previewers/buffer_previewer.lua
+++ b/lua/telescope/previewers/buffer_previewer.lua
@@ -372,7 +372,10 @@ previewers.help = defaulter(function(_)
}
end, {})
-previewers.man = defaulter(function(_)
+previewers.man = defaulter(function(opts)
+ local pager = utils.get_lazy_default(opts.PAGER, function()
+ return vim.fn.executable('col') == 1 and 'col -bx' or ''
+ end)
return previewers.new_buffer_previewer {
get_buffer_by_name = function(_, entry)
return entry.value
@@ -380,8 +383,8 @@ previewers.man = defaulter(function(_)
define_preview = function(self, entry, status)
local win_width = vim.api.nvim_win_get_width(self.state.winid)
- putils.job_maker({'man', '-P', 'cat', entry.value}, self.state.bufnr, {
- env = { ["MANWIDTH"] = win_width },
+ putils.job_maker({'man', entry.section, entry.value}, self.state.bufnr, {
+ env = { ["PAGER"] = pager, ["MANWIDTH"] = win_width },
value = entry.value,
bufname = self.state.bufname
})