diff --git a/.config/kak/config/mappings.kak b/.config/kak/config/mappings.kak index 4b7b709..2b204b5 100644 --- a/.config/kak/config/mappings.kak +++ b/.config/kak/config/mappings.kak @@ -1,8 +1,8 @@ -map global normal :toggle-whitespace -map global normal :buffer-switcher -map global normal :xplr -map global normal :lazygit - -map global user 'p' 'pbpaste' -docstring 'Paste from clipboard' -map global user 'P' '!pbpaste' -docstring 'Paste from clipboard' -map global user 'y' 'pbcopy' -docstring 'Yank to clipboard' +map global user 'b' ':fzf-buflist' -docstring 'Select buffer from list' +map global user 'f' ':xplr' -docstring 'File finder' +map global user 'g' ':lazygit' -docstring 'Open lazygit' +map global user 'l' ':fzf-lines' -docstring 'Jump to line' +map global user 'p' ':paste-sys-after' -docstring 'Paste from clipboard after selection' +map global user 'P' ':paste-sys-before' -docstring 'Paste from clipboard before selection' +map global user 'w' ':toggle-whitespace' -docstring 'Toggle whitespace highlighter' +map global user 'y' ':yank-sys' -docstring 'Yank to clipboard' diff --git a/.config/kak/config/options.kak b/.config/kak/config/options.kak index 8bbe66f..f814804 100644 --- a/.config/kak/config/options.kak +++ b/.config/kak/config/options.kak @@ -1,17 +1,20 @@ colorscheme everforest-dark-soft -set-option global ui_options terminal_set_title=no terminal_assistant=cat # The cat is critically important. +set-option global ui_options terminal_set_title=no set-option global tabstop 4 set-option global indentwidth 4 add-highlighter global/ show-matching -declare-option str windowing_placement horizontal +#declare-option str windowing_placement horizontal # With the way that Kakoune's windowing detection is currently set up, the wezterm module will never be loaded. # So, we need to fix the order in which windowing modules are declared. +# TODO: submit a PR to Kakoune fixing this. declare-option str-list windowing_modules 'tmux' 'screen' 'zellij' 'kitty' 'wezterm' 'iterm' 'appleterminal' 'sway' 'wayland' 'x11' +set-option global windowing_placement horizontal + hook global WinCreate .* %{ add-highlighter window/number-lines number-lines -hlcursor } diff --git a/.config/kak/config/plugins.kak b/.config/kak/config/plugins.kak index f632bbd..be035a5 100644 --- a/.config/kak/config/plugins.kak +++ b/.config/kak/config/plugins.kak @@ -1,5 +1,5 @@ source "%val{config}/bundle/kak-bundle/rc/kak-bundle.kak" -bundle-noload kak-bundle "ln -sf ~/workspace/kak-bundle/" +bundle-noload kak-bundle "https://codeberg.org/jdugan6240/kak-bundle" bundle kakoune-lsp "https://github.com/kakoune-lsp/kakoune-lsp" %{ set-option global lsp_diagnostic_line_error_sign  @@ -7,6 +7,8 @@ bundle kakoune-lsp "https://github.com/kakoune-lsp/kakoune-lsp" %{ set-option global lsp_diagnostic_line_info_sign ℹ set-option global lsp_diagnostic_line_warning_sign  + set-option global lsp_hover_anchor true + # kakoune-lsp doesn't have a command to enable auto-hover per buffer, # only supporting enabling auto-hover globally, # which causes issues in filetypes that don't have lsp set up. @@ -35,40 +37,43 @@ bundle kakoune-lsp "https://github.com/kakoune-lsp/kakoune-lsp" %{ # We want to be explicit about lsp server settings per filetype # So, we are disabling the default lsp server hooks remove-hooks global lsp-filetype-.* + + set global lsp_debug true } bundle-install-hook kakoune-lsp %{ CARGO_PROFILE_RELEASE_LTO=false cargo install --locked --force --path . } -bundle-noload everforest.kak "ln -sf ~/workspace/everforest.kak/" -bundle-install-hook everforest.kak %{ - mkdir -p "${kak_config}/colors" - ln -sf "${kak_opt_bundle_path}/everforest.kak" "${kak_config}/colors/" -} -bundle-cleaner everforest.kak %{ - rm "${kak_config}/colors/everforest.kak" -} +bundle-theme everforest.kak "https://codeberg.org/jdugan6240/everforest.kak" bundle luar "https://github.com/gustavo-hms/luar" %@ require-module luar - # Luar's highlighters are very subtly broken so we need to replace them - # TODO: submit a PR to luar with these fixes. + # Luar's highlighters are very subtly broken so we need to replace them. + # These aren't perfect either, as they assume the "lua" or "fennel" command invocation is the first thing in the line, + # but whatever - when both "lua" and "fennel" can appear in many contexts, it's hard to be robust without a true parser. + remove-highlighter shared/kakrc/code/lua remove-highlighter shared/kakrc/lua1 remove-highlighter shared/kakrc/lua2 remove-highlighter shared/kakrc/lua3 remove-highlighter shared/kakrc/lua4 - add-highlighter shared/kakrc/lua1 region -recurse '\{' '(^|\h)lua\s(([\s{}\w%/$-|''"])* )?%\{\K' '\}' ref lua - add-highlighter shared/kakrc/lua2 region -recurse '\(' '(^|\h)lua\s(([\s{}\w%/$-|''"])* )?%\(\K' '\)' ref lua - add-highlighter shared/kakrc/lua3 region -recurse '\[' '(^|\h)lua\s(([\s{}\w%/$-|''"])* )?%\[\K' '\]' ref lua - add-highlighter shared/kakrc/lua4 region -recurse '<' '(^|\h)lua\s(([\s{}\w%/$-|''"])* )?%<\K' '>' ref lua + remove-highlighter shared/kakrc/code/fennel + remove-highlighter shared/kakrc/fennel1 + remove-highlighter shared/kakrc/fennel2 + remove-highlighter shared/kakrc/fennel3 + remove-highlighter shared/kakrc/fennel4 + add-highlighter shared/kakrc/code/lua regex (^\s*)lua(?:(?=\s)|\z) 0:keyword + add-highlighter shared/kakrc/lua1 region -recurse '\{' '^\s*lua\s(([\s{}\w%/$-|''"])* )?%\{\K' '\}' ref lua + add-highlighter shared/kakrc/lua2 region -recurse '\(' '^\s*lua\s(([\s{}\w%/$-|''"])* )?%\(\K' '\)' ref lua + add-highlighter shared/kakrc/lua3 region -recurse '\[' '^\s*lua\s(([\s{}\w%/$-|''"])* )?%\[\K' '\]' ref lua + add-highlighter shared/kakrc/lua4 region -recurse '<' '^\s*lua\s(([\s{}\w%/$-|''"])* )?%<\K' '>' ref lua + add-highlighter shared/kakrc/code/fennel regex (^\s*)fennel(?:(?=\s)|\z) 0:keyword + add-highlighter shared/kakrc/fennel1 region -recurse '\{' '^\s*fennel\s(([\s{}\w%/$-|''"])* )?%\{\K' '\}' ref fennel + add-highlighter shared/kakrc/fennel2 region -recurse '\(' '^\s*fennel\s(([\s{}\w%/$-|''"])* )?%\(\K' '\)' ref fennel + add-highlighter shared/kakrc/fennel3 region -recurse '\[' '^\s*fennel\s(([\s{}\w%/$-|''"])* )?%\[\K' '\]' ref fennel + add-highlighter shared/kakrc/fennel4 region -recurse '<' '^\s*fennel\s(([\s{}\w%/$-|''"])* )?%<\K' '>' ref fennel @ -bundle kakoune-buffer-switcher "https://github.com/occivink/kakoune-buffer-switcher" %{ - # Make the current buffer more visible - set-face global BufferSwitcherCurrent value -} - bundle kakoune-focus "https://github.com/caksoylar/kakoune-focus" %{ map global user ':focus-toggle' -docstring "toggle selections focus" } @@ -78,45 +83,83 @@ bundle kakship https://github.com/eburghar/kakship %{ } bundle-install-hook kakship %{ cargo install --force --path . --root ~/.local - [ ! -e $kak_config/starship.toml ] && cp starship.toml $kak_config/ + if [ ! -e $kak_config/starship.toml ]; then + cp starship.toml $kak_config/ + fi } bundle-cleaner kakship %{ rm ~/.local/bin/kakship } -bundle popup.kak https://github.com/enricozb/popup.kak -bundle-install-hook popup.kak %{ - cargo install --force --path . -} -bundle-cleaner popup.kak %{ - cargo uninstall kak-popup -} - bundle-customload kak-tree-sitter https://git.sr.ht/~hadronized/kak-tree-sitter %{ - evaluate-commands %sh{ kak-tree-sitter -dks --init $kak_session } + evaluate-commands %sh{ kak-tree-sitter -dks --init $kak_session --with-highlighting -vvvvv } + + # kak-tree-sitter sometimes gets out of sync during editing, especially with large files + # so, whenever we get back to normal mode, force an update + hook global ModeChange .*:normal %{ + tree-sitter-buffer-update + } } bundle-install-hook kak-tree-sitter %{ - cargo install --force --path ./kak-tree-sitter - cargo install --force --path ./ktsctl + cargo install --force --path kak-tree-sitter + cargo install --force --path ktsctl } bundle-cleaner kak-tree-sitter %{ cargo uninstall kak-tree-sitter cargo uninstall ktsctl } -bundle-noload kakeidoscope "git clone --recurse-submodules https://git.sr.ht/~orchid/kakeidoscope" +bundle kakeidoscope https://git.sr.ht/~orchid/kakeidoscope %{ + #hook global WinCreate .* kakeidoscope-enable-window +} bundle-install-hook kakeidoscope %{ - cd src - make - mv kakeidoscope ~/.local/bin/ + cargo install --force --path . } bundle-cleaner kakeidoscope %{ - rm ~/.local/bin/kakeidoscope -} -bundle-updater kakeidoscope %{ - git pull --recurse-submodules + cargo uninstall kakeidoscope } -bundle peneira https://github.com/gustavo-hms/peneira %{ - require-module peneira +bundle-noload kak-rainbower %{ + # This is the last commit of kak-rainbower that worked + git clone https://github.com/crizan/kak-rainbower + cd kak-rainbower + git reset --hard 692c196650edd97da9ed6c275bb9b261630d063d +}%{ + set-option global rainbow_mode 0 + hook global WinCreate .* %{ + rainbow-enable-window + } } +bundle-install-hook kak-rainbower %{ + c++ rc/rainbower.cpp -o rc/rainbower +} +bundle-updater kak-rainbower %{ + # This is the last commit of kak-rainbower that worked + #git reset --hard 692c196650edd97da9ed6c275bb9b261630d063d + git reset --hard frederick-the-great +} + +bundle kak-rainbow https://github.com/Bodhizafa/kak-rainbow %{ + hook global WinCreate .* %{ + rainbow-enable-window + } +} + +bundle pairs.kak https://github.com/42xel/pairs.kak %{ + pairs_enable +} + +bundle parinfer-rust https://github.com/eraserhd/parinfer-rust %{ + hook global WinSetOption filetype=(clojure|fennel|lisp|picolisp|racket|scheme) %{ + parinfer-enable-window -smart + } +} +bundle-install-hook parinfer-rust %{ + cargo install --force --path . +} +bundle-cleaner parinfer-rust %{ + cargo uninstall parinfer-rust +} + +# Automatically clean any unregistered plugins +bundle-clean diff --git a/.config/kak/filetypes/fennel.kak b/.config/kak/filetypes/fennel.kak new file mode 100755 index 0000000..9f5eb6e --- /dev/null +++ b/.config/kak/filetypes/fennel.kak @@ -0,0 +1,22 @@ +hook global WinSetOption filetype=fennel %{ + set-option buffer lsp_servers %{ + [fennel-ls] + root_globs = [".git", ".hg", "fennel.lua"] + command = "/home/ANT.AMAZON.COM/dugajame/fennel-ls/fennel-ls" + } + lsp-enable-buffer + softtab-enable +} + +hook global ModuleLoaded fennel %{ + # By default, Kakoune highlights colon strings in the "keyword" face. + # This is incorrect - they should be highlighted as strings. + # So, we override the builtin highlighter with our own. + remove-highlighter shared/fennel/colon-string + add-highlighter shared/fennel/colon-string region '\W\K:[-\w?\\^_!$%&*+./@|<=>]' '(?![-\w?\\^_!$%&*+./@|<=>])' fill string + + # Kakoune's default fennel support also doesn't properly highlight values, + # so we patch the lua highlighter in here + remove-highlighter shared/fennel/code/value + add-highlighter shared/fennel/code/value regex \b(false|nil|true|self|[0-9]+(:?\.[0-9])?(:?[eE]-?[0-9]+)?|0x[0-9a-fA-F]+)\b 0:value +} diff --git a/.config/kak/filetypes/go.kak b/.config/kak/filetypes/go.kak index a3bc8e2..501cd10 100644 --- a/.config/kak/filetypes/go.kak +++ b/.config/kak/filetypes/go.kak @@ -19,4 +19,6 @@ hook global WinSetOption filetype=go %{ } lsp-enable-buffer lsp-semantic-tokens-enable + + set-option buffer indentwidth 0 # Use tabs } diff --git a/.config/kak/filetypes/kak.kak b/.config/kak/filetypes/kak.kak index 34a9579..58c2593 100644 --- a/.config/kak/filetypes/kak.kak +++ b/.config/kak/filetypes/kak.kak @@ -10,4 +10,10 @@ hook global ModuleLoaded kak %@ ~ catch %$ echo -debug "Error: kakrc: can't declare additional kakrc highlighters: %val{error}" $ + # highlighting for bundle_sh_code + try %~ + add-highlighter shared/kakrc/bundle_sh_code region -recurse '\{' '\bbundle_sh_code\s+%\{' '\}' ref sh + ~ catch %$ + echo -debug "Error: kakrc: can't declare additional kakrc highlighters: %val{error}" + $ @ diff --git a/.config/kak/filetypes/kdl.kak b/.config/kak/filetypes/kdl.kak new file mode 100755 index 0000000..caf4faf --- /dev/null +++ b/.config/kak/filetypes/kdl.kak @@ -0,0 +1,9 @@ +hook global WinSetOption filetype=kdl %{ + set-option buffer lsp_servers %{ + [kdl-lsp] + root_globs = [".git", ".hg"] + command = "kdl-lsp" + } + lsp-enable-buffer + softtab-enable +} diff --git a/.config/kak/filetypes/lua.kak b/.config/kak/filetypes/lua.kak index f6ae202..7a809a9 100644 --- a/.config/kak/filetypes/lua.kak +++ b/.config/kak/filetypes/lua.kak @@ -1,10 +1,18 @@ hook global WinSetOption filetype=lua %{ set-option buffer lsp_servers %{ - [lua-language-server] - root_globs = [".luarc.json", ".git", ".hg"] - command = "lua-language-server" + [lua-language-server] + root_globs = [".luarc.json", ".git", ".hg"] + command = "/home/ANT.AMAZON.COM/dugajame/lua-language-server/bin/lua-language-server" + # [emmylua_ls] + # root_globs = [".luarc.json", ".git", ".hg"] + # command = "emmylua_ls" } lsp-semantic-tokens-enable softtab-enable lsp-enable-buffer } + +hook global ModuleLoaded lua %{ + # Support highlighting shebangs + add-highlighter shared/lua/shebang region '^#!' '$' fill comment +} diff --git a/.config/kak/filetypes/python.kak b/.config/kak/filetypes/python.kak index 0dddc0e..6f38ff6 100644 --- a/.config/kak/filetypes/python.kak +++ b/.config/kak/filetypes/python.kak @@ -7,7 +7,7 @@ hook global WinSetOption filetype=python %{ [ruff] root_globs = ["requirements.txt", "setup.py", "pyrightconfig.json", ".git", ".hg"] command = "ruff" - args = ["server", "--preview"] + args = ["server"] } lsp-enable-buffer lsp-semantic-tokens-enable diff --git a/.config/kak/filetypes/rust.kak b/.config/kak/filetypes/rust.kak new file mode 100755 index 0000000..763d8c0 --- /dev/null +++ b/.config/kak/filetypes/rust.kak @@ -0,0 +1,16 @@ +hook global WinSetOption filetype=rust %{ + set-option buffer lsp_servers %{ + # [rust-analyzer] + # root_globs = ["Cargo.toml"] + # single_instance = true + # command = "rust-analyzer" + # [rls] + # root_globs = ["Cargo.toml"] + # command = "rls" + [ra-multiplex] + root_globs = ["Cargo.toml"] + command = "ra-multiplex" + } + lsp-enable-buffer + #lsp-semantic-tokens-enable +} diff --git a/.config/kak/kakrc b/.config/kak/kakrc index 500f244..c12d12c 100644 --- a/.config/kak/kakrc +++ b/.config/kak/kakrc @@ -11,7 +11,11 @@ load config plugins # Additional syntaxes load syntaxes capnp +load syntaxes hjson +load syntaxes hyprlang +load syntaxes json5 load syntaxes kdl +load syntaxes kitty load syntaxes rainbow_csv load syntaxes sshconfig @@ -22,6 +26,9 @@ load utils whitespace # Tool integration +load tools clipboard +load tools fzf +load tools kitty load tools lazygit load tools xplr @@ -35,10 +42,13 @@ load config mappings # Filetype-specific configs +load filetypes fennel load filetypes go load filetypes kak +load filetypes kdl load filetypes lua load filetypes python +load filetypes rust load filetypes sh load filetypes yaml diff --git a/.config/kak/syntaxes/hjson.kak b/.config/kak/syntaxes/hjson.kak new file mode 100755 index 0000000..992f858 --- /dev/null +++ b/.config/kak/syntaxes/hjson.kak @@ -0,0 +1,112 @@ +# http://hjson.github.io +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](hjson) %{ + set-option buffer filetype hjson +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=hjson %{ + require-module hjson + + hook window ModeChange pop:insert:.* -group hjson-trim-indent hjson-trim-indent + hook window InsertChar .* -group hjson-indent hjson-indent-on-char + hook window InsertChar \n -group hjson-indent hjson-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window hjson-.+ } +} + +hook -group hjson-highlight global WinSetOption filetype=hjson %{ + add-highlighter window/hjson ref hjson + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/hjson } +} + + +provide-module hjson %( + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/hjson regions +add-highlighter shared/hjson/code default-region group +add-highlighter shared/hjson/string region '"' (? d } +} + +define-command -hidden hjson-indent-on-char %< + evaluate-commands -draft -itersel %< + # align closer token to its opener when alone on a line + try %< execute-keys -draft ^\h+[\]}]$ m 1 > + > +> + +define-command -hidden hjson-indent-on-new-line %{ + evaluate-commands -itersel -draft %{ + execute-keys + try %{ + evaluate-commands -draft -save-regs '/"' %{ + # Ensure previous line is a comment + # This only supports "#" comments (because hjson supporting # and // comments was a mistake) + execute-keys -draft kxs^\h*#+\h* + + # now handle the coment continuation logic + try %{ + # try and match a regular block comment, copying the prefix + execute-keys -draft -save-regs '' k x 1s^(\h*#+\h*)\S.*$ y + execute-keys -draft P + } catch %{ + try %{ + # try and match a regular block comment followed by a single + # empty comment line + execute-keys -draft -save-regs '' kKx 1s^(\h*#+\h*)\S+\n\h*#+\h*$ y + execute-keys -draft P + } catch %{ + try %{ + # try and match a pair of empty comment lines, and delete + # them if we match + execute-keys -draft kKx ^\h*#+\h*\n\h*#+\h*$ + } catch %{ + # finally, we need a special case for a new line inserted + # into a file that consists of a single empty comment - in + # that case we can't expect to copy the trailing whitespace, + # so we add our own + execute-keys -draft -save-regs '' k x1s^(\h*#+)\h*$ y + execute-keys -draft P + execute-keys -draft i + } + } + } + } + + # trim trailing whitespace on the previous line + try %{ execute-keys -draft k x s\h+$ d } + } + } +} + +) + diff --git a/.config/kak/syntaxes/hyprlang.kak b/.config/kak/syntaxes/hyprlang.kak new file mode 100755 index 0000000..5028db3 --- /dev/null +++ b/.config/kak/syntaxes/hyprlang.kak @@ -0,0 +1,76 @@ +# https://hyprland.org/ + +hook global BufCreate .*/hypr/.*[.]conf %{ + set-option buffer filetype hyprlang +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=hyprlang %{ + require-module hyprlang + + hook window ModeChange pop:insert:.* -group hyprlang-trim-indent hyprlang-trim-indent + hook window InsertChar .* -group hyprlang-indent hyprlang-indent-on-char + hook window InsertChar \n -group hyprlang-indent hyprlang-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window hyprlang-.+ } +} + +hook -group hyprlang-highlight global WinSetOption filetype=hyprlang %{ + add-highlighter window/hyprlang ref hyprlang + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/hyprlang } +} + +provide-module hyprlang %@ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/hyprlang regions +add-highlighter shared/hyprlang/code default-region group + +add-highlighter shared/hyprlang/string region '"' (? d } +} + +define-command -hidden hyprlang-indent-on-char %< + evaluate-commands -draft -itersel %< + # align closer token to its opener when alone on a line + try %< execute-keys -draft ^\h+[\]}]$ m 1 > + > +> + +define-command -hidden hyprlang-indent-on-new-line %< + evaluate-commands -draft -itersel %< + # preserve previous line indent + try %{ execute-keys -draft K } + # filter previous line + try %{ execute-keys -draft k : hyprlang-trim-indent } + # indent after lines ending with opener token + try %< execute-keys -draft k x [[{]\h*$ j > + # deindent closer token(s) when after cursor + try %< execute-keys -draft x ^\h*[}\]] gh / [}\]] m 1 > + > +> + +@ diff --git a/.config/kak/syntaxes/json5.kak b/.config/kak/syntaxes/json5.kak new file mode 100755 index 0000000..23fce34 --- /dev/null +++ b/.config/kak/syntaxes/json5.kak @@ -0,0 +1,78 @@ +# http://json5.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](json5) %{ + set-option buffer filetype json5 +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=json5 %{ + require-module json5 + + hook window ModeChange pop:insert:.* -group json5-trim-indent json5-trim-indent + hook window InsertChar \n -group json5-insert json5-insert-on-new-line + hook window InsertChar \n -group json5-indent json5-indent-on-new-line + hook window InsertChar .* -group json5-indent json5-indent-on-char + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window json5-.+ } +} + +hook -group json5-highlight global WinSetOption filetype=json5 %{ + add-highlighter window/json5 ref json5 + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/json5 } +} + + +provide-module json5 %( + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/json5 regions +add-highlighter shared/json5/code default-region group +add-highlighter shared/json5/string region '"' (?kx s ^\h*\K/{2,}\h* yP } +] + +define-command -hidden json5-trim-indent %{ + # remove trailing white spaces + try %{ execute-keys -draft -itersel x s \h+$ d } +} + +define-command -hidden json5-indent-on-char %< + evaluate-commands -draft -itersel %< + # align closer token to its opener when alone on a line + try %< execute-keys -draft ^\h+[\]}]$ m 1 > + > +> + +define-command -hidden json5-indent-on-new-line %< + evaluate-commands -draft -itersel %< + # preserve previous line indent + try %{ execute-keys -draft K } + # filter previous line + try %{ execute-keys -draft k : json5-trim-indent } + # indent after lines ending with opener token + try %< execute-keys -draft k x [[{]\h*$ j > + # deindent closer token(s) when after cursor + try %< execute-keys -draft x ^\h*[}\]] gh / [}\]] m 1 > + > +> + +) diff --git a/.config/kak/syntaxes/kdl.kak b/.config/kak/syntaxes/kdl.kak index d4a0266..31fb9e8 100644 --- a/.config/kak/syntaxes/kdl.kak +++ b/.config/kak/syntaxes/kdl.kak @@ -1,4 +1,5 @@ # https://kdl.dev +# Currently only supports kdl v1 hook global BufCreate .*[.](kdl) %{ set-option buffer filetype kdl diff --git a/.config/kak/syntaxes/kitty.kak b/.config/kak/syntaxes/kitty.kak new file mode 100755 index 0000000..124f217 --- /dev/null +++ b/.config/kak/syntaxes/kitty.kak @@ -0,0 +1,225 @@ +# https://sw.kovidgoyal.net/kitty/ + +hook global BufCreate .*/kitty/.*[.]conf %{ + set-option buffer filetype kitty-conf +} + +hook global BufCreate .*/kitty/.*[.]session %{ + set-option buffer filetype kitty-session +} + +hook global WinSetOption filetype=kitty-conf %{ + require-module kitty-conf + set-option window static_words %opt{kitty_conf_static_words} + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window kitty-conf-.+ } +} + +hook -group kitty-conf-highlight global WinSetOption filetype=kitty-conf %{ + add-highlighter window/kitty-conf ref kitty-conf + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kitty-conf } +} + +hook global WinSetOption filetype=kitty-session %{ + require-module kitty-session + set-option window static_words %opt{kitty_session_static_words} + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window kitty-session-.+ } +} + +hook -group kitty-session-highlight global WinSetOption filetype=kitty-session %{ + add-highlighter window/kitty-session ref kitty-session + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kitty-session } +} + +provide-module kitty-conf %{ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/kitty-conf regions +add-highlighter shared/kitty-conf/code default-region group + + +add-highlighter shared/kitty-conf/line_comment region ^# $ fill comment +add-highlighter shared/kitty-conf/string region '"' (?%opt{yank_sys_clipboard_cmd}" +} +define-command paste-sys-before -docstring "paste from the system clipboard before selection" %{ + execute-keys -draft "!%opt{paste_sys_clipboard_cmd}" +} +define-command paste-sys-after -docstring "paste from the system clipboard after selection" %{ + execute-keys -draft "%opt{paste_sys_clipboard_cmd}" +} diff --git a/.config/kak/tools/fzf.kak b/.config/kak/tools/fzf.kak new file mode 100755 index 0000000..5ff4007 --- /dev/null +++ b/.config/kak/tools/fzf.kak @@ -0,0 +1,29 @@ +# https://junegunn.github.io/fzf + +define-command fzf-buflist -docstring "Use fzf to select buffer" %{ + set-register f %sh{ printf "%s" "$kak_buflist" | tr ' ' '\n' } + wezterm-terminal-tab sh -c %{ + PATH=$PATH:~/.fzf/bin/ + kak_session=$1 kak_client=$2 buflist=$3 + shift 3 + # Note: we need to replace ~ with $HOME here; otherwise bat can't find the file for preview + output=$(printf "$buflist" | sed "s|~|$HOME|" | fzf --preview 'bat --color=always {}') + kak_cmd="evaluate-commands -client $kak_client buffer $output" + echo $kak_cmd | kak -p $kak_session + } -- %val{session} %val{client} %reg{f} +} + +define-command fzf-lines -docstring "Use fzf to jump to line in current buffer" %{ + set-register f %sh{ mktemp } + execute-keys -draft '% nl -b a > $kak_reg_f' + wezterm-terminal-tab sh -c %{ + PATH=$PATH:~/.fzf/bin/ + kak_session=$1 kak_client=$2 buffile=$3 + shift 3 + output=$(fzf --layout=reverse < $buffile) + set -- $output + kak_cmd="evaluate-commands -client $kak_client execute-keys '${1}g'" + rm $buffile + echo $kak_cmd | kak -p $kak_session + } -- %val{session} %val{client} %reg{f} +} diff --git a/.config/kak/tools/kitty.kak b/.config/kak/tools/kitty.kak new file mode 100755 index 0000000..a2c96bd --- /dev/null +++ b/.config/kak/tools/kitty.kak @@ -0,0 +1,39 @@ +# https://sw.kovidgoyal.net/kitty +# The following assumes the "splits" layout. + +hook global ModuleLoaded kitty %{ + define-command kitty-launch-impl -params 3.. %{ + nop %sh{ + location=$1 + type=$2 + shift 2 + + match="" + if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then + match="--match=window_id:$kak_client_env_KITTY_WINDOW_ID" + fi + + listen="" + if [ -n "$kak_client_env_KITTY_LISTEN_ON" ]; then + listen="--to=$kak_client_env_KITTY_LISTEN_ON" + fi + + kitty @ $listen launch --no-response --location=$location --type=$type --cwd="$PWD" $match "$@" + } + } -hidden + + define-command kitty-terminal-horizontal -params 1.. %{ + kitty-launch-impl "vsplit" "window" %arg{@} + } + complete-command kitty-terminal-horizontal shell + + define-command kitty-terminal-vertical -params 1.. %{ + kitty-launch-impl "hsplit" "window" %arg{@} + } + complete-command kitty-terminal-vertical shell + + define-command kitty-terminal-overlay -params 1.. %{ + kitty-launch-impl "default" "overlay" %arg{@} + } + complete-command kitty-terminal-overlay shell +} diff --git a/.config/kak/tools/lazygit.kak b/.config/kak/tools/lazygit.kak index 3a78a65..e568e24 100644 --- a/.config/kak/tools/lazygit.kak +++ b/.config/kak/tools/lazygit.kak @@ -1,7 +1,7 @@ # https://github.com/jesseduffield/lazygit define-command lazygit %{ - popup lazygit + kitty-terminal-overlay lazygit } alias global lg lazygit diff --git a/.config/kak/tools/xplr.kak b/.config/kak/tools/xplr.kak index 033e966..b626d44 100644 --- a/.config/kak/tools/xplr.kak +++ b/.config/kak/tools/xplr.kak @@ -1,9 +1,10 @@ # https://xplr.dev/ -# Seriously, xplr is awesome. Get it if you haven't already. +# The reason to use xplr instead of fzf here is sometimes we want to edit a file +# not in the current working directory. -define-command xplr-open -params 1 %{ +define-command xplr-open -params 1.. %{ evaluate-commands %sh{ - for xplr_file in $1; do + for xplr_file in $@; do if [ -f "$xplr_file" ]; then printf "%s\n" "edit $xplr_file" fi @@ -11,8 +12,16 @@ define-command xplr-open -params 1 %{ } } -hidden -define-command xplr -params ..1 %{ - popup --title open --kak-script %{ xplr-open %opt{popup_output} } -- xplr %arg{@} +define-command xplr -params ..1 -docstring "Use xplr to open file" %{ + wezterm-terminal-tab sh -c %{ + PATH=$PATH:~/.fzf/bin/ + kak_buffile=$1 kak_session=$2 kak_client=$3 + shift 3 + kak_pwd="${@:-$(dirname "${kak_buffile}")}" + output=$(xplr "${kak_pwd}") + kak_cmd="evaluate-commands -client $kak_client xplr-open $output" + echo $kak_cmd | kak -p $kak_session + } -- %val{buffile} %val{session} %val{client} %arg{@} } # Utility command to edit a kak config file with xplr