Add :next and :prev for cycling though grep results

This commit is contained in:
Maxime Coste 2014-06-26 19:02:03 +01:00
parent 63878b03c5
commit a8148d496f

View File

@ -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 <c-m> jump
}
@ -30,6 +33,23 @@ decl str jumpclient
def jump %{
exec 'xs^([^:]+):(\d+):(\d+)?<ret>'
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+:<ret>}
jump
}
}
def prev -docstring 'Jump to previous grep match' %{
eval -try-client %opt{jumpclient} %{
buffer '*grep*'
exec %rec{%opt{_grep_current_line}g<a-/>^[^:]+:\d+:<ret>}
jump
}
}