diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2023-07-04 23:33:23 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2023-07-05 00:49:10 +0200 |
commit | e644e7ce0b36dd5e75770f3faa0a84f15e2561e8 (patch) | |
tree | 32a5501e84a465b5cd1b5c315b7795854ae73d78 /runtime/plugin | |
parent | 67b2ed1004ae551c9fe1bbd29a86b5a301570800 (diff) | |
download | rneovim-e644e7ce0b36dd5e75770f3faa0a84f15e2561e8.tar.gz rneovim-e644e7ce0b36dd5e75770f3faa0a84f15e2561e8.tar.bz2 rneovim-e644e7ce0b36dd5e75770f3faa0a84f15e2561e8.zip |
fix(vim.ui.open): return (don't show) error message
Problem:
Showing an error via vim.notify() makes it awkward for callers such as
lsp/handlers.lua to avoid showing redundant errors.
Solution:
Return the message instead of showing it. Let the caller decide whether
and when to show the message.
Diffstat (limited to 'runtime/plugin')
-rw-r--r-- | runtime/plugin/nvim.lua | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/runtime/plugin/nvim.lua b/runtime/plugin/nvim.lua index 9fff6246e3..33d399e577 100644 --- a/runtime/plugin/nvim.lua +++ b/runtime/plugin/nvim.lua @@ -22,12 +22,23 @@ end, { desc = 'Inspect treesitter language tree for buffer', count = true }) -- TODO: use vim.region() when it lands... #13896 #16843 local function get_visual_selection() local save_a = vim.fn.getreginfo('a') - vim.cmd[[norm! "ay]] + vim.cmd([[norm! "ay]]) local selection = vim.fn.getreg('a', 1) vim.fn.setreg('a', save_a) return selection end -local gx_desc = 'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)' -vim.keymap.set({ 'n' }, 'gx', function() vim.ui.open(vim.fn.expand('<cfile>')) end, { desc = gx_desc }) -vim.keymap.set({ 'x' }, 'gx', function() vim.ui.open(get_visual_selection()) end, { desc = gx_desc }) +local gx_desc = + 'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)' +local function do_open(uri) + local _, err = vim.ui.open(uri) + if err then + vim.notify(err, vim.log.levels.ERROR) + end +end +vim.keymap.set({ 'n' }, 'gx', function() + do_open(vim.fn.expand('<cfile>')) +end, { desc = gx_desc }) +vim.keymap.set({ 'x' }, 'gx', function() + do_open(get_visual_selection()) +end, { desc = gx_desc }) |