z_mirror/dotfiles
git clone https://git.raiguard.me/z_mirror/dotfiles
bdd601b
trunk
1source "%val{config}/load.kak" 2 3# -------------------------------------------------- 4# PLUGINS 5 6source "%val{config}/bundle/kak-bundle/rc/kak-bundle.kak" 7bundle-noload kak-bundle https://codeberg.org/jdugan6240/kak-bundle 8 9# bundle auto-pairs.kak "https://github.com/alexherbo2/auto-pairs.kak" %{ 10# enable-auto-pairs 11# } 12 13bundle kak-ansi "https://github.com/eraserhd/kak-ansi" %{ 14 hook global BufSetOption filetype=make ansi-enable 15 hook global BufCreate \*frun\* ansi-enable 16} 17 18bundle kak-fastbuild "https://codeberg.org/raiguard/kak-fastbuild" 19 20bundle kak-harpoon "https://codeberg.org/raiguard/kak-harpoon" %{ 21 harpoon-add-bindings 22} 23 24bundle kak-mark "https://codeberg.org/raiguard/kak-mark" %{ 25 set-face global MarkedPrimaryCursor ,,magenta+ua 26 set-face global MarkedPrimarySelection ,,magenta+ua 27 set-face global MarkedSecondaryCursor ,,cyan+ua 28 set-face global MarkedSecondarySelection ,,cyan+ua 29} 30 31bundle kak-mirror "https://codeberg.org/raiguard/kak-mirror" %{ 32 map global normal = ':enter-user-mode -lock mirror<ret>' -docstring 'mirror lock' 33} 34 35bundle kak-move-lines "https://codeberg.org/raiguard/kak-move-lines" %{ 36 map global normal <c-a-j> ':move-lines-down %val{count}<ret>' 37 map global normal <c-a-k> ':move-lines-up %val{count}<ret>' 38} 39 40bundle kak-live-grep "https://codeberg.org/raiguard/kak-live-grep" %{ 41 map global user / ":live-grep<ret>" -docstring "live grep" 42 hook global User ColorschemeLoaded %{ 43 set-face global LiveGrepMatch ",,rgb:%opt{orange}+u" 44 } 45} 46 47bundle kak-lsp "https://github.com/kak-lsp/kak-lsp" %{ 48 set-option global lsp_auto_highlight_references true 49 set-option global lsp_hover_max_lines 1000 50 set-option global lsp_hover_anchor true 51 set-option global lsp_snippet_support false # This breaks my muscle memory 52 53 map global lsp m ":lsp-show-message-request-next<ret>" 54 55 map global normal "'" ":enter-user-mode lsp<ret>" 56 57 map global object a '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol' 58 map global object <a-a> '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol' 59 map global object f '<a-semicolon>lsp-object Function Method<ret>' -docstring 'LSP function or method' 60 map global object t '<a-semicolon>lsp-object Class Interface Struct<ret>' -docstring 'LSP class interface or struct' 61 map global object d '<a-semicolon>lsp-diagnostic-object --include-warnings<ret>' -docstring 'LSP errors and warnings' 62 map global object D '<a-semicolon>lsp-diagnostic-object<ret>' -docstring 'LSP errors' 63 64 lsp-inlay-diagnostics-enable global 65 lsp-auto-signature-help-enable 66 67 # Custom status line 68 declare-option -hidden str lsp_modeline_progress "" 69 define-command -hidden -params 6 -override lsp-handle-progress %{ 70 set-option global lsp_modeline_progress %sh{ 71 if ! "$6"; then 72 echo "$2${5:+" ($5%)"}${4:+": $4"}" 73 fi 74 } 75 } 76} 77bundle-install-hook kak-lsp %{ cargo install --force --path . } 78 79bundle kak-rainbower "https://github.com/crizan/kak-rainbower" %{ 80 set-option global rainbow_mode 0 81 set-option global rainbow_check_templates Y 82 83 hook global WinCreate .* %{ 84 rainbow-enable-window 85 } 86} 87 88bundle kak-replace-mode "https://codeberg.org/raiguard/kak-replace-mode" %{ 89 map global normal <a-r> ":enter-replace-mode<ret>" 90} 91 92bundle kakoune-focus "https://github.com/caksoylar/kakoune-focus" %{ 93 map global user <space> ':focus-toggle<ret>' -docstring "toggle selections focus" 94} 95 96bundle kakoune-gdb "https://github.com/occivink/kakoune-gdb" %{ 97 define-command tmux-gdb -params 1.. %{ 98 tmux-terminal-impl 'split-window -v -l 25%' %arg{@} 99 } 100 # define-command custom-gdb-session-connect %{ 101 # alias window terminal tmux-gdb 102 # gdb-session-connect 103 # unalias window terminal 104 # osc-yank "new-ui mi3 %opt{gdb_dir}/pty" 105 # gdb-enable-autojump 106 # } 107 # define-command -override -params .. custom-gdb-session-new %{ 108 # alias window terminal tmux-gdb 109 # gdb-session-new %arg{@} 110 # unalias window terminal 111 # gdb-enable-autojump 112 # trigger-user-hook GDBPostInit 113 # } 114 # map global normal <s-F5> ':prompt -menu -shell-script-candidates %{ fd --type f --hidden ".*" bin } file: %{ custom-gdb-session-new %val{text} }<ret>' -docstring "new GDB session" 115 # map global normal <s-F5> ":custom-gdb-session-connect<ret>" -docstring "connect to GDB session" 116 map global normal <F9> ":gdb-toggle-breakpoint<ret>" -docstring "GDB toggle breakpoint" 117 map global normal <F10> ":gdb-next<ret>" -docstring "GDB next" 118 map global normal <F11> ":gdb-step<ret>" -docstring "GDB step" 119 map global normal <F12> ":gdb-continue<ret>" -docstring "GDB continue" 120} 121 122bundle kakoune-grep-write "https://github.com/JacobTravers/kakoune-grep-write" %{ 123 hook global WinSetOption filetype=(grep|lsp-goto) %{ 124 alias buffer w grep-write 125 } 126} 127 128bundle kakoune-sort-selections "https://github.com/occivink/kakoune-sort-selections" 129 130bundle kakoune-state-save "https://gitlab.com/Screwtapello/kakoune-state-save" %{ 131 hook global KakBegin .* %{ 132 state-save-reg-load @ 133 } 134 hook global KakEnd .* %{ 135 state-save-reg-save @ 136 } 137} 138 139bundle grep-expand.kak "https://github.com/JacobTravers/grep-expand.kak" 140 141bundle smarttab.kak "https://github.com/andreyorst/smarttab.kak" %{ 142 hook global BufCreate .* %{ 143 expandtab 144 set-option buffer tabstop 4 145 set-option buffer softtabstop 4 146 set-option buffer indentwidth 4 147 } 148} 149 150bundle-theme kak-tokyo-night "https://codeberg.org/raiguard/kak-tokyo-night" 151 152bundle kak-search-highlight "https://codeberg.org/ficd/kak-search-highlight" %{ 153 require-module search-highlight 154 hook global User ColorschemeLoaded %{ 155 set-option global search_highlight_face ",,rgb:%opt{orange}+ua" 156 } 157 hook global WinCreate .* %{ 158 search-highlight-enable 159 } 160} 161 162bundle secure-local-kakrc "https://codeberg.org/ficd/secure-local-kakrc" %{ 163 require-module local-kakrc 164} 165 166# -------------------------------------------------- 167# GENERAL 168 169# Colorscheme 170colorscheme tokyo-night-night 171set-face global DiagnosticError default 172set-face global DiagnosticWarning default 173set-face global DiagnosticInfo default 174set-face global DiagnosticHint default 175set-face global InlayDiagnosticError "rgb:%opt{red}+d" 176set-face global InlayDiagnosticWarning "rgb:%opt{yellow}+d" 177set-face global InlayDiagnosticInfo "rgb:%opt{blue}+d" 178set-face global InlayDiagnosticHint +d@comment 179trigger-user-hook ColorschemeLoaded 180 181# General highlighters 182add-highlighter global/ number-lines -relative -separator " " -hlcursor 183add-highlighter global/ show-matching 184add-highlighter global/ line '%val{cursor_line}' SubBg 185add-highlighter global/ show-whitespaces -indent │ -tab "│" -tabpad " " -spc " " -lf " " -nbsp " " 186 187# UI settings 188set-option global ui_options terminal_assistant=off terminal_set_title=false terminal_info_max_width=100 terminal_info_inline_borders=true terminal_scroll_bar=true 189set-option global startup_info_version 10000000000000 # Don't show changelog 190set-option global scrolloff 5,5 191 192# Scroll bar 193set-face global ScrollBarGutter ",rgb:%opt{subbg}" 194set-face global ScrollBarHandle +r@Default 195 196# Auto-reload please 197set-option global autoreload yes 198 199# Use ripgrep instead of grep 200set-option global grepcmd 'rg -Hn --no-heading --sort path --vimgrep' 201 202# More lenient make errors 203set-option global make_error_pattern "^\h*(?:\w:)?([^:\n]+):(\d+):(?:(\d+):)? (?:fatal )?(?:(error|warning|info|hint|note):)?([^\n]+)?" 204 205# Conveniently edit config 206define-command edit-kakrc %{ e ~/.config/kak/kakrc } 207 208# Convenient wrap highlighter 209define-command addwrap %{ 210 add-highlighter window/wrap wrap -word -indent 211} 212 213# Remove trailing whitespace on save 214hook -group auto-trim-whitespace global BufWritePre .* %{ try %{ execute-keys -draft \%s\h+$<ret>d } } 215 216# Automatically parse modelines 217hook global BufOpenFile .* modeline-parse 218 219alias global terminal-floating terminal 220alias global terminal-overlay terminal 221 222# Add extra sway commands 223hook global ModuleLoaded wayland %{ 224 set-option global termcmd 'foot sh -c' 225} 226hook global ModuleLoaded sway %{ 227 define-command -params .. terminal-floating %{ 228 set-option window termcmd 'foot -a foot.floating sh -c' 229 terminal %arg{@} 230 unset-option window termcmd 231 } 232 define-command -params .. -command-completion splith %{ 233 nop %sh{ swaymsg splith } 234 new %arg{@} 235 } 236 define-command -params .. -command-completion splitv %{ 237 nop %sh{ swaymsg splitv } 238 new %arg{@} 239 } 240 alias global terminal-overlay terminal-floating 241} 242 243# Add extra tmux commands 244hook global ModuleLoaded tmux %{ 245 alias global terminal tmux-terminal-horizontal 246 define-command -params .. terminal-floating %{ 247 tmux-terminal-impl 'display-popup -E' %arg{@} 248 } 249 define-command -params .. terminal-overlay %{ 250 tmux-terminal-window %arg{@} 251 } 252 define-command splitv %{ 253 alias local terminal tmux-terminal-vertical 254 new 255 } 256 define-command splith %{ 257 alias local terminal tmux-terminal-horizontal 258 new 259 } 260} 261 262# -------------------------------------------------- 263# MAPPINGS 264 265# NORMAL 266 267# Comment 268map global normal "#" ":comment-line<ret>" 269map global normal "<a-#>" ":comment-block<ret>" 270 271# Go to file (basic fuzzy finder) 272map global user f '<esc>:prompt -shell-script-candidates %{ fd --type f } file: %{ edit %val{text} }<ret>' -docstring "file" 273 274# Go to buffer 275map global user b '<esc>:prompt -buffer-completion buffer: %{ buffer %val{text} }<ret>' -docstring "buffer" 276 277# Pick a file with NNN 278map global normal <minus> ':terminal-overlay "%val{config}/nnn-pick.sh" "%val{buffile}" "%val{client}" "%val{session}"<ret>' 279 280# Pipe the primary selection to a command and echo the output to the statusline 281map global normal <a-$> ':prompt -shell-completion echo-pipe: %{ echo %sh{ printf "%s" "$kak_selection" | $kak_text }}<ret>' 282 283# Search case-insensitive by default 284map global normal "/" "/(?i)" 285map global normal "?" "?(?i)" 286map global normal "<a-/>" "<a-/>(?i)" 287map global normal "<a-?>" "<a-?>(?i)" 288 289# Always select entire lines 290map global normal J "Jx" 291map global normal K "Kx" 292 293# Select inner line 294map global normal X x_ 295 296# Select all occurances of current selection in file 297map global normal "<a-*>" "*<percent>s<ret>" -docstring "Select all matching in file" 298 299map global normal <c-y> ":osc-yank<ret>" 300define-command -hidden osc-yank -params .. \ 301-docstring "yank argument or selections to terminal clipboard using OSC 52" %{ 302 nop %sh{ 303 if [ $# = 0 ]; then 304 eval set -- "$kak_quoted_selections" 305 fi 306 copy=$1 307 shift 308 for sel; do 309 copy=$(printf '%s\n%s' "$copy" "$sel") 310 done 311 encoded=$(printf %s "$copy" | base64 | tr -d '\n') 312 if [ -n "$TMUX" ]; then 313 printf "\e]52;c;%s\a" "$encoded" > "$(tmux display-message -p '#{client_tty}')" 314 else 315 printf "\e]52;c;%s\a" "$encoded" > "/proc/$kak_client_pid/fd/0" 316 fi 317 } 318} 319 320map global normal <F5> ':prompt -menu -shell-script-candidates %{ fd --type f --hidden ".*" bin } file: %{ terminal lldb %val{text} }<ret>' -docstring "new LLDB session" 321 322# Jumps centered please 323map global normal <c-o> <c-o>vv 324map global normal <c-i> <c-i>vv 325 326# INSERT 327 328# Delete words in insert mode 329map global insert <c-w> "<a-;>h<a-;>B<a-;>d" 330 331# USER 332 333map global user n ':new edit %val{bufname}<ret>' -docstring "new window" 334map global user d ':osc-yank "b %val{buffile}:%val{cursor_line}"<ret>' -docstring "lldb breakpoint" 335 336# Sort 337declare-user-mode sort 338map global user s ":enter-user-mode sort<ret>" -docstring "sort..." 339map global sort l "|sort<ret>" -docstring "lines" 340map global sort s "<esc>:sort-selections<ret>" -docstring "selections" 341map global sort c "<esc>|sort<ret>|sed -E -e 's/,?$/,/' -e '$s/,$//'<ret>" -docstring "comma-aware lines" 342 343# Toggle 344declare-user-mode toggle 345map global user t ":enter-user-mode toggle<ret>" -docstring "toggle..." 346map global toggle i ':show-tab-info<ret>' -docstring "tab settings" 347define-command show-tab-info %{ 348 info -title "tab settings" "tabstop: %opt{tabstop} 349softtabstop: %opt{softtabstop} 350indentwidth: %opt{indentwidth}" 351} 352map global toggle s ':show-session-info<ret>' -docstring "session info" 353define-command -hidden show-session-info %{ 354 info -title "session info" "%val{client}/%val{session} 355%sh{pwd}" 356} 357 358# Git 359declare-user-mode git 360map global user g ":enter-user-mode git<ret>" -docstring "git..." 361map global git b ":git blame<ret>" -docstring "blame" 362map global git d ":git diff<ret>" -docstring "diff" 363map global git g ":terminal-overlay lazygit -p %sh{echo $PWD}<ret>" -docstring "lazygit" 364map global git u ":terminal-overlay gitu<ret>" -docstring "gitu" 365map global git f ":git-file-history<ret>" -docstring "file history" 366map global git l ":git-line-history<ret>" -docstring "line history" 367define-command -hidden git-line-history %{ 368 git log "-L%val{cursor_line},+1:%val{buffile}" 369} 370define-command -hidden git-file-history %{ 371 git log "%val{buffile}" 372} 373map global git o ":git-open-on-github<ret>" -docstring "open on GitHub" 374define-command git-open-on-github %{ 375 nop %sh{ gh browse "$kak_bufname:$kak_cursor_line" & } 376} 377 378# Wrap paragraphs 379map global user w ":wrap-paragraph<ret>" -docstring "wrap paragraph" 380define-command wrap-paragraph %{ 381 execute-keys "<a-i>p<a-j>|fold -s -w %opt{autowrap_column}<ret>|sed 's/\s*$//g'<ret><esc>" 382} 383 384# IDE 385declare-user-mode ide 386map global user i ":enter-user-mode ide<ret>" -docstring "ide..." 387map global ide t ':set-option global toolsclient %val{client}<ret>' -docstring "set toolsclient" 388map global ide j ':set-option global jumpclient %val{client}<ret>' -docstring "set jumpclient" 389map global ide d ':set-option global docsclient %val{client}<ret>' -docstring "set docsclient" 390 391# Other 392map global user e ":edit -scratch<ret>" -docstring "scratch buffer" 393 394evaluate-commands %sh{ 395 if [ -f "justfile" ]; then 396 echo " 397 hook global ModuleLoaded make %{ 398 set-option global makecmd just 399 alias global just make 400 } 401 " 402 fi 403} 404 405# -------------------------------------------------- 406# FILETYPE HOOKS 407 408# Default window settings 409hook global BufCreate .* %{ 410 editorconfig-load 411 # Show and automatically update git diff on write 412 evaluate-commands %sh{ 413 branch=$(git -C "${kak_buffile%/*}" rev-parse --abbrev-ref HEAD 2>/dev/null) 414 if [ -n "$branch" ]; then 415 printf %s\\n " 416 git show-diff 417 hook buffer BufWritePost .* %{ git update-diff } 418 hook buffer BufReload .* %{ git update-diff } 419 " 420 fi 421 } 422} 423 424hook global BufSetOption filetype=(c|cpp) %{ 425 set-option buffer lsp_servers %{ 426 [clangd] 427 filetypes = ["c", "cpp"] 428 root_globs = ["compile_commands.json", ".clangd", ".git", ".hg"] 429 command = "clangd" 430 # args = ["--limit-references=0", "--header-insertion=never", "--pch-storage=memory"] 431 args = ["--limit-references=0", "--header-insertion=never"] 432 } 433 434 map buffer user a ":clangd-switch-source-header<ret>" 435} 436 437hook global WinSetOption filetype=(c|cpp) %{ 438 # Better highlighting 439 add-highlighter -override "shared/%opt{filetype}/code/operator" regex (\+|-|\*|&|=|\\|\?|%|\^|\|-|!|\||->|<|>|\^|/|~|\[|\]) 0:operator 440 add-highlighter -override "shared/%opt{filetype}/code/constant" regex \b([A-Z0-9_]*)\b 1:value 441 add-highlighter -override "shared/%opt{filetype}/code/functioncall" regex \b([a-zA-Z0-9_]*)\( 1:function 442 add-highlighter -override "shared/%opt{filetype}/code/illegal_operator" regex \b(and|or|not)\b 0:+r@operator 443 444 # Factorio doc comments 445 446 remove-highlighter "shared/%opt{filetype}/line_comment" 447 add-highlighter "shared/%opt{filetype}/line_comment" region //[^\?] (?<!\\)(?=\n) fill comment 448 449 require-module markdown 450 451 add-highlighter "shared/%opt{filetype}/factorio_documentation" region //\? (?<!\\)(?=\n) regions 452 add-highlighter "shared/%opt{filetype}/factorio_documentation/text" default-region group 453 add-highlighter "shared/%opt{filetype}/factorio_documentation/text/" fill comment 454 add-highlighter "shared/%opt{filetype}/factorio_documentation/text/" ref markdown 455 add-highlighter "shared/%opt{filetype}/factorio_documentation/text/comment_prefix" regex //\? 0:meta 456 add-highlighter "shared/%opt{filetype}/factorio_documentation/text/tag" regex \$[a-z_]+ 0:function 457 458 add-highlighter "shared/%opt{filetype}/factorio_documentation/tag" region -recurse \$[a-z_]+\( \$[a-z_]+\( \) group 459 add-highlighter "shared/%opt{filetype}/factorio_documentation/tag/variable" regex [a-zA-Z0-9_:\.-]+ 0:type 460 add-highlighter "shared/%opt{filetype}/factorio_documentation/tag/tag" regex \$[a-z_]+ 0:function 461 add-highlighter "shared/%opt{filetype}/factorio_documentation/tag/property" regex (\$(|param|return|raises|subclass|property))\( 1:keyword 462 add-highlighter "shared/%opt{filetype}/factorio_documentation/tag/value" regex \b(\d+|true|false)\b 1:value 463 add-highlighter "shared/%opt{filetype}/factorio_documentation/tag/string" regex '".*?"' 0:string 464} 465# GNU STL has a really stupid indentation format 466hook global BufCreate /usr/include/c\+\+/.* %{ 467 set-option buffer tabstop 8 468 set-option buffer softabstop 4 469 set-option buffer indentwidth 4 470} 471 472hook global BufCreate ".*changelog\.txt$" %{ 473 try %{ 474 execute-keys -draft ggxs---------------------------------------------------------------------------------------------------<ret> 475 set-option buffer filetype factorio-changelog 476 } 477} 478hook global BufSetOption filetype=factorio-changelog %{ 479 add-highlighter buffer/changelog_date regex ^(Date):\s(.*?)$ 1:type 2:function 480 add-highlighter buffer/changelog_entry regex ^(\s\s)*(-)\s(.*?)$ 2:value 3:string 481 add-highlighter buffer/changelog_section regex "^\s*(Balancing|Bugfixes|Changes|Circuit Network|Combat Balancing|Compatibility|Control|Debug|Ease Of Use|Features|Graphics|Gui|Info|Locale|Major Features|Minor Features|Modding|Optimizations|Other|Scripting|Sounds|Translation):" 1:type 482 add-highlighter buffer/changelog_separator regex ^-+$ 0:keyword 483 add-highlighter buffer/changelog_version regex ^(Version):\s(\d+\.\d+\.\d+)$ 1:type 2:value 484} 485 486hook global BufCreate (.*locale/.*/.*\.cfg) %{ 487 set-option buffer filetype factorio-locale 488} 489hook global BufSetOption filetype=factorio-locale %{ 490 require-module conf 491 add-highlighter buffer/conf ref conf 492 add-highlighter buffer/locale_macro regex __[^\n]*?__ 0:meta 493 add-highlighter buffer/locale_rich_text regex \[(achievement|armor|color|entity|fluid|font|gps|item|item-group|recipe|special-item|technology|tile|tooltip|train|train-stop|virtual-signal)=.*?\] 0:function 494 add-highlighter buffer/locale_rich_text_close regex \[/(achievement|armor|color|entity|fluid|font|gps|item|item-group|recipe|special-item|technology|tile|tooltip|train|train-stop|virtual-signal)\] 0:function 495} 496 497hook global BufSetOption filetype=(git-commit|mail) %{ 498 set-option buffer autowrap_column 72 499 set-option buffer autowrap_format_paragraph true 500 autowrap-enable 501} 502 503hook global BufCreate .*[.](glsl|vert|tesc|tese|geom|frag|comp) %{ 504 set-option buffer filetype glsl 505} 506 507hook global BufSetOption filetype=glsl %{ 508 add-highlighter buffer/glsl regions 509 add-highlighter buffer/glsl/code default-region group 510 add-highlighter buffer/glsl/line_comment region '//' $ fill comment 511 add-highlighter buffer/glsl/comment region '/\*' '\*/' fill comment 512 add-highlighter buffer/glsl/code/operator regex (\+|-|\*|&|=|\\|\?|%|\^|\|-|!|\||->|<|>|\^|/|~|\[|\]) 0:operator 513 add-highlighter buffer/glsl/code/function_call regex \b([a-zA-Z0-9_]*)\h*\( 1:function 514 add-highlighter buffer/glsl/code/constant regex \b([A-Z0-9_]*)\b 1:value 515 add-highlighter buffer/glsl/code/types regex \b(void|bool|int|uint|float|double|(b|i|u|d)?vec(2|3|4)|mat(2|3|4)|mat(2|3|4)x(2|3|4)|sampler(1|2|3)D)\b 1:type 516 add-highlighter buffer/glsl/code/keyword regex \b(out|in|uniform|layout|if|else|for|struct|return)\b 1:keyword 517 add-highlighter buffer/glsl/code/macro regex (#version) 1:meta 518 add-highlighter buffer/glsl/code/export regex \b(gl_Position)\b 1:string 519} 520 521hook global BufSetOption filetype=go %{ 522 noexpandtab 523 set-option buffer indentwidth 0 524 set-option buffer tabstop 4 525 set-option buffer softtabstop 4 526 527 hook buffer BufWritePre .* lsp-formatting-sync 528 529 map buffer user a :go-alternative-file<ret> -docstring "alternative file" 530} 531 532hook global BufSetOption filetype=hare %{ 533 noexpandtab 534 set-option buffer tabstop 8 535 set-option buffer softtabstop 0 536 set-option buffer indentwidth 0 537} 538 539hook global BufSetOption filetype=java %{ 540 set-option buffer tabstop 4 541 set-option buffer softtabstop 4 542 set-option buffer indentwidth 4 543 544 hook global BufWritePre .*\.java lsp-formatting-sync 545 546 add-highlighter -override shared/java/code/operator regex (=|==|&&|\|\||\+|-|/|\*|\+=|-=|\*=|/=|!|<=|>=|<|>) 1:operator 547} 548 549hook global BufSetOption filetype=json %{ 550 set-option buffer formatcmd 'jq .' 551} 552 553hook global BufSetOption filetype=lua %{ 554 set-option buffer lsp_servers %exp{ 555 # [luapls] 556 # filetypes = ["lua"] 557 # root_globs = [".git/", ".luarc.json", ".editorconfig", ".kakrc"] 558 # command = "/home/rai/dev/personal/luapls/luapls" 559 # args = ["lsp", "3"] 560 # settings_section = "luapls" 561 562 # [luapls.settings.luapls] 563 # roots = ["demo.lua"] 564 565 [emmylua_ls] 566 filetypes = ["lua"] 567 root_globs = [".git/", ".luarc.json", ".editorconfig", ".kakrc"] 568 command = "emmylua_ls" 569 570 # [luals] 571 # filetypes = ["lua"] 572 # root_globs = [".git/", ".luarc.json", ".editorconfig", ".kakrc"] 573 # command = "/home/rai/.local/opt/lua-language-server/bin/lua-language-server" 574 # args = ["--logpath=/home/rai/.local/state/lua-language-server/log"] 575 576 # [luals.settings.Lua] 577 # diagnostics.disable = ["lowercase-global"] 578 # diagnostics.severity = { unused-local = "Error", undefined-global = "Error", undefined-field = "Error" } 579 # hover.expandAlias = false 580 # hover.previewFields = 0 581 # semantic.enable = false 582 # telemetry.enable = false 583 # workspace.userThirdParty = ["/home/rai/dev/luals"] 584 585 # [fmtk-locale] 586 # filetypes = ["factorio-locale", "lua"] 587 # root_globs = ["info.json"] 588 # command = "fmtk" 589 # args = ["lsp", "--stdio"] 590 591 # [fmtk-changelog] 592 # filetypes = ["factorio-changelog", "lua"] 593 # root_globs = ["info.json"] 594 # command = "fmtk" 595 # args = ["lsp", "--stdio"] 596 } 597 598 set-option buffer formatcmd "stylua -" 599 # Only auto-format if it is our own Factorio project 600 evaluate-commands %sh{ 601 if [ -f "info.json" ] && [ $(jq -r ".author" < info.json) = "raiguard" ]; then 602 echo "hook buffer BufWritePre .* format" 603 fi 604 } 605} 606 607hook global WinSetOption filetype=lua %{ 608 # Highlight EmmyLua annotations 609 add-highlighter window/emmylua_direct regex "---\s*(@(?:alias|as|class|enum|generic|return|type|overload))\s+([^\n]*)" 1:attribute 2:type 610 add-highlighter window/emmylua_labeled regex "---\s*(@(?:alias|cast|field|param))\s+([a-zA-Z0-9_\?]*) ([^\n]*)" 1:attribute 2:variable 3:type 611 add-highlighter window/emmylua_enum_variant regex '---\s*\|\s*("[^\n]*")' 1:string 612 613} 614 615hook global WinSetOption filetype=makefile %{ 616 noexpandtab 617 set-option window indentwidth 0 618} 619 620hook global WinSetOption filetype=odin %{ 621 noexpandtab 622 # Better highlighting 623 add-highlighter -override "shared/odin/code/operator" regex (\+|-|\*|&|=|\\|\?|%|\^|\|-|!|\||->|<|>|\^|/|~|\[|\]|:=) 0:operator 624 add-highlighter -override "shared/odin/code/constant" regex \b([A-Z0-9_]*)\b 1:value 625 add-highlighter -override "shared/odin/code/functioncall" regex \b([a-zA-Z0-9_]*)\( 1:function 626} 627 628hook global WinSetOption filetype=python %{ 629 set-option window tabstop 4 630 set-option window softtabstop 4 631 set-option window indentwidth 4 632 633 set-option window formatcmd "autopep8 -" 634 635 add-highlighter -override shared/python/code/functioncall regex '\b([a-zA-Z0-9_]*)\h*\(' 1:function 636} 637 638hook global WinSetOption filetype=rust %{ 639 lsp-inlay-hints-enable window 640 641 set-option window tabstop 4 642 set-option window softtabstop 4 643 set-option window indentwidth 4 644 645 # hook window BufWritePre .* lsp-formatting-sync 646} 647 648# TODO: Create a kak plugin for this filetype 649hook global BufCreate .+\.scd %{ 650 set-option buffer filetype scdoc 651} 652hook global WinSetOption filetype=scdoc %{ 653 noexpandtab 654 655 set-option window autowrap_format_paragraph true 656 autowrap-enable 657 658 add-highlighter window/scdoc_header regex "^##?\s*.*?$" 0:+b 659 add-highlighter window/scdoc_bold regex "\*.*?\*" 0:+b 660 add-highlighter window/scdoc_underline regex "\b_.*?_\b" 0:+u 661} 662 663hook global WinSetOption filetype=zig %{ 664 set-option window tabstop 4 665 set-option window softtabstop 4 666 set-option window indentwidth 4 667} 668hook global ModuleLoaded zig %{ 669 add-highlighter shared/zig/code/function_call regex \b([a-zA-Z0-9]+)\( 1:function 670 add-highlighter shared/zig/code/builtin_function regex (@[a-zA-Z0-9]+)\( 1:builtin 671} 672 673hook global WinCreate '/tmp/\.nnn.*' %{ 674 hook -once window WinDisplay .* %{ 675 execute-keys '%<a-s><a-s-k>^#<ret><a-;>;' 676 add-highlighter window/nnn_sources regex '^#.*?\n' 0:+d@comment 677 } 678} 679 680# -------------------------------------------------- 681# TODO Mode 682 683# Highlight TODO and other related comment tags 684hook global WinSetOption comment_line=(.*) %{ 685 add-highlighter -override window/todo regex "\Q%val{hook_param_capture_1}\E\h*(TODO(?: (raiguard|branch))?:)[^\n]*" 1:string 686 add-highlighter -override window/fixme regex "\Q%val{hook_param_capture_1}\E\h*((?:FIXME|XXX)(?: (raiguard|branch))?:)[^\n]*" 1:Error 687} 688map global toggle t ":grep '(BUG|FIXME|TODO|TEMPORARY):'<ret>" -docstring "TODOs" 689 690# -------------------------------------------------- 691# MODELINE 692 693# Git branch 694declare-option -hidden str modeline_git_branch 695hook global WinDisplay .* %{ 696 set-option window modeline_git_branch %sh{ 697 branch=$(git -C "${kak_buffile%/*}" rev-parse --abbrev-ref HEAD 2>/dev/null) 698 if [ -n "$branch" ]; then 699 printf "$branch " 700 fi 701 } 702} 703 704set-option global modelinefmt '{keyword}%opt{lsp_modeline_breadcrumbs}%opt{lsp_modeline_code_actions}%opt{lsp_modeline_progress}%opt{lsp_modeline_message_requests} {StatusLine}{string}%opt{modeline_git_branch}{type}%sh{ [ -n "$kak_opt_filetype" ] && echo "$kak_opt_filetype " }{default}%val{bufname}{{context_info}}{default} {{mode_info}} {meta}%val{cursor_line}:%val{cursor_char_column}' 705 706# -------------------------------------------------- 707# OTHER 708 709# Enable LSP 710# This has to be after filetype hooks in order to load those filetypes' LSP configurations. 711lsp-enable 712 713# Wrapper commands 714define-command -params .. -docstring "fmm [<arguments>]: fmm utility wrapper" fmm %{ 715 fifo -name *fmm* -scroll -- fmm %arg{@} 716 set-option buffer filetype make 717 set-option buffer jump_current_line 0 718} 719define-command -params .. -docstring "frun [<arguments>]: frun utility wrapper" frun %{ 720 fifo -name *frun* -scroll -- frun %arg{@} 721 set-option buffer filetype grep 722 set-option buffer jump_current_line 0 723} 724 725# Quickly test faces 726declare-option range-specs test_ranges 727define-command add-test-face -params 1 %{ 728 set-option -add window test_ranges "%val{selection_desc}|%arg{1}" 729 add-highlighter -override window/test_ranges ranges test_ranges 730} 731alias global tface add-test-face 732 733define-command run-selected-commands %{ 734 evaluate-commands -itersel -draft %exp{ %val{selection} } 735} 736 737source "%val{config}/delete-all-buffers.kak" 738source "%val{config}/detect-indentation.kak" 739source "%val{config}/jump-stack.kak" 740 741hook global BufOpenFile ".*" %{ 742 detect-indent-style 743} 744 745local-kakrc-load-if-trusted 746 747loadg filetypes *