diff options
Diffstat (limited to '.vim/lua/misc.lua')
| -rw-r--r-- | .vim/lua/misc.lua | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/.vim/lua/misc.lua b/.vim/lua/misc.lua index 8b26ed1..4f2b9dc 100644 --- a/.vim/lua/misc.lua +++ b/.vim/lua/misc.lua @@ -2,17 +2,33 @@ local M = {} +function M.do_under_cursor(obj, cb) + return cb(vim.fn.expand(vim.fn.expand(obj))) +end + +function M.word_under_cursor(cb) + return M.do_under_cursor('<cword>', cb) +end + +function M.expr_under_cursor(cb) + return M.do_under_cursor('<cexpr>', cb) +end + +function M.file_under_cursor(cb) + return M.do_under_cursor('<cfile>', cb) +end + function M.open_under_cursor(cmd) - local txt = vim.fn.expand('<cfile>') - local txt = vim.fn.expand(txt) - if not cmd then - vim.fn.inputsave() - cmd = vim.fn.input('open with: ') - vim.fn.inputrestore() - end - if cmd then - c = vim.loop.spawn(cmd, { args = {txt} }, function() c:close() end) - end + return M.file_under_cursor(function(txt) + if not cmd then + vim.fn.inputsave() + cmd = vim.fn.input('open with: ') + vim.fn.inputrestore() + end + if cmd then + c = vim.loop.spawn(cmd, { args = {txt} }, function() c:close() end) + end + end) end return M |