about summary refs log tree commit diff
path: root/config/kak/compilation-mode.kak
blob: bdbb5e225a9f7eb156e8e434fe4d52539090d154 (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
# Requires kakpipe and unbuffer

declare-option -docstring "The last command ran in compilation-mode
"\
str compile_last_command ""

declare-option -docstring "How the compile buffer should be displayed
Options:
            'default': Create a new buffer in the current kakoune window
                'new': Create a new window via ':terminal'
      'tmux_vertical': Create a tmux vertical split
    'tmux_horizontal': Create a tmux horizontal split
         'tmux_popup': Create a tmux popup window
"\
str compile_run_mode "default"

define-command -hidden -params 1.. compile-exec %{
    evaluate-commands %sh{
        case "$kak_opt_compile_run_mode" in
            default)
                exec kakpipe fifo -s "$kak_session" -- unbuffer "$@"
                ;;
            new)
                printf 'terminal kak -e "set-option global compile_run_mode default; compile %s"\n' "$*"
                ;;
            tmux_vertical|tmux_horizontal|tmux_popup)
                if [ -z "$kak_client_env_TMUX" ]; then
                    echo 'fail "tmux is not running"'
                    exit
                fi
                case "$kak_opt_compile_run_mode" in
                    tmux_vertical)
                        tmux_args="split-window -t '${kak_client_env_TMUX_PANE}' -v"
                        ;;
                    tmux_horizontal)
                        tmux_args="split-window -t '${kak_client_env_TMUX_PANE}' -h"
                        ;;
                    tmux_popup)
                        tmux_args="popup -E -t '${kak_client_env_TMUX_PANE}'"
                        ;;
                esac
                printf "nop %%sh{ tmux %s kak -e 'set-option global compile_run_mode default; compile %s' }\n" "$tmux_args" "$*"
                ;;
        esac
    }
}

define-command -docstring "Compile: run a command in a fifo buffer" compile -params 1.. %{
    set-option global compile_last_command "%arg{@}"
    compile-exec %arg{@}
}

define-command -docstring "Recompile: re-run the last compile command" recompile %{
    evaluate-commands %sh{
        if [ -z "$kak_opt_compile_last_command" ]; then
            echo 'fail "No previous compile command"'
        else
            echo "compile-exec $kak_opt_compile_last_command"
        fi
    }
}