z_mirror/kak-live-grep
git clone https://git.raiguard.me/z_mirror/kak-live-grep
58f6e59
trunk
1declare-option -hidden bool live_grep_select_matches false 2declare-option int live_grep_timeout 300 3declare-option int live_grep_results_limit 10000 4 5set-face global LiveGrepMatch default+bu 6 7define-command -params ..1 -docstring "live-grep [init]: start a live grep in the *grep* buffer" live-grep %{ 8 try %{ focus %opt{toolsclient} } 9 evaluate-commands -try-client %opt{toolsclient} %{ 10 edit -scratch *grep* 11 set-option buffer filetype grep 12 try %{ 13 set-option buffer jump_current_line 0 14 } catch %{ 15 set-option buffer grep_current_line 0 16 } 17 set-option window idle_timeout %opt{live_grep_timeout} 18 prompt -init %arg{1} -on-change %{ 19 evaluate-commands -save-regs '"' %{ 20 set-register '"' %sh{ 21 if [ -z "$kak_quoted_text" ]; then 22 exit 23 fi 24 result=$($kak_opt_grepcmd "$kak_quoted_text" < /dev/null | tr -d '\r' | head -n $kak_opt_live_grep_results_limit) 25 echo "$result" 26 } 27 execute-keys '<a-;>%<a-;>"_d<a-;>P<a-;>gg' 28 } 29 try %{ 30 add-highlighter -override window/grep/live_grep_match regex "%val{text}" 0:LiveGrepMatch 31 } 32 } -on-abort %{ 33 remove-hooks window LiveGrepPrompt 34 remove-highlighter window/grep/live_grep_match 35 unset-option window idle_timeout 36 } live-grep: %{ 37 remove-hooks window LiveGrepPrompt 38 evaluate-commands -save-regs / %sh{ 39 if [ $kak_opt_live_grep_select_matches = true ]; then 40 query=$(echo "$kak_quoted_text" | sed "s/'/''/g") 41 printf %s\\n "try %§ 42 execute-keys '%<a-s>s[^:]*:[^:]*:([^:]*:)?<ret>l<a-l>' 43 set-register / '$query' 44 execute-keys 's<ret>)' 45 set-option window live_grep_select_matches false 46 §" 47 fi 48 } 49 unset-option window idle_timeout 50 } 51 hook -group LiveGrepPrompt window RawKey <a-ret> %{ 52 set-option window live_grep_select_matches true 53 remove-highlighter window/grep/live_grep_match 54 execute-keys -with-hooks <ret> 55 } 56 } 57}