aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2023-09-01 21:21:16 +0200
committerjdhao <jdhao@hotmail.com>2023-09-01 21:22:22 +0200
commite92362041c9427a5a5a1a8b354afa51343085a7e (patch)
tree3b102ff7236aa51b2bf8e31f16a1d6120991fc65
parent63ff776758996733e747ff4ffa5c1c3f05cebc8a (diff)
fix hlslens issue when no pattern is found
The captured error message is not correct before.
-rw-r--r--lua/config/hlslens.lua7
1 files changed, 4 insertions, 3 deletions
diff --git a/lua/config/hlslens.lua b/lua/config/hlslens.lua
index e23671f..430bd23 100644
--- a/lua/config/hlslens.lua
+++ b/lua/config/hlslens.lua
@@ -12,10 +12,11 @@ local activate_hlslens = function(direction)
local cmd = string.format("normal! %s%szzzv", vim.v.count1, direction)
local status, msg = pcall(vim.cmd, cmd)
+ -- Deal with the case that there is no such pattern in current buffer.
if not status then
- -- 13 is the index where real error message starts
- msg = msg:sub(13)
- api.nvim_err_writeln(msg)
+ local start_idx, _ = string.find(msg, 'E486', 1, true)
+ local msg_part = string.sub(msg, start_idx)
+ api.nvim_err_writeln(msg_part)
return
end