From 40ffd5ff3b7e8990ddc9d1a96dcb4dd72423ceef Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 25 Feb 2024 11:12:55 +0100 Subject: [PATCH] rc grep/make: never match multiline filenames If a user modifies a grep buffer, we can end up in weird situations where we try match a filename over multiple lines. Let's rule out newlines in filenames here. There is an argument this is a case of GIGO but we already do this for the corresponding highlighters. We also do it in make.kak, see ca225ad4d (Cleanup make.kak and optimize the make-next/make-prev regexes, 2016-12-09). There is one case left where a filename would theoretically span multiple lines. Fix and optimize this too. --- rc/tools/grep.kak | 6 +++--- rc/tools/make.kak | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rc/tools/grep.kak b/rc/tools/grep.kak index a36854313..eb6eed10a 100644 --- a/rc/tools/grep.kak +++ b/rc/tools/grep.kak @@ -54,7 +54,7 @@ declare-option -docstring "name of the client in which all source code jumps wil define-command -hidden grep-jump %{ evaluate-commands %{ # use evaluate-commands to ensure jumps are collapsed try %{ - execute-keys 'xs^([^:]+):(\d+):(\d+)?' + execute-keys 'xs^([^:\n]+):(\d+):(\d+)?' set-option buffer grep_current_line %val{cursor_line} evaluate-commands -try-client %opt{jumpclient} -verbatim -- edit -existing %reg{1} %reg{2} %reg{3} try %{ focus %opt{jumpclient} } @@ -68,7 +68,7 @@ define-command grep-next-match -docstring 'Jump to the next grep match' %{ # First jump to end of buffer so that if grep_current_line == 0 # 0g will be a no-op and we'll jump to the first result. # Yeah, thats ugly... - execute-keys ge %opt{grep_current_line}g /^[^:]+:\d+: + execute-keys ge %opt{grep_current_line}g /^[^:\n]+:\d+: grep-jump } try %{ @@ -83,7 +83,7 @@ define-command grep-previous-match -docstring 'Jump to the previous grep match' evaluate-commands -try-client %opt{jumpclient} %{ buffer '*grep*' # See comment in grep-next-match - execute-keys ge %opt{grep_current_line}g ^[^:]+:\d+: + execute-keys ge %opt{grep_current_line}g ^[^:\n]+:\d+: grep-jump } try %{ diff --git a/rc/tools/make.kak b/rc/tools/make.kak index acdcb31ec..f2c472923 100644 --- a/rc/tools/make.kak +++ b/rc/tools/make.kak @@ -56,7 +56,7 @@ define-command -hidden make-jump %{ try %{ execute-keys gl "Entering directory" # Try to parse the error into capture groups, failing on absolute paths - execute-keys s "Entering directory [`']([^']+)'.*\n([^:/][^:]*):(\d+):(?:(\d+):)?([^\n]+)\z" l + execute-keys s "Entering directory [`']([^']+)'.*\n([^:\n/][^:\n]*):(\d+):(?:(\d+):)?([^\n]+)\z" l set-option buffer make_current_error_line %val{cursor_line} make-open-error "%reg{1}/%reg{2}" "%reg{3}" "%reg{4}" "%reg{5}" } catch %{