# ──────────────────────────────────────────────────────────────────────────────
hook global BufOpenFile .* %{
modeline-parse
- editorconfig-load
}
hook global BufCreate [^*].* %{
hook global WinSetOption filetype=(makefile|gas) noexpandtab
hook global WinSetOption filetype=(c|cpp) smarttab
}
- plug "whereswaldon/shellcheck.kak"
plug "occivink/kakoune-sudo-write"
plug "occivink/kakoune-find"
plug "foot.kak"
}
+# Enable some linting and formatting
+# ──────────────────────────────────────────────────────────────────────────────
+ hook global WinSetOption filetype=js %{
+ set window formatcmd 'npx prettier --stdin-filepath $kak_buffile<ret><space>;'
+ }
+ hook global WinSetOption filetype=css %{
+ set window formatcmd 'npx prettier --parser css'
+ }
+ hook global WinSetOption filetype=scss %{
+ set window formatcmd 'npx prettier --parser scss'
+ }
+ hook global WinSetOption filetype=less %{
+ set window formatcmd 'npx prettier --parser less'
+ }
+ hook global WinSetOption filetype=html %{
+ set window formatcmd 'npx prettier --parser html'
+ }
+ hook global WinSetOption filetype=json %{
+ set window formatcmd 'npx prettier --parser json'
+ }
+ hook global WinSetOption filetype=md %{
+ set window formatcmd 'npx prettier --parser md'
+ }
+ hook global WinSetOption filetype=sh %{
+ # needs shfmt: $ go install mvdan.cc/sh/v3/cmd/shfmt@latest
+ set-option buffer formatcmd "shfmt"
+ set-option window lintcmd "shellcheck -fgcc -Cnever"
+ }
+ hook global WinSetOption filetype=yaml %{
+ set window formatcmd 'npx prettier --parser yaml'
+ set-option window lintcmd %{
+ run() {
+ # change [message-type] to message-type:
+ yamllint -f parsable "$1" | sed 's/ \[\(.*\)\] / \1: /'
+ } && run }
+ }
+
+
# Look and Feel
# ──────────────────────────────────────────────────────────────────────────────
add-highlighter global/trailing-whitespace regex '\h+$' 0:Error # trailing whitespaces in red
execute-keys -draft \%@s\h+$<ret>d
} }
# Bring back <c-a> and <c-x> from Vim to increment/decrement the number under the cursor
-define-command -hidden -params 2 inc %{ try %{
- evaluate-commands %sh{
- [ "$1" = 0 ] && count=1 || count="$1"
- printf '%s%s' 'exec h"_/\d<ret><a-i>na' "$2($count)<esc>|{<space>cat<semicolon>echo<semicolon>}|bc<ret>"
- }
-} catch %{
- execute-keys l
-}}
+# define-command -hidden -params 2 inc %{ try %{
+# evaluate-commands %sh{
+# [ "$1" = 0 ] && count=1 || count="$1"
+# printf '%s%s' 'exec h"_/\d<ret><a-i>na' "$2($count)<esc>|{<space>cat<semicolon>echo<semicolon>}|bc<ret>"
+# }
+# } catch %{
+# execute-keys l
+# }}
# Various mappings
# ──────────────────────────────────────────────────────────────────────────────
import languagecmd
-# Reload kakrc and .kak when saving.
-# ──────────────────────────────────────────────────────────────────────────────
-# Adds -override to definitions (unless they seem to be python defs!)
-# Evals provide module directly
-
-def resource -params 1 %{
- eval %sh{
- file=$(dirname "$1")/.reload.kak
- cat "$1" |
- sed 's/^def \([^:]*\)$/def -override \1/' |
- sed 's/^define-command /def -override /' |
- sed 's/^addhl /addhl -override/' |
- sed 's/^add-highlighter /addhl -override /' |
- sed 's/^provide-module \w\+ /eval /' |
- cat > "$file"
- printf %s "
- source $file
- nop %sh{
- rm $file
- }
- "
- }
- echo Reloaded %arg{1}
-}
-
-rmhooks global reload-kak
-hook -group reload-kak global BufWritePost (.*kakrc|.*\.kak) %{
- resource %val{hook_param}
-}
-