diff --git a/README.md b/README.md index b95fa11..d1262ab 100644 --- a/README.md +++ b/README.md @@ -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', diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index 2b0b9fa..68485c8 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -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', diff --git a/lua/fzf-lua/actions.lua b/lua/fzf-lua/actions.lua index b939bc7..3db17c2 100644 --- a/lua/fzf-lua/actions.lua +++ b/lua/fzf-lua/actions.lua @@ -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) diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index a7758bc..11a2223 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -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 = { diff --git a/lua/fzf-lua/previewer/builtin.lua b/lua/fzf-lua/previewer/builtin.lua index d504639..5617224 100644 --- a/lua/fzf-lua/previewer/builtin.lua +++ b/lua/fzf-lua/previewer/builtin.lua @@ -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(_) diff --git a/lua/fzf-lua/previewer/init.lua b/lua/fzf-lua/previewer/init.lua index 2e7dcc7..f203a53 100644 --- a/lua/fzf-lua/previewer/init.lua +++ b/lua/fzf-lua/previewer/init.lua @@ -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 diff --git a/lua/fzf-lua/providers/helptags.lua b/lua/fzf-lua/providers/helptags.lua index 95df2c1..82ef68f 100644 --- a/lua/fzf-lua/providers/helptags.lua +++ b/lua/fzf-lua/providers/helptags.lua @@ -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)