args refactor and resume support

main
bhagwan 2 years ago
parent 6e1ceb6a63
commit 22d7f4b6c5

@ -546,7 +546,7 @@ require'fzf-lua'.setup {
prompt = 'Args ',
files_only = true,
-- actions inherit from 'actions.files' and merge
actions = { ["ctrl-x"] = actions.arg_del }
actions = { ["ctrl-x"] = { actions.arg_del, actions.resume } }
},
oldfiles = {
prompt = 'History ',

@ -588,7 +588,7 @@ Consult the list below for available settings:
prompt = 'Args ',
files_only = true,
-- actions inherit from 'actions.files' and merge
actions = { ["ctrl-x"] = actions.arg_del }
actions = { ["ctrl-x"] = { actions.arg_del, actions.resume } }
},
oldfiles = {
prompt = 'History ',

@ -283,7 +283,7 @@ M.globals.args = {
git_icons = true,
_actions = function() return M.globals.actions.files end,
actions = {
["ctrl-x"] = actions.arg_del
["ctrl-x"] = { actions.arg_del, actions.resume }
},
}
M.globals.oldfiles = {

@ -46,38 +46,56 @@ M.args = function(opts)
opts = config.normalize_opts(opts, config.globals.args)
if not opts then return end
local entries = vim.fn.execute("args")
entries = utils.strsplit(entries, "%s\n")
-- remove the current file indicator
-- remove all non-files
local args = {}
for _, s in ipairs(entries) do
if s:match('^%[') then
s = s:gsub('^%[', ''):gsub('%]$', '')
end
local st = vim.loop.fs_stat(s)
if opts.files_only == false or
st and st.type == 'file' then
table.insert(args, s)
end
if opts.fzf_opts['--header'] == nil then
opts.fzf_opts['--header'] = vim.fn.shellescape((':: %s to delete')
:format(utils.ansi_codes.yellow("<Ctrl-x>")))
end
entries = nil
local contents = function (cb)
for _, x in ipairs(args) do
local function add_entry(x, co)
x = core.make_entry_file(opts, x)
if x then
cb(x, function(err)
if err then return end
-- close the pipe to fzf, this
-- removes the loading indicator in fzf
cb(nil, function() end)
end)
end
if not x then return end
cb(x, function(err)
coroutine.resume(co)
if err then
-- close the pipe to fzf, this
-- removes the loading indicator in fzf
cb(nil, function() end)
end
end)
coroutine.yield()
end
utils.delayed_cb(cb)
-- run in a coroutine for async progress indication
coroutine.wrap(function()
local co = coroutine.running()
local entries = vim.fn.execute("args")
entries = utils.strsplit(entries, "%s\n")
-- remove the current file indicator
-- remove all non-files
-- local start = os.time(); for _ = 1,10000,1 do
for _, s in ipairs(entries) do
if s:match('^%[') then
s = s:gsub('^%[', ''):gsub('%]$', '')
end
local st = vim.loop.fs_stat(s)
if opts.files_only == false or
st and st.type == 'file' then
add_entry(s, co)
end
end
-- end; print("took", os.time()-start, "seconds.")
-- done
cb(nil, function() coroutine.resume(co) end)
coroutine.yield()
end)()
end
opts = core.set_header(opts, 2)
return core.fzf_files(opts, contents)
end

Loading…
Cancel
Save