diff options
| author | twells46 <173561638+twells46@users.noreply.github.com> | 2025-12-31 13:28:05 -0600 |
|---|---|---|
| committer | twells46 <173561638+twells46@users.noreply.github.com> | 2025-12-31 13:28:05 -0600 |
| commit | 2140ab51deed88e90eafebf9520fa5f9995dc7c9 (patch) | |
| tree | 03cf1dcd2900495c1efb79aaa85f3254ecd5fb87 /dot_config/kak/kakrc | |
| parent | ff8f50638e4b17a9d7cc88d2f0d9560b7effce39 (diff) | |
Migrate from stow
Diffstat (limited to 'dot_config/kak/kakrc')
| -rw-r--r-- | dot_config/kak/kakrc | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/dot_config/kak/kakrc b/dot_config/kak/kakrc new file mode 100644 index 0000000..4b11572 --- /dev/null +++ b/dot_config/kak/kakrc @@ -0,0 +1,216 @@ +#colorscheme catppuccin_latte + +# Lines numbers and relative numbers +add-highlighter global/ number-lines -relative + +# Highlight matching pair +add-highlighter global/ show-matching + +# Wrap on word boundaries +add-highlighter global/ wrap -indent -word + +# Highlight trailing whitespace +add-highlighter global/ regex \h+$ 0:Error + +set-option global scrolloff 5,5 + +map global normal <c-v> ":comment-line<ret>" + +# System clipboard bindings +map global user y "<a-|>cp.sh<ret>" -docstring "[Y]ank to system clipboard" +map global user p "|put.sh<ret>" -docstring "[P]ut from system clipboard" + +### A note on the /dev/null black magic ### +# %sh is synchronous by design. It will wait for: +# 1. The shell process to exit. +# 2. All pipes (stdin, stdout, stderr) to close. +# +# The final `&` forks the process, satisfying the first condition, but all +# pipes are left open. So, we need to "close" them: +# - `> /dev/null` to close stdout +# - `2>&1` redirects stderr to stdout, which in this case is `/dev/null` - closed +# - `< /dev/null` closes stdin +# Now, as far as kakoune is concerned, the process has finished and all pipes +# are closed, so control immediately returns to the client. +define-command -docstring "Compile the current document" compile %{ + nop %sh{ { + compiler $"{kak_buffile}" + } > /dev/null 2>&1 < /dev/null & } +} +map global user c -docstring "[C]ompile the current file" ":compile<ret>" + +map global user = -docstring "Format current buffer with :format" ":format<ret>" + +hook global BufCreate .*\.[Rr]md %{ set-option buffer filetype markdown } + +# Pattern for communicating with kak via it's session socket +define-command sockettest %{ + nop %sh{ { + sleep 10 + echo "eval -client '$kak_client' 'echo sleep ended'" | + kak -p ${kak_session} + } > /dev/null 2>&1 < /dev/null & } +} + +# fzf file chooser +define-command fzf_file %{ + nop %sh{ + # Create a temporary file for storage + foot -T 'foot_tmp' dash -c ' + next=$(fzf --height=100% --layout=default --preview "highlight -O ansi {}") + printf "eval -client %s %%{ edit %s }\n" "$kak_client" "$next" | + kak -p "$kak_session" + ' > /dev/null 2>&1 < /dev/null & + } +} +map global user f -docstring "Browse [f]iles with fzf" ":fzf_file<ret>" + +# fzf buffer chooser +define-command fzf_buffer %{ + nop %sh{ + # Create a temporary file for storage + foot -T 'foot_tmp' dash -c ' + next=$(printf "%s\n" "$kak_buflist" | tr " " "\n" | + fzf --height=100% --layout=default --preview "highlight -O ansi {}") + printf "eval -client %s %%{ buffer %s }\n" "$kak_client" "$next" | + kak -p "$kak_session" + ' > /dev/null 2>&1 < /dev/null & + } +} +map global user b -docstring "Browse [b]uffers with fzf" ":fzf_buffer<ret>" + +define-command fifotest %{ + evaluate-commands %sh{ + # Create a temporary fifo for communication + output=$(mktemp -d -t kak-temp-XXXXXXXX)/fifo + mkfifo ${output} + # run command detached from the shell + { fzf > ${output} } > /dev/null 2>&1 < /dev/null & + # Open the file in Kakoune and add a hook to remove the fifo + echo "edit! -fifo ${output} *buffer-name* + hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output})} }" + } +} + + +# Trick to make compiler run async +#hook global BufWritePost .*\.(md|tex|ms)$ %{ +# nop %sh{ { +# compiler $"{kak_buffile}" +# } > /dev/null 2>&1 < /dev/null & } +#} +# Simpler version +# hook global BufWritePost .*\.(md|tex)$ %{ +# echo -debug %sh{compiler "${kak_buffile}"} +# } + +# Filetypes with two-space indentation +hook global BufCreate .*\.(js|html|ts|tsx|hs)$ %{ + # Map tab key to `>` in normal mode -- inserts <indentwidth> spaces + map global insert <tab> '<a-;><a-gt>' + set-option buffer indentwidth 2 +} +# Filetypes with four-space indentation +hook global BufCreate .*\.(py|json|jsonc)$ %{ + map global insert <tab> '<a-;><a-gt>' + set-option buffer indentwidth 4 +} + +eval %sh{kak-lsp} +hook global WinSetOption filetype=(haskell|rust|python|go|javascript|typescript|c|cpp) %{ + lsp-enable-window +} + +remove-hooks global lsp-filetype-python +hook -group lsp-filetype-python global BufSetOption filetype=python %{ + # set-option buffer lsp_servers %{ + # [pylsp] + # root_globs = ["requirements.txt", "setup.py", "pyproject.toml", ".git", ".hg"] + # settings_section = "_" + # [pylsp.settings._] + # # See https://github.com/python-lsp/python-lsp-server#configuration + # # pylsp.configurationSources = ["flake8"] + # pylsp.plugins.jedi_completion.include_params = true + # } + set-option buffer lsp_servers %{ + [pyright-langserver] + root_globs = ["requirements.txt", "setup.py", "pyproject.toml", "pyrightconfig.json", ".git", ".hg"] + args = ["--stdio"] + } + # set-option -add buffer lsp_servers %{ + # [ruff] + # args = ["server", "--quiet"] + # root_globs = ["requirements.txt", "setup.py", "pyproject.toml", ".git", ".hg"] + # settings_section = "_" + # [ruff.settings._.globalSettings] + # organizeImports = true + # fixAll = true + # } +} + +hook -group lsp-filetype-javascript global BufSetOption filetype=(?:javascript|typescript) %{ + set-option buffer lsp_servers %{ + [vtsls] + root_globs = ["package.json", "tsconfig.json", "jsconfig.json", ".git", ".hg"] + args = ["--stdio"] + settings_section = "_" + [vtsls.settings._] + quotePreference = "single" + # typescript.format.semicolons = "insert" + } + #set-option buffer lsp_servers %{ + # [typescript-language-server] + # root_globs = ["package.json", "tsconfig.json", "jsconfig.json", ".git", ".hg"] + # args = ["--stdio"] + # settings_section = "_" + # [typescript-language-server.settings._] + # # quotePreference = "double" + # # typescript.format.semicolons = "insert" + #} + # set-option buffer lsp_servers %{ + # [deno] + # root_globs = ["package.json", "tsconfig.json", ".git", ".hg"] + # args = ["lsp"] + # settings_section = "deno" + # [deno.settings.deno] + # enable = true + # lint = true + # } + # set-option buffer lsp_servers %opt{lsp_server_biome} + # set-option buffer lsp_servers %{ + # [eslint-language-server] + # root_globs = [".eslintrc", ".eslintrc.json"] + # args = ["--stdio"] + # workaround_eslint = true + # [eslint-language-server.settings] + # codeActionsOnSave = { mode = "all", "source.fixAll.eslint" = true } + # format = { enable = true } + # quiet = false + # rulesCustomizations = [] + # run = "onType" + # validate = "on" + # experimental = {} + # problems = { shortenToSingleLine = false } + # codeAction.disableRuleComment = { enable = true, location = "separateLine" } + # codeAction.showDocumentation = { enable = false } + # } + # set-option buffer lsp_servers %{ + # [tailwindcss-language-server] + # root_globs = ["tailwind.*"] + # args = ["--stdio"] + # [tailwindcss-language-server.settings.tailwindCSS] + # editor = {} + # } +} + +map global user l ':enter-user-mode lsp<ret>' -docstring 'LSP mode' + +map global insert <tab> '<a-;>:try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks <lt>tab> }<ret>' -docstring 'Select next snippet placeholder' +map global user h ':lsp-hover<ret>' -docstring 'LSP hover' + +map global object a '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol' +map global object <a-a> '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol' +map global object f '<a-semicolon>lsp-object Function Method<ret>' -docstring 'LSP function or method' +map global object t '<a-semicolon>lsp-object Class Interface Struct<ret>' -docstring 'LSP class interface or struct' +map global object d '<a-semicolon>lsp-diagnostic-object --include-warnings<ret>' -docstring 'LSP errors and warnings' +map global object D '<a-semicolon>lsp-diagnostic-object<ret>' -docstring 'LSP errors' |