added provider for builtin methods

main
bhagwan 3 years ago
parent 4f3ff903c8
commit eb9dec7dcd

@ -129,6 +129,7 @@ nnoremap <c-P> <cmd>lua require('fzf-lua').files()<CR>
|`help_tags`|help tags|
|`man_pages`|man pages|
|`colorschemes`|color schemes|
|`builtin`|fzf-lua builtin methods|
## LSP Commands

@ -10,14 +10,19 @@ M.expect = function(actions)
end
end
if #keys > 0 then
return table.concat(keys, ',')
return string.format("--expect=%s", table.concat(keys, ','))
end
return nil
end
M.act = function(actions, action, selected)
if not actions or not action then return end
if #action == 0 then action = "default" end
M.act = function(actions, selected)
if not actions or not selected then return end
local action = "default"
-- if there are no actions besides default
-- the table will contain the results directly
-- otherwise 'selected[1]` will contain the keybind
-- empty string in selected[1] represents default
if #selected>1 and #selected[1]>0 then action = selected[1] end
if actions[action] then
actions[action](selected)
end
@ -107,8 +112,17 @@ M.buf_del = function(selected)
end
M.colorscheme = function(selected)
if not selected or #selected < 2 then return end
vim.cmd("colorscheme " .. selected[2])
if not selected then return end
local colorscheme = selected[1]
if #selected>1 then colorscheme = selected[2] end
vim.cmd("colorscheme " .. colorscheme)
end
M.run_builtin = function(selected)
if not selected then return end
local method = selected[1]
if #selected>1 then method = selected[2] end
vim.cmd(string.format("lua require'fzf-lua'.%s()", method))
end
M.help = function(selected)

@ -200,6 +200,17 @@ M.lsp = {
},
}
M.builtin = {
prompt = 'Builtin> ',
winopts = {
win_height = 0.65,
win_width = 0.50,
},
actions = {
["default"] = actions.run_builtin,
},
}
-- <F2> toggle preview
-- <F3> toggle preview text wrap
-- <C-f>|<C-b> page down|up

@ -51,7 +51,7 @@ M.build_fzf_cli = function(opts)
[[ %s --layout=%s --bind=%s --prompt=%s]] ..
[[ --preview-window='%s%s' --preview=%s]] ..
[[ --height=100%% --ansi --info=inline]] ..
[[ --expect=%s %s %s]],
[[ %s %s %s]],
opts.fzf_args or cfg.fzf_args or '',
opts.fzf_layout or cfg.fzf_layout,
utils._if(opts.fzf_binds, opts.fzf_binds,
@ -60,7 +60,7 @@ M.build_fzf_cli = function(opts)
utils._if(opts.preview_window, opts.preview_window, cfg.preview_window()),
utils._if(#opts.preview_offset>0, ":"..opts.preview_offset, ''),
utils._if(opts.preview, opts.preview, M.preview_cmd(opts, cfg)),
utils._if(opts.actions, actions.expect(opts.actions), 'ctrl-s,ctrl-v,ctrl-t'),
utils._if(actions.expect(opts.actions), actions.expect(opts.actions), ''),
utils._if(opts.nomulti, '--no-multi', '--multi'),
utils._if(opts.cli_args, opts.cli_args, '')
)
@ -208,7 +208,7 @@ M.fzf_files = function(opts)
-- dump fails after fzf for some odd reason
-- functions are still valid as can seen by pairs
-- _G.dump(opts.actions)
actions.act(opts.actions, selected[1], selected)
actions.act(opts.actions, selected)
end)()

@ -163,11 +163,15 @@ function M.setup(opts)
setopts(config.helptags, opts.helptags, {
prompt = "string",
})
setopts(config.builtin, opts.builtin, {
prompt = "string",
})
-- table overrides without losing defaults
for _, k in ipairs({
"git", "files", "oldfiles", "buffers",
"grep", "quickfix", "loclist",
"grep", "quickfix", "loclist", "lsp",
"colorschemes", "helptags", "manpages",
"builtin",
}) do
setopt_tbl(config[k], opts[k], "actions")
setopt_tbl(config[k], opts[k], "winopts")
@ -216,4 +220,11 @@ M.lsp_code_actions = require'fzf-lua.providers.lsp'.code_actions
M.lsp_document_diagnostics = require'fzf-lua.providers.lsp'.diagnostics
M.lsp_workspace_diagnostics = require'fzf-lua.providers.lsp'.workspace_diagnostics
M.builtin = function(self)
return require'fzf-lua.providers.module'.metatable({
metatable = M,
metatable_exclude = { ["setup"]=0, ["fzf_files"]=0 },
})
end
return M

@ -140,7 +140,7 @@ M.buffers = function(opts)
end
end
actions.act(opts.actions, selected[1], selected)
actions.act(opts.actions, selected)
end)()
end

@ -37,20 +37,26 @@ M.colorschemes = function(opts)
local current_background = vim.o.background
local colors = vim.list_extend(opts.colors or {}, vim.fn.getcompletion('', 'color'))
-- must add ':nohidden' or fzf ignore the preview action
-- disabling our live preview of colorschemes
opts.preview = prev_act
opts.preview_window = opts.preview_window or 'right:0'
opts.preview_window = opts.preview_window or 'nohidden:right:0'
opts.nomulti = utils._if(opts.nomulti~=nil, opts.nomulti, true)
local selected = fzf.fzf(colors,
core.build_fzf_cli(opts),
config.winopts(opts.winopts))
if not selected then
-- reset color scheme if live_preview is enabled
-- and nothing or non-default action was selected
if opts.live_preview and (not selected or #selected[1]>0) then
vim.o.background = current_background
vim.cmd("colorscheme " .. current_colorscheme)
vim.o.background = current_background
else
actions.act(opts.actions, selected[1], selected)
end
if selected then
actions.act(opts.actions, selected)
end
if opts.post_reset_cb then

@ -113,7 +113,7 @@ M.helptags = function(opts)
if not selected then return end
actions.act(opts.actions, selected[1], selected)
actions.act(opts.actions, selected)
end)()

@ -266,7 +266,7 @@ M.code_actions = function(opts)
if not selected then return end
actions.act(opts.actions, selected[1], selected)
actions.act(opts.actions, selected)
end)()

@ -50,7 +50,7 @@ M.manpages = function(opts)
end
end
actions.act(opts.actions, selected[1], selected)
actions.act(opts.actions, selected)
end)()

Loading…
Cancel
Save