From d59bc583287b8925d044ffb139920da5e21a16b3 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Wed, 17 Aug 2022 17:19:42 -0700 Subject: [PATCH] feat(loclist): use `alt-l` to send selection to the loclist (#435) --- README.md | 11 +++++++---- doc/fzf-lua.txt | 11 +++++++---- lua/fzf-lua/actions.lua | 25 +++++++++++++++++++++---- lua/fzf-lua/config.lua | 9 +++++++-- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1d1b0ca..33e301d 100644 --- a/README.md +++ b/README.md @@ -451,6 +451,7 @@ require'fzf-lua'.setup { ["ctrl-v"] = actions.file_vsplit, ["ctrl-t"] = actions.file_tabedit, ["alt-q"] = actions.file_sel_to_qf, + ["alt-l"] = actions.file_sel_to_ll, }, buffers = { -- providers that inherit these actions: @@ -748,8 +749,9 @@ require'fzf-lua'.setup { }, -- actions inherit from 'actions.buffers' and merge actions = { - ["default"] = { actions.buf_edit_or_qf }, - ["alt-q"] = { actions.buf_sel_to_qf } + ["default"] = actions.buf_edit_or_qf, + ["alt-q"] = actions.buf_sel_to_qf, + ["alt-l"] = actions.buf_sel_to_ll }, }, blines = { @@ -765,8 +767,9 @@ require'fzf-lua'.setup { }, -- actions inherit from 'actions.buffers' and merge actions = { - ["default"] = { actions.buf_edit_or_qf }, - ["alt-q"] = { actions.buf_sel_to_qf } + ["default"] = actions.buf_edit_or_qf, + ["alt-q"] = actions.buf_sel_to_qf, + ["alt-l"] = actions.buf_sel_to_ll }, }, tags = { diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index 6659835..702bbf0 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -490,6 +490,7 @@ open an issue and I'll be more than happy to help.** ["ctrl-v"] = actions.file_vsplit, ["ctrl-t"] = actions.file_tabedit, ["alt-q"] = actions.file_sel_to_qf, + ["alt-l"] = actions.file_sel_to_ll, }, buffers = { -- providers that inherit these actions: @@ -787,8 +788,9 @@ open an issue and I'll be more than happy to help.** }, -- actions inherit from 'actions.buffers' and merge actions = { - ["default"] = { actions.buf_edit_or_qf }, - ["alt-q"] = { actions.buf_sel_to_qf } + ["default"] = actions.buf_edit_or_qf, + ["alt-q"] = actions.buf_sel_to_qf, + ["alt-l"] = actions.buf_sel_to_ll }, }, blines = { @@ -804,8 +806,9 @@ open an issue and I'll be more than happy to help.** }, -- actions inherit from 'actions.buffers' and merge actions = { - ["default"] = { actions.buf_edit_or_qf }, - ["alt-q"] = { actions.buf_sel_to_qf } + ["default"] = actions.buf_edit_or_qf, + ["alt-q"] = actions.buf_sel_to_qf, + ["alt-l"] = actions.buf_sel_to_ll }, }, tags = { diff --git a/lua/fzf-lua/actions.lua b/lua/fzf-lua/actions.lua index f24c474..ae546ba 100644 --- a/lua/fzf-lua/actions.lua +++ b/lua/fzf-lua/actions.lua @@ -157,7 +157,7 @@ M.file_open_in_background = function(selected, opts) M.vimcmd_file(vimcmd, selected, opts) end -M.file_sel_to_qf = function(selected, opts) +local sel_to_qf = function(selected, opts, is_loclist) local qf_list = {} for i = 1, #selected do local file = path.entry_to_file(selected[i], opts) @@ -169,8 +169,21 @@ M.file_sel_to_qf = function(selected, opts) text = text, }) end - vim.fn.setqflist(qf_list) - vim.cmd 'copen' + if is_loclist then + vim.fn.setloclist(0, qf_list) + vim.cmd 'lopen' + else + vim.fn.setqflist(qf_list) + vim.cmd 'copen' + end +end + +M.file_sel_to_qf = function(selected, opts) + sel_to_qf(selected, opts) +end + +M.file_sel_to_ll = function(selected, opts) + sel_to_qf(selected, opts, true) end M.file_edit_or_qf = function(selected, opts) @@ -298,7 +311,11 @@ M.buf_switch_or_edit = function(...) end M.buf_sel_to_qf = function(selected, opts) - return M.file_sel_to_qf(selected, opts) + return sel_to_qf(selected, opts) +end + +M.buf_sel_to_ll = function(selected, opts) + return sel_to_qf(selected, opts, true) end M.buf_edit_or_qf = function(selected, opts) diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index da2dcb6..7f7c20b 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -126,6 +126,7 @@ M.globals = { ["ctrl-v"] = actions.file_vsplit, ["ctrl-t"] = actions.file_tabedit, ["alt-q"] = actions.file_sel_to_qf, + ["alt-l"] = actions.file_sel_to_ll, }, buffers = { ["default"] = actions.buf_edit, @@ -393,7 +394,8 @@ M.globals.lines = { _actions = function() return M.globals.actions.buffers end, actions = { ["default"] = actions.buf_edit_or_qf, - ["alt-q"] = actions.buf_sel_to_qf + ["alt-q"] = actions.buf_sel_to_qf, + ["alt-l"] = actions.buf_sel_to_ll }, } M.globals.blines = { @@ -411,7 +413,8 @@ M.globals.blines = { _actions = function() return M.globals.actions.buffers end, actions = { ["default"] = actions.buf_edit_or_qf, - ["alt-q"] = actions.buf_sel_to_qf + ["alt-q"] = actions.buf_sel_to_qf, + ["alt-l"] = actions.buf_sel_to_ll }, } M.globals.tags = { @@ -990,11 +993,13 @@ M._action_to_helpstr = { [actions.file_vsplit] = "file-vsplit", [actions.file_tabedit] = "file-tabedit", [actions.file_sel_to_qf] = "file-selection-to-qf", + [actions.file_sel_to_ll] = "file-selection-to-loclist", [actions.file_switch] = "file-switch", [actions.file_switch_or_edit] = "file-switch-or-edit", [actions.buf_edit] = "buffer-edit", [actions.buf_edit_or_qf] = "buffer-edit-or-qf", [actions.buf_sel_to_qf] = "buffer-selection-to-qf", + [actions.buf_sel_to_ll] = "buffer-selection-to-loclist", [actions.buf_split] = "buffer-split", [actions.buf_vsplit] = "buffer-vsplit", [actions.buf_tabedit] = "buffer-tabedit",