summaryrefslogtreecommitdiff
path: root/autoload/tools/jump.kak
blob: 60d777d4552c682db159f963487e7f8ff6224378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
declare-option -docstring "name of the client in which all source code jumps will be executed" \
    str jumpclient
declare-option -docstring "name of the client in which utilities display information" \
    str toolsclient

provide-module jump %{

declare-option -hidden int jump_current_line 0

define-command -hidden jump %{
    evaluate-commands -save-regs a %{ # use evaluate-commands to ensure jumps are collapsed
        try %{
            evaluate-commands -draft %{
                execute-keys ',xs^([^:\n]+):(\d+):(\d+)?<ret>'
                set-register a %reg{1} %reg{2} %reg{3}
            }
            set-option buffer jump_current_line %val{cursor_line}
            evaluate-commands -try-client %opt{jumpclient} -verbatim -- edit -existing -- %reg{a}
            try %{ focus %opt{jumpclient} }
        }
    }
}

define-command jump-next -params 1.. -docstring %{
    jump-next <bufname>: jump to next location listed in the given *grep*-like location list buffer.
} %{
    evaluate-commands -try-client %opt{jumpclient} -save-regs / %{
        buffer %arg{@}
        jump-select-next
        jump
    }
    try %{
        evaluate-commands -client %opt{toolsclient} %{
            buffer %arg{@}
            execute-keys gg %opt{jump_current_line}g
        }
    }
}
complete-command jump-next buffer
define-command -hidden jump-select-next %{
    # First jump to end of buffer so that if jump_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{jump_current_line}g<a-l> /^[^:\n]+:\d+:<ret>
}

define-command jump-previous -params 1.. -docstring %{
    jump-previous <bufname>: jump to previous location listed in the given *grep*-like location list buffer.
} %{
    evaluate-commands -try-client %opt{jumpclient} -save-regs / %{
        buffer %arg{@}
        jump-select-previous
        jump
    }
    try %{
        evaluate-commands -client %opt{toolsclient} %{
            buffer %arg{@}
            execute-keys gg %opt{jump_current_line}g
        }
    }
}
complete-command jump-previous buffer
define-command -hidden jump-select-previous %{
    # See comment in jump-select-next
    execute-keys ge %opt{jump_current_line}g<a-h> <a-/>^[^:\n]+:\d+:<ret>
}

}

hook -once global KakBegin .* %{ require-module jump }