From a8148d496fe8fceabf9c949bec66fa4e6381133a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 26 Jun 2014 19:02:03 +0100 Subject: [PATCH] Add :next and :prev for cycling though grep results --- rc/grep.kak | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rc/grep.kak b/rc/grep.kak index 2c9ca9ec..12ec6915 100644 --- a/rc/grep.kak +++ b/rc/grep.kak @@ -1,5 +1,6 @@ decl str grepcmd 'grep -RHn' decl str toolsclient +decl -hidden int _grep_current_line 0 def -shell-params -file-completion \ grep %{ %sh{ @@ -14,6 +15,7 @@ def -shell-params -file-completion \ echo "eval -try-client '$kak_opt_toolsclient' %{ edit! -fifo ${output} -scroll *grep* set buffer filetype grep + set buffer _grep_current_line 0 hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } }" }} @@ -21,6 +23,7 @@ def -shell-params -file-completion \ hook global WinSetOption filetype=grep %{ addhl group grep addhl -group grep regex "^([^:]+):(\d+):(\d+)?" 1:cyan 2:green 3:green + addhl -group grep line_option _grep_current_line default,blue hook buffer -group grep-hooks NormalKey jump } @@ -30,6 +33,23 @@ decl str jumpclient def jump %{ exec 'xs^([^:]+):(\d+):(\d+)?' + set buffer _grep_current_line %val{cursor_line} eval -try-client %opt{jumpclient} edit %reg{1} %reg{2} %reg{3} try %{ focus %opt{jumpclient} } } + +def next -docstring 'Jump to next grep match' %{ + eval -try-client %opt{jumpclient} %{ + buffer '*grep*' + exec %rec{%opt{_grep_current_line}ggl/^[^:]+:\d+:} + jump + } +} + +def prev -docstring 'Jump to previous grep match' %{ + eval -try-client %opt{jumpclient} %{ + buffer '*grep*' + exec %rec{%opt{_grep_current_line}g^[^:]+:\d+:} + jump + } +}