From 88aff72bc8c9b2c0adb20ff2da8c1d898ab4c91b Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 25 Feb 2024 11:12:57 +0100 Subject: [PATCH] rc grep/make: don't touch user selections Since the default make error pattern spans until the end of the line, make-jump select the whole line, moving the cursor to the end. This is especially bad when the error message is very long and hence the cursor movement scrolls the viewport so the file:line:col is no longer visible. Stop moving the cursor in `*make*` and `*grep*` buffers. We already have highlighting to indicate the current line. --- rc/tools/grep.kak | 9 ++++++--- rc/tools/make.kak | 28 ++++++++++++++++------------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/rc/tools/grep.kak b/rc/tools/grep.kak index eb6eed10..d9738842 100644 --- a/rc/tools/grep.kak +++ b/rc/tools/grep.kak @@ -52,11 +52,14 @@ declare-option -docstring "name of the client in which all source code jumps wil str jumpclient define-command -hidden grep-jump %{ - evaluate-commands %{ # use evaluate-commands to ensure jumps are collapsed + evaluate-commands -save-regs a %{ # use evaluate-commands to ensure jumps are collapsed try %{ - execute-keys 'xs^([^:\n]+):(\d+):(\d+)?' + evaluate-commands -draft %{ + execute-keys ',xs^([^:\n]+):(\d+):(\d+)?' + set-register a %reg{1} %reg{2} %reg{3} + } set-option buffer grep_current_line %val{cursor_line} - evaluate-commands -try-client %opt{jumpclient} -verbatim -- edit -existing %reg{1} %reg{2} %reg{3} + evaluate-commands -try-client %opt{jumpclient} -verbatim -- edit -existing -- %reg{a} try %{ focus %opt{jumpclient} } } } diff --git a/rc/tools/make.kak b/rc/tools/make.kak index 85260bc6..5d4813d3 100644 --- a/rc/tools/make.kak +++ b/rc/tools/make.kak @@ -52,19 +52,23 @@ define-command -hidden make-open-error -params 4 %{ } define-command -hidden make-jump %{ - evaluate-commands -save-regs / %{ - try %{ - execute-keys gl "Entering directory" - # Try to parse the error into capture groups, failing on absolute paths - execute-keys s "Entering directory [`']([^']+)'.*\n([^:\n/][^:\n]*):(\d+):(?:(\d+):)?([^\n]+)\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 %{ - set-register / %opt{make_error_pattern} - execute-keys sl - set-option buffer make_current_error_line %val{cursor_line} - make-open-error "%reg{1}" "%reg{2}" "%reg{3}" "%reg{4}" + evaluate-commands -save-regs a/ %{ + evaluate-commands -draft %{ + execute-keys , + try %{ + execute-keys gl "Entering directory" + # Try to parse the error into capture groups, failing on absolute paths + execute-keys s "Entering directory [`']([^']+)'.*\n([^:\n/][^:\n]*):(\d+):(?:(\d+):)?([^\n]+)\n?\z" l + set-option buffer make_current_error_line %val{cursor_line} + set-register a "%reg{1}/%reg{2}" "%reg{3}" "%reg{4}" "%reg{5}" + } catch %{ + set-register / %opt{make_error_pattern} + execute-keys sl + set-option buffer make_current_error_line %val{cursor_line} + set-register a "%reg{1}" "%reg{2}" "%reg{3}" "%reg{4}" + } } + make-open-error %reg{a} } }