z_mirror/dotfiles

git clone https://git.raiguard.me/z_mirror/dotfiles

Caleb Heuerkak: More tangere tweaksa38ff8b

tangere
26.8 KiB757 linesraw
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
9bundle 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
79# bundle 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 kak-search-highlight "https://codeberg.org/ficd/kak-search-highlight" %{
151    require-module search-highlight
152    hook global User ColorschemeLoaded %{
153        set-option global search_highlight_face ",,yellow+u"
154    }
155    hook global WinCreate .* %{
156        search-highlight-enable
157    }
158}
159
160bundle secure-local-kakrc "https://codeberg.org/ficd/secure-local-kakrc" %{
161  require-module local-kakrc
162}
163
164bundle-theme tangere "https://github.com/ftonneau/tangere-terminal"
165
166# --------------------------------------------------
167# GENERAL
168
169# Colorscheme
170colorscheme tangere-17-dark
171set-face global Reference +bu
172set-face global Whitespace +d@comment
173set-face global operator magenta
174set-face global attribute blue
175set-face global meta blue
176# Infobox faces
177set-face global InfoDefault Information
178set-face global InfoBlock block
179set-face global InfoBlockQuote block
180set-face global InfoBullet bullet
181set-face global InfoHeader header
182set-face global InfoLink link
183set-face global InfoLinkMono header
184set-face global InfoMono mono
185set-face global InfoRule comment
186set-face global InfoDiagnosticError InlayDiagnosticError
187set-face global InfoDiagnosticHint InlayDiagnosticHint
188set-face global InfoDiagnosticInformation InlayDiagnosticInfo
189set-face global InfoDiagnosticWarning InlayDiagnosticWarning
190trigger-user-hook ColorschemeLoaded
191
192# General highlighters
193add-highlighter global/ number-lines -relative -separator " " -hlcursor
194add-highlighter global/ show-matching
195add-highlighter global/ line '%val{cursor_line}' SubBg
196add-highlighter global/ show-whitespaces -indent │ -tab "│" -tabpad " " -spc " " -lf " " -nbsp " "
197
198# UI settings
199set-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
200set-option global startup_info_version 10000000000000 # Don't show changelog
201set-option global scrolloff 5,5
202
203# Scroll bar
204set-face global ScrollBarGutter default,bright-white
205set-face global ScrollBarHandle +r
206
207# Auto-reload please
208set-option global autoreload yes
209
210# Use ripgrep instead of grep
211set-option global grepcmd 'rg -Hn --no-heading --sort path --vimgrep'
212
213# More lenient make errors
214set-option global make_error_pattern "^\h*(?:\w:)?([^:\n]+):(\d+):(?:(\d+):)? (?:fatal )?(?:(error|warning|info|hint|note):)?([^\n]+)?"
215
216# Conveniently edit config
217define-command edit-kakrc %{ e ~/.config/kak/kakrc }
218
219# Convenient wrap highlighter
220define-command addwrap %{
221  add-highlighter window/wrap wrap -word -indent
222}
223
224# Remove trailing whitespace on save
225hook -group auto-trim-whitespace global BufWritePre .* %{ try %{ execute-keys -draft \%s\h+$<ret>d } }
226
227# Automatically parse modelines
228hook global BufOpenFile .* modeline-parse
229
230alias global terminal-floating terminal
231alias global terminal-overlay terminal
232
233# Add extra sway commands
234hook global ModuleLoaded wayland %{
235  set-option global termcmd 'foot sh -c'
236}
237hook global ModuleLoaded sway %{
238  define-command -params .. terminal-floating %{
239    set-option window termcmd 'foot -a foot.floating sh -c'
240    terminal %arg{@}
241    unset-option window termcmd
242  }
243  define-command -params .. -command-completion splith %{
244    nop %sh{ swaymsg splith }
245    new %arg{@}
246  }
247  define-command -params .. -command-completion splitv %{
248    nop %sh{ swaymsg splitv }
249    new %arg{@}
250  }
251  alias global terminal-overlay terminal-floating
252}
253
254# Add extra tmux commands
255hook global ModuleLoaded tmux %{
256  alias global terminal tmux-terminal-horizontal
257  define-command -params .. terminal-floating %{
258    tmux-terminal-impl 'display-popup -E' %arg{@}
259  }
260  define-command -params .. terminal-overlay %{
261    tmux-terminal-window %arg{@}
262  }
263  define-command splitv %{
264    alias local terminal tmux-terminal-vertical
265    new
266  }
267  define-command splith %{
268    alias local terminal tmux-terminal-horizontal
269    new
270  }
271}
272
273# --------------------------------------------------
274# MAPPINGS
275
276# NORMAL
277
278# Comment
279map global normal "#" ":comment-line<ret>"
280map global normal "<a-#>" ":comment-block<ret>"
281
282# Go to file (basic fuzzy finder)
283map global user f '<esc>:prompt -shell-script-candidates %{ fd --type f } file: %{ edit %val{text} }<ret>' -docstring "file"
284
285# Go to buffer
286map global user b '<esc>:prompt -buffer-completion buffer: %{ buffer %val{text} }<ret>' -docstring "buffer"
287
288# Pick a file with NNN
289map global normal <minus> ':terminal-overlay "%val{config}/nnn-pick.sh" "%val{buffile}" "%val{client}" "%val{session}"<ret>'
290
291# Pipe the primary selection to a command and echo the output to the statusline
292map global normal <a-$> ':prompt -shell-completion echo-pipe: %{ echo %sh{ printf "%s" "$kak_selection" | $kak_text }}<ret>'
293
294# Search case-insensitive by default
295map global normal "/" "/(?i)"
296map global normal "?" "?(?i)"
297map global normal "<a-/>" "<a-/>(?i)"
298map global normal "<a-?>" "<a-?>(?i)"
299
300# Always select entire lines
301map global normal J "Jx"
302map global normal K "Kx"
303
304# Select inner line
305map global normal X x_
306
307# Select all occurances of current selection in file
308map global normal "<a-*>" "*<percent>s<ret>" -docstring "Select all matching in file"
309
310map global normal <c-y> ":osc-yank<ret>"
311define-command -hidden osc-yank -params .. \
312-docstring "yank argument or selections to terminal clipboard using OSC 52" %{
313  nop %sh{
314    if [ $# = 0 ]; then
315      eval set -- "$kak_quoted_selections"
316    fi
317    copy=$1
318    shift
319    for sel; do
320      copy=$(printf '%s\n%s' "$copy" "$sel")
321    done
322    encoded=$(printf %s "$copy" | base64 | tr -d '\n')
323    if [ -n "$TMUX" ]; then
324      printf "\e]52;c;%s\a" "$encoded" > "$(tmux display-message -p '#{client_tty}')"
325    else
326      printf "\e]52;c;%s\a" "$encoded" > "/proc/$kak_client_pid/fd/0"
327    fi
328  }
329}
330
331map global normal <F5> ':prompt -menu -shell-script-candidates %{ fd --type f --hidden ".*" bin } file: %{ terminal lldb %val{text} }<ret>' -docstring "new LLDB session"
332
333# Jumps centered please
334map global normal <c-o> <c-o>vv
335map global normal <c-i> <c-i>vv
336
337# INSERT
338
339# Delete words in insert mode
340map global insert <c-w> "<a-;>h<a-;>B<a-;>d"
341
342# USER
343
344map global user n ':new edit %val{bufname}<ret>' -docstring "new window"
345map global user d ':osc-yank "b %val{buffile}:%val{cursor_line}"<ret>' -docstring "lldb breakpoint"
346
347# Sort
348declare-user-mode sort
349map global user s ":enter-user-mode sort<ret>" -docstring "sort..."
350map global sort l "|sort<ret>" -docstring "lines"
351map global sort s "<esc>:sort-selections<ret>" -docstring "selections"
352map global sort c "<esc>|sort<ret>|sed -E -e 's/,?$/,/' -e '$s/,$//'<ret>" -docstring "comma-aware lines"
353
354# Toggle
355declare-user-mode toggle
356map global user t ":enter-user-mode toggle<ret>" -docstring "toggle..."
357map global toggle i ':show-tab-info<ret>' -docstring "tab settings"
358define-command show-tab-info %{
359  info -title "tab settings" "tabstop: %opt{tabstop}
360softtabstop: %opt{softtabstop}
361indentwidth: %opt{indentwidth}"
362}
363map global toggle s ':show-session-info<ret>' -docstring "session info"
364define-command -hidden show-session-info %{
365  info -title "session info" "%val{client}/%val{session}
366%sh{pwd}"
367}
368
369# Git
370declare-user-mode git
371map global user g ":enter-user-mode git<ret>" -docstring "git..."
372map global git b ":git blame<ret>" -docstring "blame"
373map global git d ":git diff<ret>" -docstring "diff"
374map global git g ":terminal-overlay lazygit -p %sh{echo $PWD}<ret>" -docstring "lazygit"
375map global git u ":terminal-overlay gitu<ret>" -docstring "gitu"
376map global git f ":git-file-history<ret>" -docstring "file history"
377map global git l ":git-line-history<ret>" -docstring "line history"
378define-command -hidden git-line-history %{
379  git log "-L%val{cursor_line},+1:%val{buffile}"
380}
381define-command -hidden git-file-history %{
382  git log "%val{buffile}"
383}
384map global git o ":git-open-on-github<ret>" -docstring "open on GitHub"
385define-command git-open-on-github %{
386  nop %sh{ gh browse "$kak_bufname:$kak_cursor_line" & }
387}
388
389# Wrap paragraphs
390map global user w ":wrap-paragraph<ret>" -docstring "wrap paragraph"
391define-command wrap-paragraph %{
392  execute-keys "<a-i>p<a-j>|fold -s -w %opt{autowrap_column}<ret>|sed 's/\s*$//g'<ret><esc>"
393}
394
395# IDE
396declare-user-mode ide
397map global user i ":enter-user-mode ide<ret>" -docstring "ide..."
398map global ide t ':set-option global toolsclient %val{client}<ret>' -docstring "set toolsclient"
399map global ide j ':set-option global jumpclient %val{client}<ret>' -docstring "set jumpclient"
400map global ide d ':set-option global docsclient %val{client}<ret>' -docstring "set docsclient"
401
402# Other
403map global user e ":edit -scratch<ret>" -docstring "scratch buffer"
404
405evaluate-commands %sh{
406  if [ -f "justfile" ]; then
407    echo "
408      hook global ModuleLoaded make %{
409        set-option global makecmd just
410        alias global just make
411      }
412    "
413  fi
414}
415
416# --------------------------------------------------
417# FILETYPE HOOKS
418
419# Default window settings
420hook global BufCreate .* %{
421  editorconfig-load
422  # Show and automatically update git diff on write
423  evaluate-commands %sh{
424    branch=$(git -C "${kak_buffile%/*}" rev-parse --abbrev-ref HEAD 2>/dev/null)
425    if [ -n "$branch" ]; then
426      printf %s\\n "
427        git show-diff
428        hook buffer BufWritePost .* %{ git update-diff }
429        hook buffer BufReload .* %{ git update-diff }
430      "
431    fi
432  }
433}
434
435hook global BufSetOption filetype=(c|cpp) %{
436  set-option buffer lsp_servers %{
437    [clangd]
438    filetypes = ["c", "cpp"]
439    root_globs = ["compile_commands.json", ".clangd", ".git", ".hg"]
440    command = "clangd"
441    args = ["--limit-references=0", "--header-insertion=never", "--pch-storage=memory"]
442  }
443
444  map buffer user a ":clangd-switch-source-header<ret>"
445}
446
447hook global WinSetOption filetype=(c|cpp) %{
448  # Better highlighting
449  add-highlighter -override "shared/%opt{filetype}/code/operator" regex (\+|-|\*|&|=|\\|\?|%|\^|\|-|!|\||->|<|>|\^|/|~|\[|\]) 0:operator
450  add-highlighter -override "shared/%opt{filetype}/code/constant" regex \b([A-Z0-9_]*)\b 1:value
451  add-highlighter -override "shared/%opt{filetype}/code/functioncall" regex \b([a-zA-Z0-9_]*)\( 1:function
452  add-highlighter -override "shared/%opt{filetype}/code/illegal_operator" regex \b(and|or|not)\b 0:+r@operator
453
454  # Factorio doc comments
455
456  remove-highlighter "shared/%opt{filetype}/line_comment"
457  add-highlighter "shared/%opt{filetype}/line_comment" region //[^\?] (?<!\\)(?=\n) fill comment
458
459  require-module markdown
460
461  add-highlighter "shared/%opt{filetype}/factorio_documentation" region //\? (?<!\\)(?=\n) regions
462  add-highlighter "shared/%opt{filetype}/factorio_documentation/text" default-region group
463  add-highlighter "shared/%opt{filetype}/factorio_documentation/text/" fill comment
464  add-highlighter "shared/%opt{filetype}/factorio_documentation/text/" ref markdown
465  add-highlighter "shared/%opt{filetype}/factorio_documentation/text/comment_prefix" regex //\? 0:meta
466  add-highlighter "shared/%opt{filetype}/factorio_documentation/text/tag" regex \$[a-z_]+ 0:function
467
468  add-highlighter "shared/%opt{filetype}/factorio_documentation/tag" region -recurse \$[a-z_]+\( \$[a-z_]+\( \) group
469  add-highlighter "shared/%opt{filetype}/factorio_documentation/tag/variable" regex [a-zA-Z0-9_:\.-]+ 0:type
470  add-highlighter "shared/%opt{filetype}/factorio_documentation/tag/tag" regex \$[a-z_]+ 0:function
471  add-highlighter "shared/%opt{filetype}/factorio_documentation/tag/property" regex (\$(|param|return|raises|subclass|property))\( 1:keyword
472  add-highlighter "shared/%opt{filetype}/factorio_documentation/tag/value" regex \b(\d+|true|false)\b 1:value
473  add-highlighter "shared/%opt{filetype}/factorio_documentation/tag/string" regex '".*?"' 0:string
474}
475# GNU STL has a really stupid indentation format
476hook global BufCreate /usr/include/c\+\+/.* %{
477  set-option buffer tabstop 8
478  set-option buffer softabstop 4
479  set-option buffer indentwidth 4
480}
481
482hook global BufCreate ".*changelog\.txt$" %{
483  try %{
484    execute-keys -draft ggxs---------------------------------------------------------------------------------------------------<ret>
485    set-option buffer filetype factorio-changelog
486  }
487}
488hook global BufSetOption filetype=factorio-changelog %{
489  add-highlighter buffer/changelog_date regex ^(Date):\s(.*?)$ 1:type 2:function
490  add-highlighter buffer/changelog_entry regex ^(\s\s)*(-)\s(.*?)$ 2:value 3:string
491  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
492  add-highlighter buffer/changelog_separator regex ^-+$ 0:keyword
493  add-highlighter buffer/changelog_version regex ^(Version):\s(\d+\.\d+\.\d+)$ 1:type 2:value
494}
495
496hook global BufCreate (.*locale/.*/.*\.cfg) %{
497  set-option buffer filetype factorio-locale
498}
499hook global BufSetOption filetype=factorio-locale %{
500  require-module conf
501  add-highlighter buffer/conf ref conf
502  add-highlighter buffer/locale_macro regex __[^\n]*?__ 0:meta
503  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
504  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
505}
506
507hook global BufSetOption filetype=(git-commit|mail) %{
508  set-option buffer autowrap_column 72
509  set-option buffer autowrap_format_paragraph true
510  autowrap-enable
511}
512
513hook global BufCreate .*[.](glsl|vert|tesc|tese|geom|frag|comp) %{
514  set-option buffer filetype glsl
515}
516
517hook global BufSetOption filetype=glsl %{
518  add-highlighter buffer/glsl regions
519  add-highlighter buffer/glsl/code default-region group
520  add-highlighter buffer/glsl/line_comment region '//' $ fill comment
521  add-highlighter buffer/glsl/comment region '/\*' '\*/' fill comment
522  add-highlighter buffer/glsl/code/operator regex (\+|-|\*|&|=|\\|\?|%|\^|\|-|!|\||->|<|>|\^|/|~|\[|\]) 0:operator
523  add-highlighter buffer/glsl/code/function_call regex \b([a-zA-Z0-9_]*)\h*\( 1:function
524  add-highlighter buffer/glsl/code/constant regex \b([A-Z0-9_]*)\b 1:value
525  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
526  add-highlighter buffer/glsl/code/keyword regex \b(out|in|uniform|layout|if|else|for|struct|return)\b 1:keyword
527  add-highlighter buffer/glsl/code/macro regex (#version) 1:meta
528  add-highlighter buffer/glsl/code/export regex \b(gl_Position)\b 1:string
529}
530
531hook global BufSetOption filetype=go %{
532  noexpandtab
533  set-option buffer indentwidth 0
534  set-option buffer tabstop 4
535  set-option buffer softtabstop 4
536
537  hook buffer BufWritePre .* lsp-formatting-sync
538
539  map buffer user a :go-alternative-file<ret> -docstring "alternative file"
540}
541
542hook global BufSetOption filetype=hare %{
543  noexpandtab
544  set-option buffer tabstop 8
545  set-option buffer softtabstop 0
546  set-option buffer indentwidth 0
547}
548
549hook global BufSetOption filetype=java %{
550  set-option buffer tabstop 4
551  set-option buffer softtabstop 4
552  set-option buffer indentwidth 4
553
554  hook global BufWritePre .*\.java lsp-formatting-sync
555
556  add-highlighter -override shared/java/code/operator regex (=|==|&&|\|\||\+|-|/|\*|\+=|-=|\*=|/=|!|<=|>=|<|>) 1:operator
557}
558
559hook global BufSetOption filetype=json %{
560  set-option buffer formatcmd 'jq .'
561}
562
563hook global BufSetOption filetype=lua %{
564  set-option buffer lsp_servers %exp{
565    # [luapls]
566    # filetypes = ["lua"]
567    # root_globs = [".git/", ".luarc.json", ".editorconfig", ".kakrc"]
568    # command = "/home/rai/dev/personal/luapls/luapls"
569    # args = ["lsp", "3"]
570    # settings_section = "luapls"
571
572    # [luapls.settings.luapls]
573    # roots = ["demo.lua"]
574
575    # [emmylua_ls]
576    # filetypes = ["lua"]
577    # root_globs = [".git/", ".luarc.json", ".editorconfig", ".kakrc"]
578    # command = "emmylua_ls"
579
580    [luals]
581    filetypes = ["lua"]
582    root_globs = [".git/", ".luarc.json", ".editorconfig", ".kakrc"]
583    command = "/home/rai/.local/lua-language-server/bin/lua-language-server"
584    args = ["--logpath=/home/rai/.local/state/lua-language-server/log"]
585
586    [luals.settings.Lua]
587    diagnostics.disable = ["lowercase-global"]
588    diagnostics.severity = { unused-local = "Error", undefined-global = "Error", undefined-field = "Error" }
589    hover.expandAlias = false
590    hover.previewFields = 0
591    semantic.enable = false
592    telemetry.enable = false
593    workspace.userThirdParty = ["/home/rai/dev/luals"]
594
595    [fmtk-locale]
596    filetypes = ["factorio-locale", "lua"]
597    root_globs = ["info.json"]
598    command = "fmtk"
599    args = ["lsp", "--stdio"]
600
601    [fmtk-changelog]
602    filetypes = ["factorio-changelog", "lua"]
603    root_globs = ["info.json"]
604    command = "fmtk"
605    args = ["lsp", "--stdio"]
606  }
607
608  set-option buffer formatcmd "stylua -"
609  # Only auto-format if it is our own Factorio project
610  evaluate-commands %sh{
611    if [ -f "info.json" ] && [ $(jq -r ".author" < info.json) = "raiguard" ]; then
612      echo "hook buffer BufWritePre .* format"
613    fi
614  }
615}
616
617hook global WinSetOption filetype=lua %{
618  # Highlight EmmyLua annotations
619  add-highlighter window/emmylua_direct regex "---\s*(@(?:alias|as|class|enum|generic|return|type|overload))\s+([^\n]*)" 1:attribute 2:type
620  add-highlighter window/emmylua_labeled regex "---\s*(@(?:alias|cast|field|param))\s+([a-zA-Z0-9_\?]*) ([^\n]*)" 1:attribute 2:variable 3:type
621  add-highlighter window/emmylua_enum_variant regex '---\s*\|\s*("[^\n]*")' 1:string
622
623}
624
625hook global WinSetOption filetype=makefile %{
626  noexpandtab
627  set-option window indentwidth 0
628}
629
630hook global WinSetOption filetype=odin %{
631  noexpandtab
632  # Better highlighting
633  add-highlighter -override "shared/odin/code/operator" regex (\+|-|\*|&|=|\\|\?|%|\^|\|-|!|\||->|<|>|\^|/|~|\[|\]|:=) 0:operator
634  add-highlighter -override "shared/odin/code/constant" regex \b([A-Z0-9_]*)\b 1:value
635  add-highlighter -override "shared/odin/code/functioncall" regex \b([a-zA-Z0-9_]*)\( 1:function
636}
637
638hook global WinSetOption filetype=python %{
639  set-option window tabstop 4
640  set-option window softtabstop 4
641  set-option window indentwidth 4
642
643  set-option window formatcmd "autopep8 -"
644
645  add-highlighter -override shared/python/code/functioncall regex '\b([a-zA-Z0-9_]*)\h*\(' 1:function
646}
647
648hook global WinSetOption filetype=rust %{
649  lsp-inlay-hints-enable window
650
651  set-option window tabstop 4
652  set-option window softtabstop 4
653  set-option window indentwidth 4
654
655  # hook window BufWritePre .* lsp-formatting-sync
656}
657
658# TODO: Create a kak plugin for this filetype
659hook global BufCreate .+\.scd %{
660  set-option buffer filetype scdoc
661}
662hook global WinSetOption filetype=scdoc %{
663  noexpandtab
664
665  set-option window autowrap_format_paragraph true
666  autowrap-enable
667
668  add-highlighter window/scdoc_header regex "^##?\s*.*?$" 0:+b
669  add-highlighter window/scdoc_bold regex "\*.*?\*" 0:+b
670  add-highlighter window/scdoc_underline regex "\b_.*?_\b" 0:+u
671}
672
673hook global WinSetOption filetype=zig %{
674  set-option window tabstop 4
675  set-option window softtabstop 4
676  set-option window indentwidth 4
677}
678hook global ModuleLoaded zig %{
679  add-highlighter shared/zig/code/function_call regex \b([a-zA-Z0-9]+)\( 1:function
680  add-highlighter shared/zig/code/builtin_function regex (@[a-zA-Z0-9]+)\( 1:builtin
681}
682
683hook global WinCreate '/tmp/\.nnn.*' %{
684  hook -once window WinDisplay .* %{
685    execute-keys '%<a-s><a-s-k>^#<ret><a-;>;'
686    add-highlighter window/nnn_sources regex '^#.*?\n' 0:+d@comment
687  }
688}
689
690# --------------------------------------------------
691# TODO Mode
692
693# Highlight TODO and other related comment tags
694hook global WinSetOption comment_line=(.*) %{
695  add-highlighter -override window/todo regex "\Q%val{hook_param_capture_1}\E\h*(TODO(?: (raiguard|branch))?:)[^\n]*" 1:string
696  add-highlighter -override window/fixme regex "\Q%val{hook_param_capture_1}\E\h*((?:FIXME|XXX)(?: (raiguard|branch))?:)[^\n]*" 1:Error
697}
698map global toggle t ":grep '(BUG|FIXME|TODO|TEMPORARY):'<ret>" -docstring "TODOs"
699
700# --------------------------------------------------
701# MODELINE
702
703# Git branch
704declare-option -hidden str modeline_git_branch
705hook global WinDisplay .* %{
706  set-option window modeline_git_branch %sh{
707    branch=$(git -C "${kak_buffile%/*}" rev-parse --abbrev-ref HEAD 2>/dev/null)
708    if [ -n "$branch" ]; then
709      printf "$branch "
710    fi
711  }
712}
713
714set-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}'
715
716# --------------------------------------------------
717# OTHER
718
719# Enable LSP
720# This has to be after filetype hooks in order to load those filetypes' LSP configurations.
721lsp-enable
722
723# Wrapper commands
724define-command -params .. -docstring "fmm [<arguments>]: fmm utility wrapper" fmm %{
725  fifo -name *fmm* -scroll -- fmm %arg{@}
726  set-option buffer filetype make
727  set-option buffer jump_current_line 0
728}
729define-command -params .. -docstring "frun [<arguments>]: frun utility wrapper" frun %{
730  fifo -name *frun* -scroll -- frun %arg{@}
731  set-option buffer filetype grep
732  set-option buffer jump_current_line 0
733}
734
735# Quickly test faces
736declare-option range-specs test_ranges
737define-command add-test-face -params 1 %{
738  set-option -add window test_ranges "%val{selection_desc}|%arg{1}"
739  add-highlighter -override window/test_ranges ranges test_ranges
740}
741alias global tface add-test-face
742
743define-command run-selected-commands %{
744  evaluate-commands -itersel -draft %exp{ %val{selection} }
745}
746
747source "%val{config}/delete-all-buffers.kak"
748source "%val{config}/detect-indentation.kak"
749source "%val{config}/jump-stack.kak"
750
751hook global BufOpenFile ".*" %{
752  detect-indent-style
753}
754
755local-kakrc-load-if-trusted
756
757loadg filetypes *