c81266d4f6
`grep-next-match` works only on the `*grep*` buffer so it can't be used on buffers that were preserved by renaming or on other grep-flavored buffers created by 3rd party plugins kakoune-find and kakoune-lsp, like `*find*` and `*references*`. Let's generalize `grep-next-match` with a `jump-next` command that takes a buffer argument. This renames some options but I think they're not commonly used. kakoune-lsp is an exception that uses grep_current_line but it's no big deal, things will fail loud and early if options are missing. Since grep.kak and friends now depend on jump.kak, move the jumpclient declaration there as well.
61 lines
2.1 KiB
Plaintext
61 lines
2.1 KiB
Plaintext
# require-module jump
|
|
|
|
declare-option -docstring "shell command run to search for subtext in a file/directory" \
|
|
str grepcmd 'grep -RHn'
|
|
|
|
define-command -params .. -docstring %{
|
|
grep [<arguments>]: grep utility wrapper
|
|
All optional arguments are forwarded to the grep utility
|
|
Passing no argument will perform a literal-string grep for the current selection
|
|
} grep %{ evaluate-commands %sh{
|
|
if [ $# -eq 0 ]; then
|
|
case "$kak_opt_grepcmd" in
|
|
ag\ * | git\ grep\ * | grep\ * | rg\ * | ripgrep\ * | ugrep\ * | ug\ *)
|
|
set -- -F "${kak_selection}"
|
|
;;
|
|
ack\ *)
|
|
set -- -Q "${kak_selection}"
|
|
;;
|
|
*)
|
|
set -- "${kak_selection}"
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-grep.XXXXXXXX)/fifo
|
|
mkfifo ${output}
|
|
( ${kak_opt_grepcmd} "$@" 2>&1 | tr -d '\r' > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
|
|
|
|
printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{
|
|
edit! -fifo ${output} *grep*
|
|
set-option buffer filetype grep
|
|
set-option buffer jump_current_line 0
|
|
hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
|
|
}"
|
|
}}
|
|
complete-command grep file
|
|
|
|
hook -group grep-highlight global WinSetOption filetype=grep %{
|
|
add-highlighter window/grep group
|
|
add-highlighter window/grep/ regex "^([^:\n]+):(\d+):(\d+)?" 1:cyan 2:green 3:green
|
|
add-highlighter window/grep/ line %{%opt{jump_current_line}} default+b
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/grep }
|
|
}
|
|
|
|
hook global WinSetOption filetype=grep %{
|
|
hook buffer -group grep-hooks NormalKey <ret> jump
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks buffer grep-hooks }
|
|
}
|
|
|
|
define-command -hidden grep-jump %{
|
|
jump
|
|
}
|
|
|
|
define-command grep-next-match -docstring %{alias for "jump-next *grep*"} %{
|
|
jump-next *grep*
|
|
}
|
|
|
|
define-command grep-previous-match -docstring %{alias for "jump-previous *grep*"} %{
|
|
jump-previous *grep*
|
|
}
|