jump.kak (2328B)
1 declare-option -docstring "name of the client in which all source code jumps will be executed" \ 2 str jumpclient 3 declare-option -docstring "name of the client in which utilities display information" \ 4 str toolsclient 5 6 provide-module jump %{ 7 8 declare-option -hidden int jump_current_line 0 9 10 define-command -hidden jump %{ 11 evaluate-commands -save-regs a %{ # use evaluate-commands to ensure jumps are collapsed 12 try %{ 13 evaluate-commands -draft %{ 14 execute-keys ',xs^([^:\n]+):(\d+):(\d+)?<ret>' 15 set-register a %reg{1} %reg{2} %reg{3} 16 } 17 set-option buffer jump_current_line %val{cursor_line} 18 evaluate-commands -try-client %opt{jumpclient} -verbatim -- edit -existing -- %reg{a} 19 try %{ focus %opt{jumpclient} } 20 } 21 } 22 } 23 24 define-command jump-next -params 1.. -docstring %{ 25 jump-next <bufname>: jump to next location listed in the given *grep*-like location list buffer. 26 } %{ 27 evaluate-commands -try-client %opt{jumpclient} -save-regs / %{ 28 buffer %arg{@} 29 jump-select-next 30 jump 31 } 32 try %{ 33 evaluate-commands -client %opt{toolsclient} %{ 34 buffer %arg{@} 35 execute-keys gg %opt{jump_current_line}g 36 } 37 } 38 } 39 complete-command jump-next buffer 40 define-command -hidden jump-select-next %{ 41 # First jump to end of buffer so that if jump_current_line == 0 42 # 0g<a-l> will be a no-op and we'll jump to the first result. 43 # Yeah, thats ugly... 44 execute-keys ge %opt{jump_current_line}g<a-l> /^[^:\n]+:\d+:<ret> 45 } 46 47 define-command jump-previous -params 1.. -docstring %{ 48 jump-previous <bufname>: jump to previous location listed in the given *grep*-like location list buffer. 49 } %{ 50 evaluate-commands -try-client %opt{jumpclient} -save-regs / %{ 51 buffer %arg{@} 52 jump-select-previous 53 jump 54 } 55 try %{ 56 evaluate-commands -client %opt{toolsclient} %{ 57 buffer %arg{@} 58 execute-keys gg %opt{jump_current_line}g 59 } 60 } 61 } 62 complete-command jump-previous buffer 63 define-command -hidden jump-select-previous %{ 64 # See comment in jump-select-next 65 execute-keys ge %opt{jump_current_line}g<a-h> <a-/>^[^:\n]+:\d+:<ret> 66 } 67 68 } 69 70 hook -once global KakBegin .* %{ require-module jump }