kakoune icon indicating copy to clipboard operation
kakoune copied to clipboard

[QUESTION] How can I stop grep-next-match from wrapping around

Open AndrewVos opened this issue 2 years ago • 1 comments

Question

I find it quite tricky when I'm doing manual find/replaces because the search wraps around and I'm not sure if I've finished replacing everything or not. It gets a bit confusing.

Anyway, I looked at the code, and it's a little bit hacky really: https://github.com/mawww/kakoune/blob/master/rc/tools/grep.kak#L57

I wonder if we could simply change the default to stop wrapping, and maybe echo some message like this is the last match.

Has anyone tried this? I would like to try overriding grep-next-match but I'm unsure how I can check for zero and branch in that code.

AndrewVos avatar May 25 '22 08:05 AndrewVos

define-command grep-next-match -docstring 'Jump to the next grep match' %{
    evaluate-commands -try-client %opt{jumpclient} %{
        buffer '*grep*'
        # First jump to end of buffer so that if grep_current_line == 0
        # 0g<a-l> will be a no-op and we'll jump to the first result.
        # Yeah, thats ugly...
        execute-keys "ge %opt{grep_current_line}g<a-l> /^[^:]+:\d+:<ret>"
        grep-jump
    }
    try %{
        evaluate-commands -client %opt{toolsclient} %{
            buffer '*grep*'
            execute-keys gg %opt{grep_current_line}g
        }
    }
}

AndrewVos avatar May 25 '22 08:05 AndrewVos