Kakoune restructure

This commit is contained in:
2026-08-27 13:44:15 +02:00
parent d984cbb7af
commit 5ee19b70c5
21 changed files with 213 additions and 56 deletions
+6
View File
@@ -0,0 +1,6 @@
define-command -hidden -override filetype-css %{
set-option window tabstop 2
set-option window indentwidth 2
}
hook global WinSetOption filetype=css %{ filetype-css }
+7
View File
@@ -0,0 +1,7 @@
define-command -hidden -override filetype-go %{
set-option window tabstop 4
set-option window indentwidth 0
set-option window formatcmd 'gofmt'
}
hook global WinSetOption filetype=go %{ filetype-go }
+6
View File
@@ -0,0 +1,6 @@
define-command -hidden -override filetype-html %{
set-option window tabstop 2
set-option window indentwidth 2
}
hook global WinSetOption filetype=html %{ filetype-html }
+6
View File
@@ -0,0 +1,6 @@
define-command -hidden -override filetype-javascript %{
set-option window tabstop 2
set-option window indentwidth 2
}
hook global WinSetOption filetype=javascript %{ filetype-javascript }
+6
View File
@@ -0,0 +1,6 @@
define-command -hidden -override filetype-json %{
set-option window tabstop 2
set-option window indentwidth 2
}
hook global WinSetOption filetype=json %{ filetype-json }
+6
View File
@@ -0,0 +1,6 @@
define-command -hidden -override filetype-markdown %{
set-option window tabstop 2
set-option window indentwidth 2
}
hook global WinSetOption filetype=markdown %{ filetype-markdown }
+6
View File
@@ -0,0 +1,6 @@
define-command -hidden -override filetype-python %{
set-option window tabstop 4
set-option window indentwidth 4
}
hook global WinSetOption filetype=python %{ filetype-python }
+7
View File
@@ -0,0 +1,7 @@
define-command -hidden -override filetype-rust %{
set-option window tabstop 4
set-option window indentwidth 4
set-option window formatcmd 'rustfmt --edition 2021'
}
hook global WinSetOption filetype=rust %{ filetype-rust }
+6
View File
@@ -0,0 +1,6 @@
define-command -hidden -override filetype-scss %{
set-option window tabstop 2
set-option window indentwidth 2
}
hook global WinSetOption filetype=scss %{ filetype-scss }
+6
View File
@@ -0,0 +1,6 @@
define-command -hidden -override filetype-sh %{
set-option window tabstop 4
set-option window indentwidth 4
}
hook global WinSetOption filetype=sh %{ filetype-sh }
+6
View File
@@ -0,0 +1,6 @@
define-command -hidden -override filetype-toml %{
set-option window tabstop 2
set-option window indentwidth 2
}
hook global WinSetOption filetype=toml %{ filetype-toml }
+6
View File
@@ -0,0 +1,6 @@
define-command -hidden -override filetype-yaml %{
set-option window tabstop 2
set-option window indentwidth 2
}
hook global WinSetOption filetype=yaml %{ filetype-yaml }
+7 -56
View File
@@ -1,56 +1,7 @@
colorscheme mygruvbox
add-highlighter global/ number-lines -hlcursor
# Highlight trailing whitespace
# Softwrap long lines
add-highlighter global/ wrap -word -indent -marker ">>>"
add-highlighter global/ show-whitespaces
set-option -add global ui_options terminal_status_on_top=true
set-option -add global ui_options terminal_assistant=cat
set-option global tabstop 4
set-option global indentwidth 4
set-option global scrolloff 1,3
# Clipboard management mappings
map -docstring "yank the selection into the clipboard" global user y "<a-|> wl-copy<ret>"
map -docstring "paste the clipboard" global user p "<a-!> wl-paste<ret>"
map -docstring "Show filetype" global user t ': echo %opt{filetype}<ret>'
map -docstring "Open file" global user o ': tmux-repl-vertical "echo ""evaluate-commands -client %val{client} e $(fzf)"" | kak -p %val{session}"<ret>'
map -docstring "Zeile auskommentieren" global normal <C-l> ":comment-line<ret>"
map -docstring "Speichern" global normal <C-s> ":w<ret>"
map -docstring "Beenden" global normal <C-q> ":q<ret>"
map -docstring "Cursor nach oben erweitern" global normal <C-k> "<a-C><ret>"
map -docstring "Cursor nach unten erweitern" global normal <C-j> "<C><ret>"
map global normal <C-up> '|echo "$(($kak_selection + 1))"<ret>'
map global normal <C-down> '|echo "$(($kak_selection - 1))"<ret>'
# Convert spaces to tabs
hook global BufWritePre .* %{
try %{ execute-keys -draft '%@' }
}
# hook global BufWritePost .* %{
# echo %sh{ sassc main.scss > main.css }
# }
eval %sh{kak-debug init --session $kak_session}
map global user d ':enter-user-mode dap<ret>' -docstring 'DAP mode'
eval %sh{kak-lsp}
lsp-enable
lsp-inlay-diagnostics-enable global
# gd -> zur Definition springen
map global goto d '<esc>: lsp-definition<ret>' -docstring 'definition'
# gr -> Referenzen (Aufrufstellen) auflisten
map global goto r '<esc>: lsp-references<ret>' -docstring 'references'
# LLM-Integration (FIM + smartcat)
source "%val{config}/llm.kak"
source "%val{config}/modules/ui.kak"
source "%val{config}/modules/editing.kak"
source "%val{config}/modules/mappings.kak"
source "%val{config}/modules/filetypes.kak"
source "%val{config}/modules/lsp.kak"
source "%val{config}/modules/debug.kak"
source "%val{config}/modules/llm.kak"
+5
View File
@@ -0,0 +1,5 @@
evaluate-commands %sh{
command -v kak-debug >/dev/null || exit 0
kak-debug init --session "$kak_session"
printf "%s\n" "map global user d ':enter-user-mode dap<ret>' -docstring 'DAP mode'"
}
+7
View File
@@ -0,0 +1,7 @@
set-option global tabstop 4
set-option global indentwidth 4
set-option global scrolloff 1,3
hook global BufWritePre .* %{
try %{ execute-keys -draft '%@' }
}
+19
View File
@@ -0,0 +1,19 @@
declare-option -hidden str-list filetype_modules
define-command -hidden -params 1 filetype-module-load %{
evaluate-commands %sh{
ft="$1"
file="$kak_config/filetypes/$ft.kak"
[ -f "$file" ] || exit 0
for loaded in $kak_opt_filetype_modules; do
[ "$loaded" = "$ft" ] && exit 0
done
printf 'set-option -add global filetype_modules %%{%s}\n' "$ft"
printf 'source %%{%s}\n' "$file"
printf 'try %%{ filetype-%s }\n' "$ft"
}
}
hook global WinSetOption filetype=(.+) %{
filetype-module-load %val{hook_param_capture_1}
}
+46
View File
@@ -0,0 +1,46 @@
declare-option str llm_ctx "/tmp/kak-fim.buf"
declare-option str llm_gen "/tmp/kak-gen.out"
define-command fim-complete -docstring "FIM-Completion am Cursor (Mistral)" %{
write -force %opt{llm_ctx}
execute-keys "!python3 %val{config}/scripts/mistral-fim.py %opt{llm_ctx} %val{cursor_line} %val{cursor_column}<ret>"
}
map global user f ': fim-complete<ret>' -docstring 'FIM complete'
define-command -params 1 gen -docstring 'LLM: Codeblock generieren & einfügen' %{
write -force %opt{llm_ctx}
nop %sh{
{ printf 'Anweisung: %s\n\nVorhandener Code als Kontext:\n' "$1"
cat "$kak_opt_llm_ctx"; } | sc default > "$kak_opt_llm_gen"
}
execute-keys "!cat %opt{llm_gen}<ret>"
}
map global user G ': gen ""<left>' -docstring 'Codeblock generieren'
define-command -params 1 gen-sel -docstring 'LLM: Selektion neu generieren' %{
nop %sh{
printf 'Anweisung: %s\n\nCode:\n%s' "$1" "$kak_selection" \
| sc default > "$kak_opt_llm_gen"
}
execute-keys "|cat %opt{llm_gen}<ret>"
}
map global user g ': gen-sel ""<left>' -docstring 'Selektion neu generieren'
define-command -params 1 ask -docstring 'LLM-Frage zum Buffer' %{
write -force %opt{llm_ctx}
evaluate-commands %sh{
ans=$( { printf 'Frage: %s\n\nCode:\n' "$1"; cat "$kak_opt_llm_ctx"; } \
| sc ask | sed "s/'/''/g")
printf "info -title 'Le Chat' '%s'" "$ans"
}
}
map global user A ': ask ""<left>' -docstring 'Ask about the buffer'
define-command -params 1 ask-sel -docstring 'LLM-Frage zur Selektion' %{
evaluate-commands %sh{
ans=$(printf 'Frage: %s\n\nCode:\n%s' "$1" "$kak_selection" \
| sc ask | sed "s/'/''/g")
printf "info -title 'Le Chat' '%s'" "$ans"
}
}
map global user a ': ask-sel ""<left>' -docstring 'Ask about selection'
+5
View File
@@ -0,0 +1,5 @@
evaluate-commands %sh{
command -v kak-lsp >/dev/null || exit 0
kak-lsp --kakoune -s "$kak_session"
printf '%s\n' 'lsp-enable'
}
+13
View File
@@ -0,0 +1,13 @@
map -docstring "yank the selection into the clipboard" global user y "<a-|> wl-copy<ret>"
map -docstring "paste the clipboard" global user p "<a-!> wl-paste<ret>"
map -docstring "Show filetype" global user t ': echo %opt{filetype}<ret>'
map -docstring "Open file" global user o ': tmux-repl-vertical "echo ""evaluate-commands -client %val{client} e $(fzf)"" | kak -p %val{session}"<ret>'
map -docstring "Zeile auskommentieren" global normal <C-l> ":comment-line<ret>"
map -docstring "Speichern" global normal <C-s> ":w<ret>"
map -docstring "Beenden" global normal <C-q> ":q<ret>"
map -docstring "Cursor nach oben erweitern" global normal <C-k> "<a-C><ret>"
map -docstring "Cursor nach unten erweitern" global normal <C-j> "<C><ret>"
map global normal <C-up> '|echo "$(($kak_selection + 1))"<ret>'
map global normal <C-down> '|echo "$(($kak_selection - 1))"<ret>'
+8
View File
@@ -0,0 +1,8 @@
colorscheme mygruvbox
add-highlighter global/ number-lines -hlcursor
add-highlighter global/ wrap -word -indent -marker ">>>"
add-highlighter global/ show-whitespaces
set-option -add global ui_options terminal_status_on_top=true
set-option -add global ui_options terminal_assistant=cat
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
import json, os, sys, urllib.request
buf, line, col = sys.argv[1], int(sys.argv[2]), int(sys.argv[3])
CTX_BEFORE, CTX_AFTER = 120, 60 # Kontext-Budget in Zeilen
lines = open(buf, encoding="utf-8").read().split("\n")
before, cur, after = lines[:line-1], (lines[line-1] if line-1 < len(lines) else ""), lines[line:]
prefix = "\n".join(before + [cur[:col-1]])
suffix = "\n".join([cur[col-1:]] + after)
prefix = "\n".join(prefix.split("\n")[-CTX_BEFORE:]) # nach hinten kappen
suffix = "\n".join(suffix.split("\n")[:CTX_AFTER])
body = json.dumps({
"model": "codestral-latest",
"prompt": prefix, "suffix": suffix,
"max_tokens": 96, "temperature": 0.2,
}).encode()
req = urllib.request.Request(
"https://api.mistral.ai/v1/fim/completions", data=body,
headers={"Authorization": "Bearer " + os.environ["MISTRAL_API_KEY"],
"Content-Type": "application/json"})
try:
with urllib.request.urlopen(req, timeout=20) as r:
sys.stdout.write(json.load(r)["choices"][0]["message"]["content"])
except Exception:
pass # fail silent → leeres Insert