diff options
| -rw-r--r-- | .vim/lua/misc.lua | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/.vim/lua/misc.lua b/.vim/lua/misc.lua index 37ef854..6c642f4 100644 --- a/.vim/lua/misc.lua +++ b/.vim/lua/misc.lua @@ -148,28 +148,31 @@ function M.fold_block() -- {{{ vim.api.nvim_win_set_cursor(0, inital_cusor_pos) end -- }}} -local function render_link_preview(buf, ln, link) - local j = require('plenary.job'):new({ - command = vim.env.SHELL, - args = {'-c', [[ curl -sSfL ]] .. link .. [[ | grep -iPo '(?<=property="og:title" content=")([^\"]+)(?=")' ]]}, - enable_recording = true, - }) - local results, code = j:sync() - if not code == 0 or #results == 0 then return end - - local ns = vim.api.nvim_create_namespace('') - vim.api.nvim_buf_set_extmark(buf, ns, ln, 0, { - virt_text = {{results[1], 'Error'}}, - virt_text_pos = 'eol' - }) -end function M.link_preview() local link = vim.fn.expand('<cfile>') if not link then return end + local buf = vim.api.nvim_get_current_buf() local ln = (vim.api.nvim_win_get_cursor(0)[1]) - 1 - render_link_preview(0, ln, link) + local j = require('job').jobstart({ + format_title = function() return "link-preview" end, + command = vim.env.SHELL, + args = {'-c', [[ curl -sSfL ]] .. link .. [[ | grep -iPo '(?<=property="og:title" content=")([^\"]+)(?=")' ]]}, + populate_quickfix = false, + enable_recording = true, + }) + + j:after_success(vim.schedule_wrap(function(j, code, _) + local results = j:result() + if not code == 0 or #results == 0 then return end + + local ns = vim.api.nvim_create_namespace('') + vim.api.nvim_buf_set_extmark(buf, ns, ln, 0, { + virt_text = {{results[1], 'Error'}}, + virt_text_pos = 'eol' + }) + end)) end return M |