From 4dac61c864a3ec4b480cfd5229ca92890f8b9b7f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 28 Jul 2017 20:19:58 +0200 Subject: [PATCH] Fix grep-next/prev-match not jumping correctly to first/last match When used just after grepping, grep-next-match ended up jumping to the second match, as `0g` is the same as `g`. The fix itself is pretty ugly, a better one might be to distinguish the `0` count from no count given, so that `0g` could fail with "no such line" or similar. --- rc/core/grep.kak | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rc/core/grep.kak b/rc/core/grep.kak index 8c043077..40072882 100644 --- a/rc/core/grep.kak +++ b/rc/core/grep.kak @@ -60,17 +60,21 @@ def -hidden grep-jump %{ def grep-next-match -docstring 'Jump to the next grep match' %{ eval -collapse-jumps -try-client %opt{jumpclient} %{ buffer '*grep*' - exec "%opt{grep_current_line}g/^[^:]+:\d+:" + # First jump to enf 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... + exec "ge %opt{grep_current_line}g /^[^:]+:\d+:" grep-jump } - try %{ eval -client %opt{toolsclient} %{ exec %opt{grep_current_line}g } } + try %{ eval -client %opt{toolsclient} %{ exec gg %opt{grep_current_line}g } } } def grep-previous-match -docstring 'Jump to the previous grep match' %{ eval -collapse-jumps -try-client %opt{jumpclient} %{ buffer '*grep*' - exec "%opt{grep_current_line}g^[^:]+:\d+:" + # See comment in grep-next-match + exec "ge %opt{grep_current_line}g ^[^:]+:\d+:" grep-jump } - try %{ eval -client %opt{toolsclient} %{ exec %opt{grep_current_line}g } } + try %{ eval -client %opt{toolsclient} %{ exec gg %opt{grep_current_line}g } } }