~ntgg/dotfiles

ref: 7c878992f39b164bb505fa5c0378aba89963f1ad dotfiles/.config/kak/kakrc -rw-r--r-- 5.8 KiB
7c878992 — Noah Graff added starship prompt config 2 years ago
                                                                                
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#   ___                              _    
#  / __|___ _ __  _ __  __ _ _ _  __| |___
# | (__/ _ \ '  \| '  \/ _` | ' \/ _` (_-<
#  \___\___/_|_|_|_|_|_\__,_|_||_\__,_/__/
#                                         

define-command filetype-hook -params 2 %{
    hook global WinSetOption "filetype=(%arg{1})" "%arg(2)"
}

define-command indent-spaces -params 1 %{
    expandtab
    set-option buffer indentwidth %arg(1)
    set-option buffer softtabstop %arg(1)
    set-option buffer tabstop %arg(1)
}

define-command indent-tabs -params 1 %{
    noexpandtab
    set-option buffer indentwidth %arg(1)
    set-option buffer softtabstop %arg(1)
    set-option buffer tabstop %arg(1)
}

define-command latex-preview %{
    evaluate-commands %sh{
        latex_outdir=$(mktemp -dp'/tmp' -d latex_outdir.XXXXX)

        # FIXME: the weird printf formatting
        printf 'hook -group latex-preview buffer BufWritePost %s %%{
            nop %%sh{
                (
                    cp -r %s %s.bak &&
                    pdflatex -output-directory %s %s ||
                    (rm -rf %s && mv %s.bak %s); \
                    rm -rf %s.bak
                ) > /dev/null 2>&1 < /dev/null &
            }
        }' \
        "${kak_buffile}" \
        "${latex_outdir}" "${latex_outdir}" \
        "${latex_outdir}" "${kak_buffile}" \
        "${latex_outdir}" "${latex_outdir}" "${latex_outdir}" \
        "${latex_outdir}"

        (
            pdflatex -output-directory "${latex_outdir}" "${kak_buffile}" &&
            xdg-open "${latex_outdir}/$(basename ${kak_buffile} .tex).pdf" &&
            rm -rf "${latex_outdir}" &&
            printf 'remove-hooks buffer latex-preview'
        ) > /dev/null 2>&1 < /dev/null &
    }
}

#  ___ _ _       ___              _  __ _    
# | __(_) |___  / __|_ __  ___ __(_)/ _(_)__ 
# | _|| | / -_) \__ \ '_ \/ -_) _| |  _| / _|
# |_| |_|_\___| |___/ .__/\___\__|_|_| |_\__|
#                   |_|                      

filetype-hook html|markdown|ocaml|gas|nim|latex %{ indent-spaces 2 }
filetype-hook zig|javascript|haskell|python|rust|kak|c|fish %{ indent-spaces 4 }
filetype-hook css %{ indent-tabs 4 }

hook global WinCreate ^[^*]+$ %{
    add-highlighter window/ number-lines -relative
    add-highlighter window/ show-whitespaces
    add-highlighter window/ show-matching
    add-highlighter window/ regex \b(TODO|FIXME|NOTE)\b 0:default+b
    auto-pairs-enable
}

filetype-hook rust %{
    set-option buffer formatcmd 'rustfmt'
}

filetype-hook c %{
    set-option buffer formatcmd "clang-format -style='WebKit'"
}

filetype-hook haskell %{
    set-option buffer lintcmd 'hlint'
}


filetype-hook latex %{
    set-option buffer autowrap_column 80
    autowrap-enable
}

filetype-hook markdown %{
    set-option buffer autowrap_column 80
    autowrap-enable
}


#  __  __                _              
# |  \/  |__ _ _ __ _ __(_)_ _  __ _ ___
# | |\/| / _` | '_ \ '_ \ | ' \/ _` (_-<
# |_|  |_\__,_| .__/ .__/_|_||_\__, /__/
#             |_|  |_|         |___/    

map global user 'c' ': comment-line<ret>' -docstring 'comment line'
map global user '<a-c>' ': comment-block<ret>' -docstring 'comment block'

# System clipboard
map global user 'y' '<a-|> wl-copy<ret>' -docstring 'copy to clipboard'
map global user 'p' '<a-!> wl-paste<ret>' -docstring 'insert content from clipboard'
map global user 'P' '! wl-paste<ret>' -docstring 'append content from clipboard'
map global user 'R' '| wl-paste<ret>' -docstring 'replace selection with content in clipboard'

#  __  __         _     _ _          
# |  \/  |___  __| |___| (_)_ _  ___ 
# | |\/| / _ \/ _` / -_) | | ' \/ -_)
# |_|  |_\___/\__,_\___|_|_|_||_\___|
#                                    

hook global WinCreate .* %{ evaluate-commands %sh{
    fmt_line='%val{cursor_line}:%val{cursor_char_column} %opt{filetype} %val{bufname} {{context_info}} {{mode_info}}'
    is_work_tree=$(cd "$(dirname "${kak_buffile}")" && git rev-parse --is-inside-work-tree 2>/dev/null)
    [ "${is_work_tree}" = 'true' ] && fmt_line=" %opt{modeline_git_branch} ${fmt_line}"
    printf 'set-option window modelinefmt %%{%s}' "${fmt_line}"
}}

#  ___ _           _         
# | _ \ |_  _ __ _(_)_ _  ___
# |  _/ | || / _` | | ' \(_-<
# |_| |_|\_,_\__, |_|_||_/__/
#            |___/           

source "%val{config}/plugins/plug.kak/rc/plug.kak"

plug "andreyorst/plug.kak" noload
plug "andreyorst/smarttab.kak"

plug "alexherbo2/auto-pairs.kak" config %{
    map global user 's' ': auto-pairs-surround <lt> <gt><ret>' -docstring 'Surround'
    filetype-hook markdown %{
        set-option -add buffer auto_pairs_surround _ _
    }
    filetype-hook latex|markdown %{
        set-option -add buffer auto_pairs_surround $ $
    }
    filetype-hook zig %{
        set-option -add buffer auto_pairs_surround | |
    }
}

plug "occivink/kakoune-snippets" config %{
    # unmap global insert '<c-i>'
    map global insert '<a-i>' '<a-;>: snippets-select-next-placeholders<ret>'
    filetype-hook rust %{
        set-option buffer snippets_auto_expand true
    }
}

plug "andreyorst/fzf.kak" config %{
    map global user 'f' ': fzf-mode<ret>' -docstring 'enter fzf mode'
    # NOTE maybe broken???
    # set-option global fzf_file_command 'rg'
    # set-option global fzf_highlight_cmd 'bat'
}

plug "ul/kak-lsp" do %{
    cargo build --release --locked
    cargo install --force --path .
} config %{
    define-command lsp-restart -docstring 'restart the language server' %{ lsp-stop; lsp-start }

    filetype-hook rust %{
        set-option buffer lsp_server_configuration rust.clippy_preference="on"
    }

    filetype-hook rust|python|c %{
        lsp-enable-window
        map window user 'l' ': enter-user-mode lsp<ret>' -docstring 'enter lsp mode'
        map window lsp 'R' ': lsp-rename-prompt<ret>' -docstring 'rename the symbol beneath the cursor'
    }

    hook global KakEnd .* lsp-exit
}


colorscheme gruvbox