diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2024-02-25 11:12:55 +0100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-02-27 00:03:36 +1100 |
| commit | 40ffd5ff3b7e8990ddc9d1a96dcb4dd72423ceef (patch) | |
| tree | d75f2e1f548de4f10f174a9fbc89347cb1efbc1b | |
| parent | 20d353936e10b512e30beb3cd4089b5334dfe750 (diff) | |
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.
| -rw-r--r-- | rc/tools/grep.kak | 6 | ||||
| -rw-r--r-- | 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 a3685431..eb6eed10 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+)?<ret>' + execute-keys 'xs^([^:\n]+):(\d+):(\d+)?<ret>' 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<a-l> will be a no-op and we'll jump to the first result. # Yeah, thats ugly... - execute-keys ge %opt{grep_current_line}g<a-l> /^[^:]+:\d+:<ret> + execute-keys ge %opt{grep_current_line}g<a-l> /^[^:\n]+:\d+:<ret> 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<a-h> <a-/>^[^:]+:\d+:<ret> + execute-keys ge %opt{grep_current_line}g<a-h> <a-/>^[^:\n]+:\d+:<ret> grep-jump } try %{ diff --git a/rc/tools/make.kak b/rc/tools/make.kak index acdcb31e..f2c47292 100644 --- a/rc/tools/make.kak +++ b/rc/tools/make.kak @@ -56,7 +56,7 @@ define-command -hidden make-jump %{ try %{ execute-keys gl<a-?> "Entering directory" <ret><a-:> # Try to parse the error into capture groups, failing on absolute paths - execute-keys s "Entering directory [`']([^']+)'.*\n([^:/][^:]*):(\d+):(?:(\d+):)?([^\n]+)\z" <ret>l + execute-keys s "Entering directory [`']([^']+)'.*\n([^:\n/][^:\n]*):(\d+):(?:(\d+):)?([^\n]+)\z" <ret>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 %{ |
