feat(help_tags): preview no longer runs `:help` (closes #457)

main
bhagwan 2 years ago
parent 6a4392564b
commit d44a33733e

@ -770,26 +770,23 @@ require'fzf-lua'.setup {
["Hint"] = { icon = "", color = "magenta" }, -- hint
},
},
-- uncomment to disable the previewer
-- nvim = { marks = { previewer = { _ctor = false } } },
-- helptags = { previewer = { _ctor = false } },
-- manpages = { previewer = { _ctor = false } },
-- uncomment to set dummy win location (help|man bar)
-- "topleft" : up
-- "botright" : down
-- helptags = { previewer = { split = "topleft" } },
-- uncomment to use the old help previewer which used a
-- minimized help window to generate the help tag preview
-- helptags = { previewer = "help_tags" },
-- uncomment to use `man` command as native fzf previewer
-- manpages = { previewer = { _ctor = require'fzf-lua.previewer'.fzf.man_pages } },
-- (instead of using a neovim floating window)
-- manpages = { previewer = "man_native" },
--
-- optional override of file extension icon colors
-- available colors (terminal):
-- clear, bold, black, red, green, yellow
-- blue, magenta, cyan, grey, dark_grey, white
file_icon_colors = {
["sh"] = "green",
},
-- padding can help kitty term users with
-- double-width icon rendering
file_icon_padding = '',
file_icon_colors = {
["lua"] = "blue",
},
-- uncomment if your terminal/font does not support unicode character
-- 'EN SPACE' (U+2002), the below sets it to 'NBSP' (U+00A0) instead
-- nbsp = '\xc2\xa0',

@ -815,26 +815,23 @@ Consult the list below for available settings:
["Hint"] = { icon = "", color = "magenta" }, -- hint
},
},
-- uncomment to disable the previewer
-- nvim = { marks = { previewer = { _ctor = false } } },
-- helptags = { previewer = { _ctor = false } },
-- manpages = { previewer = { _ctor = false } },
-- uncomment to set dummy win location (help|man bar)
-- "topleft" : up
-- "botright" : down
-- helptags = { previewer = { split = "topleft" } },
-- uncomment to use the old help previewer which used a
-- minimized help window to generate the help tag preview
-- helptags = { previewer = "help_tags" },
-- uncomment to use `man` command as native fzf previewer
-- manpages = { previewer = { _ctor = require'fzf-lua.previewer'.fzf.man_pages } },
-- (instead of using a neovim floating window)
-- manpages = { previewer = "man_native" },
--
-- optional override of file extension icon colors
-- available colors (terminal):
-- clear, bold, black, red, green, yellow
-- blue, magenta, cyan, grey, dark_grey, white
file_icon_colors = {
["sh"] = "green",
},
-- padding can help kitty term users with
-- double-width icon rendering
file_icon_padding = '',
file_icon_colors = {
["lua"] = "blue",
},
-- uncomment if your terminal/font does not support unicode character
-- 'EN SPACE' (U+2002), the below sets it to 'NBSP' (U+00A0) instead
-- nbsp = '\xc2\xa0',

@ -410,19 +410,25 @@ M.packadd = function(selected)
end
end
local function helptags(s)
return vim.tbl_map(function(x)
return x:match("[^%s]+")
end, s)
end
M.help = function(selected)
local vimcmd = "help"
M.vimcmd(vimcmd, selected, true)
M.vimcmd(vimcmd, helptags(selected), true)
end
M.help_vert = function(selected)
local vimcmd = "vert help"
M.vimcmd(vimcmd, selected, true)
M.vimcmd(vimcmd, helptags(selected), true)
end
M.help_tab = function(selected)
local vimcmd = "tab help"
M.vimcmd(vimcmd, selected, true)
M.vimcmd(vimcmd, helptags(selected), true)
end
M.man = function(selected)

@ -176,6 +176,13 @@ M.globals = {
cmd = "man",
_ctor = previewers.fzf.man_pages,
},
help_tags = {
split = "botright", -- "topleft"
_ctor = previewers.builtin.help_tags,
},
help_file = {
_ctor = previewers.builtin.help_file,
},
builtin = {
syntax = true,
syntax_delay = 0,
@ -460,8 +467,12 @@ M.globals.helptags = {
["ctrl-v"] = actions.help_vert,
["ctrl-t"] = actions.help_tab,
},
fzf_opts = {
['--delimiter'] = "'[ ]'",
['--with-nth'] = "..-2",
},
previewer = {
_ctor = previewers.builtin.help_tags,
_ctor = previewers.builtin.help_file,
},
}
M.globals.manpages = {

@ -12,6 +12,12 @@ local Previewer = {}
Previewer.base = Object:extend()
function Previewer.base:new(o, opts, fzf_win)
local function default(var, def)
if var ~= nil then return var
else return def end
end
o = o or {}
self.type = "builtin"
self.opts = opts;
@ -19,11 +25,11 @@ function Previewer.base:new(o, opts, fzf_win)
self.delay = self.win.winopts.preview.delay or 100
self.title = self.win.winopts.preview.title
self.winopts = self.win.winopts.preview.winopts
self.syntax = o.syntax
self.syntax_delay = o.syntax_delay
self.syntax_limit_b = o.syntax_limit_b
self.syntax_limit_l = o.syntax_limit_l
self.limit_b = o.limit_b
self.syntax = default(o.syntax, true)
self.syntax_delay = default(o.syntax_delay, 0)
self.syntax_limit_b = default(o.syntax_limit_b, 1024*1024)
self.syntax_limit_l = default(o.syntax_limit_l, 0)
self.limit_b = default(o.limit_b, 1024*1024*10)
self.backups = {}
-- convert extension map to lower case
if o.extensions then
@ -41,7 +47,7 @@ function Previewer.base:new(o, opts, fzf_win)
["cover"] = "cover",
["forced_cover"] = "forced_cover",
}
self.ueberzug_scaler = uz_scalers[o.ueberzug_scaler]
self.ueberzug_scaler = o.ueberzug_scaler and uz_scalers[o.ueberzug_scaler]
if o.ueberzug_scaler and not self.ueberzug_scaler then
utils.warn(("Invalid ueberzug image scaler '%s', option will be omitted.")
:format(o.ueberzug_scaler))
@ -687,7 +693,7 @@ function Previewer.help_tags:exec_cmd(str)
end
function Previewer.help_tags:parse_entry(entry_str)
return entry_str
return entry_str:match("[^%s]+")
end
local function curtab_helpbuf()
@ -758,8 +764,47 @@ function Previewer.help_tags:win_leave()
self.prev_help_bufnr = nil
end
-- inherit from help_tags for the specialized
-- 'gen_winopts()' without ':set number'
Previewer.help_file = Previewer.buffer_or_file:extend()
function Previewer.help_file:new(o, opts, fzf_win)
Previewer.help_file.super.new(self, o, opts, fzf_win)
return self
end
function Previewer.help_file:parse_entry(entry_str)
local tag, filename = entry_str:match("(.*)%s+(.*)$")
return {
htag = tag,
hregex = ([[\V*%s*]]):format(tag:gsub([[\]], [[\\]])),
path = filename,
filetype = 'help',
}
end
function Previewer.help_file:gen_winopts()
local winopts = {
wrap = self.win.preview_wrap,
number = false
}
return vim.tbl_extend("keep", winopts, self.winopts)
end
function Previewer.help_file:set_cursor_hl(entry)
pcall(api.nvim_win_call, self.win.preview_winid, function()
-- start searching at line 1 in case we
-- didn't reload the buffer (same file)
api.nvim_win_set_cursor(0, {1, 0})
fn.clearmatches()
fn.search(entry.hregex, "W")
if self.win.winopts.hl.search then
fn.matchadd(self.win.winopts.hl.search, entry.hregex)
end
self.orig_pos = api.nvim_win_get_cursor(0)
utils.zz()
end)
end
Previewer.man_pages = Previewer.base:extend()
function Previewer.man_pages:should_clear_preview(_)

@ -12,6 +12,7 @@ Previewer.fzf.man_pages = function() return require 'fzf-lua.previewer.fzf'.man_
Previewer.builtin = {}
Previewer.builtin.buffer_or_file = function() return require 'fzf-lua.previewer.builtin'.buffer_or_file end
Previewer.builtin.help_tags = function() return require 'fzf-lua.previewer.builtin'.help_tags end
Previewer.builtin.help_file = function() return require 'fzf-lua.previewer.builtin'.help_file end
Previewer.builtin.man_pages = function() return require 'fzf-lua.previewer.builtin'.man_pages end
Previewer.builtin.marks = function() return require 'fzf-lua.previewer.builtin'.marks end
Previewer.builtin.jumps = function() return require 'fzf-lua.previewer.builtin'.jumps end

@ -50,7 +50,7 @@ local fzf_function = function (cb)
--[[ local tag = string.format("%-58s\t%s",
utils.ansi_codes.blue(t.name),
utils._if(t.name and #t.name>0, path.basename(t.name), '')) ]]
local tag = utils.ansi_codes.magenta(t.name)
local tag = ("%s %s"):format(utils.ansi_codes.magenta(t.name), t.filename)
fzf_cb(tag, function()
coroutine.resume(co)
end)

Loading…
Cancel
Save