diff options
| author | Alvaro Muñoz <alvaro@pwntester.com> | 2020-12-30 00:56:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-30 00:56:12 +0100 |
| commit | e0705b5d4a10570b4b781a5ecfc4f026b2f2cd4e (patch) | |
| tree | 91ba32e28f8bdf73c112ac6e2c78cd5b77ea179f /lua/telescope/previewers/utils.lua | |
| parent | 1d40ab5ccda6be3680fd809d34d93366b11c4ef8 (diff) | |
feat: append mode for previewers.utils.job_maker (#372)
Diffstat (limited to 'lua/telescope/previewers/utils.lua')
| -rw-r--r-- | lua/telescope/previewers/utils.lua | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lua/telescope/previewers/utils.lua b/lua/telescope/previewers/utils.lua index d584577..475083a 100644 --- a/lua/telescope/previewers/utils.lua +++ b/lua/telescope/previewers/utils.lua @@ -22,20 +22,30 @@ end -- API helper functions for buffer previewer --- Job maker for buffer previewer -utils.job_maker = function(cmd, env, value, bufnr, bufname, callback) - if bufname ~= value then +utils.job_maker = function(cmd, bufnr, opts) + opts = opts or {} + opts.mode = opts.mode or "insert" + -- bufname and value are optional + -- if passed, they will be use as the cache key + -- if any of them are missing, cache will be skipped + if opts.bufname ~= opts.value or not opts.bufname or not opts.value then local command = table.remove(cmd, 1) Job:new({ command = command, args = cmd, - env = env, + env = opts.env, on_exit = vim.schedule_wrap(function(j) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, j:result()) - if callback then callback(bufnr, j:result()) end + if opts.mode == "append" then + local count = vim.api.nvim_buf_line_count(bufnr) + vim.api.nvim_buf_set_lines(bufnr, count, -1, false, j:result()) + elseif opts.mode == "insert" then + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, j:result()) + end + if opts.callback then opts.callback(bufnr, j:result()) end end) }):start() else - if callback then callback(bufnr) end + if opts.callback then opts.callback(bufnr) end end end |
