From e92362041c9427a5a5a1a8b354afa51343085a7e Mon Sep 17 00:00:00 2001 From: jdhao Date: Fri, 1 Sep 2023 21:21:16 +0200 Subject: [PATCH] fix hlslens issue when no pattern is found The captured error message is not correct before. --- lua/config/hlslens.lua | 7 ++++--- 1 file 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