diff options
| author | Robert Günzler <r@gnzler.io> | 2024-05-15 09:00:31 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2024-05-15 09:00:31 +0200 |
| commit | 3dbe74f2eef627e2dc19b79fe06753d5dc09003f (patch) | |
| tree | b78d1cdab62cec9ed4bbe35447108547b935ef03 /.vim/lua/internal/misc.lua | |
| parent | 0ab72c1113139c196115c974eadaded449002c32 (diff) | |
update nvim
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.vim/lua/internal/misc.lua')
| -rw-r--r-- | .vim/lua/internal/misc.lua | 99 |
1 files changed, 27 insertions, 72 deletions
diff --git a/.vim/lua/internal/misc.lua b/.vim/lua/internal/misc.lua index 8664cbc..a92b7aa 100644 --- a/.vim/lua/internal/misc.lua +++ b/.vim/lua/internal/misc.lua @@ -2,53 +2,6 @@ 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, detect_cmd) - return M.file_under_cursor(function(txt) - txt = vim.trim(txt) - if not cmd and detect_cmd then - if vim.regex([[^http.*$]]):match_str(txt) then - cmd = 'url-launcher' - end - if vim.regex([[^(\.\./|[\w\d_/\-])*(\.[\w\d]+)?$]]):match_str(txt) then - cmd = ':edit' - end - vim.notify('open_under_cursor: detected command ' .. txt .. ' => ' .. (cmd or '<nil>')) - end - if not cmd then - vim.fn.inputsave() - vim.ui.input('open with: ', function(result) - cmd = result - end) - vim.fn.inputrestore() - if not cmd then - return - end - end - -- detect vim command - if cmd:sub(1, 1) == ':' then - vim.cmd(cmd:sub(2) .. ' ' .. txt) - else - vim.loop.spawn(cmd, { args = { txt } }) - end - end) -end - local function get_visual_selection() local top = vim.fn.getpos("'<") top = { ln = top[2], col = top[3] } @@ -132,7 +85,7 @@ local get_searchdirs = function(dirs) return dirs end -function onchoice(opts, cb) +local function onchoice(opts, cb) if not cb then return end @@ -143,7 +96,7 @@ function onchoice(opts, cb) return end require('telescope.actions').close(prompt_bufnr) - on_choice(selection.path) + cb(selection.path) end) return true end @@ -209,35 +162,37 @@ function M.link_preview() local ln = vim.api.nvim_win_get_cursor(0)[1] - 1 require('job') - .jobstart({ - format_title = function() - return 'link-preview' - end, - command = vim.env.SHELL, - args = { - '-c', - [[ curl -sSfL ]] + .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, - }) - :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', + }, + populate_quickfix = false, + enable_recording = true, }) - end)) + :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 function M.setup(opts) + opts = opts or {} + if opts.sortline then vim.api.nvim_create_user_command( 'SortLine', |