aboutsummaryrefslogtreecommitdiff
path: root/lua/config/hlslens.lua
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2022-04-29 02:21:05 +0800
committerjdhao <jdhao@hotmail.com>2022-04-29 02:21:05 +0800
commitaaafaf58d6010228639fcc17b35d4fa0387b5b2f (patch)
treed71d63f6152604f9c8f19aef582ef3fa905c2cf4 /lua/config/hlslens.lua
parent1b9bd9ceefd31003853e607eeb31198994b9b83b (diff)
fix: error when pressing n/N if pattern not present in buffer
Diffstat (limited to 'lua/config/hlslens.lua')
-rw-r--r--lua/config/hlslens.lua14
1 files changed, 12 insertions, 2 deletions
diff --git a/lua/config/hlslens.lua b/lua/config/hlslens.lua
index cd03af0..e2e048f 100644
--- a/lua/config/hlslens.lua
+++ b/lua/config/hlslens.lua
@@ -8,7 +8,12 @@ vim.keymap.set('n', 'n', '',
noremap = true,
silent = true,
callback = function()
- vim.fn.execute("normal! " .. vim.v.count1 .. "nzzzv")
+ local status, msg = pcall(vim.fn.execute, "normal! " .. vim.v.count1 .. "nzzzv")
+
+ if not status then
+ vim.api.nvim_echo({{msg, "ErrorMsg"}}, false, {})
+ return
+ end
require('hlslens').start()
end
})
@@ -18,7 +23,12 @@ vim.keymap.set('n', 'N', '',
noremap = true,
silent = true,
callback = function()
- vim.fn.execute("normal! " .. vim.v.count1 .. "Nzzzv")
+ local status, msg = pcall(vim.fn.execute, "normal! " .. vim.v.count1 .. "Nzzzv")
+
+ if not status then
+ vim.api.nvim_echo({{msg, "ErrorMsg"}}, false, {})
+ return
+ end
require('hlslens').start()
end
})