aboutsummaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/+init.kak41
-rw-r--r--autoload/formatter.kak19
-rw-r--r--autoload/repl.kak73
3 files changed, 104 insertions, 29 deletions
diff --git a/autoload/+init.kak b/autoload/+init.kak
index 3857043..4c71b83 100644
--- a/autoload/+init.kak
+++ b/autoload/+init.kak
@@ -1,11 +1,11 @@
# Link builtin autoloads
nop %sh{ ln -s "$kak_runtime/rc" "$kak_config/autoload/standard-library" 2>/dev/null || true }
-# evaluate-commands %sh{kak-tree-sitter -dksvv --init "${kak_session}"}
evaluate-commands %sh{kcr init kakoune}
hook global KakBegin .* %{
require-module luar
set-option global luar_interpreter luajit
+ # evaluate-commands %sh{kak-tree-sitter -dksvv --init "${kak_session}" --with-highlighting --with-text-objects}
}
colorscheme phenax
@@ -16,10 +16,7 @@ set-option global tabstop 2
set-option global path -add "**"
set-option global startup_info_version 20250603
set-option global scrolloff 10,3
-set-option global makecmd 'make -j8' # Override for others
-set-option -add global ui_options \
- terminal_enable_mouse=false
- # terminal_assistant=none \
+set-option -add global ui_options terminal_enable_mouse=false terminal_set_title=true
set-option global modelinefmt \
'{StatusLineDetails}{{context_info}} {{mode_info}}
%val{cursor_line}/%val{buf_line_count}:%val{cursor_char_column}
@@ -33,6 +30,7 @@ add-highlighter global/ line '%val{cursor_line}' RowLine
add-highlighter global/ regex \h+$ 0:Error # Highlight trailing whitespaces
add-highlighter global/ wrap -word -indent # Softwrap long lines
add-highlighter global/ show-matching -previous
+add-highlighter global/ show-whitespaces -spc ' ' -tab '│' -tabpad 'y' -lf '¬' -indent '│'
# Search
hook global RegisterModified '/' %{ add-highlighter -override global/search regex "%reg{/}" 0:search }
@@ -40,6 +38,12 @@ map global user '<esc>' ': set-register slash ""<ret>'
map global user '/' '/(?i)'
map global user 'r' '*%s<ret>'
+declare-user-mode system
+map global user q ': enter-user-mode system<ret>' -docstring 'System mode'
+map global system o ': echo %opt{}<left>'
+map global system v ': echo %val{}<left>'
+map global system d ': buffer *debug*<ret>'
+
# Preserve count for user modes (look for alternatives)
# TODO: Reset count on modechange?
declare-option -hidden int user_mode_count 0
@@ -49,7 +53,6 @@ define-command enter-user-mode-with-count -params 1 %{
}
# Mode cursors
-set-face global InsertCursor default,red+B
hook global ModeChange .*:.*:insert %{
set-face window PrimaryCursor InsertCursor
set-face window PrimaryCursorEol InsertCursor
@@ -79,6 +82,7 @@ map global user p "<a-!> xclip -selection clipboard -o<ret>" -docstring "paste t
declare-user-mode code
map global user c ':enter-user-mode code<ret>' -docstring 'Code mode'
map global code c :comment-line<ret> -docstring 'Comment/uncomment lines'
+map global code f :format<ret> -docstring 'Format buffer'
def casecamel %{ exec '`s[-_<space>]<ret>d~<a-i>w' }
def casesnake %{ exec '<a-:><a-;>s-|[a-z][A-Z]<ret>;a<space><esc>s[-\s]+<ret>c_<esc><a-i>w`' }
def casekebab %{ exec '<a-:><a-;>s_|[a-z][A-Z]<ret>;a<space><esc>s[_\s]+<ret>c-<esc><a-i>w`' }
@@ -94,3 +98,28 @@ map global normal <c-k> 15k
hook global BufOpenFile .* %{ try %{editorconfig-load} }
hook global BufNewFile .* %{ try %{editorconfig-load} }
+declare-user-mode surround
+declare-user-mode surround-append
+declare-user-mode surround-delete
+map global user s ': enter-user-mode surround<ret>'
+map global surround a ': enter-user-mode surround-append<ret>'
+map global surround d ': enter-user-mode surround-delete<ret>'
+
+define-command define-surround -params 3 %{
+ evaluate-commands %sh{
+ echo "map global surround-append %{${1}} %{i${2}<esc>a${3}}"
+ echo "map global surround-delete %{${1}} %{<a-a>${2}<a-S>d,}"
+ }
+}
+
+# hook global KakBegin .* %{
+# define-surround ( ( )
+# define-surround [ [ ]
+# # define-surround < < >
+# # define-surround '{' '{' '}'
+# # define-surround '<' '<' '>'
+# # define-surround '`' '`' '`'
+# define-surround '"' '"' '"'
+# # define-surround "'" "'" "'"
+# }
+
diff --git a/autoload/formatter.kak b/autoload/formatter.kak
new file mode 100644
index 0000000..741e9e8
--- /dev/null
+++ b/autoload/formatter.kak
@@ -0,0 +1,19 @@
+# TODO: Use a single hook?
+hook global BufSetOption filetype=json %{ set-option buffer formatcmd "jq" }
+hook global BufSetOption filetype=fennel %{ set-option buffer formatcmd "fnlfmt -" }
+hook global BufSetOption filetype=nix %{ set-option buffer formatcmd "nixfmt -" }
+hook global BufSetOption filetype=(?:javascript|typescript) %{
+ evaluate-commands %sh{
+ if [ -f "$PWD/biome.json" ]; then
+ echo "set-option buffer formatcmd %{npx biome check --fix --stdin-file-path=$kak_buffile 2>/dev/null}"
+ fi
+ }
+}
+hook global BufSetOption filetype=(?:ruby) %{
+ evaluate-commands %sh{
+ if [ -f "$PWD/.rubocop.yml" ]; then
+ echo "set-option buffer formatcmd %{rubocop -x --stderr -s '$kak_buffile'}"
+ fi
+ }
+}
+
diff --git a/autoload/repl.kak b/autoload/repl.kak
index 31922f0..f5dacef 100644
--- a/autoload/repl.kak
+++ b/autoload/repl.kak
@@ -1,54 +1,80 @@
-declare-option str xrepl_init_cmd "$SHELL";
-declare-option str xrepl_input_transform;
+declare-option str xrepl_mode_config;
declare-option bool xrepl_running false;
+declare-option str-to-str-map xrepl_modes;
-declare-option str-list xrepl_modes;
-
-set-option -add global xrepl_modes "node"
-declare-option str xrepl_init_cmd_node "node"
+set-option -add global xrepl_modes %{node={
+ "cmd": "node"
+}}
+set-option -add global xrepl_modes %{shell={
+ "cmd": "$SHELL",
+ "transform": "echo 'echo 123 $foooo :: \\$kak_buffile :: \\$kak_selection :: \\$kak_seletion_desc'"
+}}
define-command xrepl-set-mode -params 1 %{
xrepl-quit
- evaluate-commands %sh{
- cmd="$(eval echo "\$kak_opt_xrepl_init_cmd_$1")"
- input_transform="$(eval echo "\$kak_opt_xrepl_input_transform_$1")"
- echo "info %{$kak_opt_xrepl_init_cmd_node; $cmd:$input_transform}"
- if [ -z "$cmd" ]; then cmd="$SHELL"; fi
- if [ -z "$input_transform" ]; then input_transform=""; fi
- echo "set global xrepl_init_cmd '$(printf '%q' $cmd)'"
- echo "set global xrepl_input_transform '$(printf '%q' $input_transform)'"
+ # TODO: This preevaluates the params in transform.
+ fennel %arg{1} %opt{xrepl_modes} %{
+ (local [mode & modestxt] [(args)])
+ (each [_ val (ipairs modestxt)]
+ (local (key config) (string.match val "^%s*([^=]*)=(.*)$"))
+ (kak.info config)
+ (when (= key mode)
+ (kak.set "global" "xrepl_mode_config" config)))
+ }
+ xrepl-begin
+}
+
+define-command xrepl-select %{
+ fennel %opt{xrepl_modes} %{
+ (local modes [(args)])
+ (local modenames [])
+ (each [_ val (ipairs modes)]
+ (local (key _config) (string.match val "^%s*([^=]*)=(.*)$"))
+ (when key (table.insert modenames key)))
+ (local compl (.. "echo -e \"" (table.concat modenames "\n") "\""))
+ (kak.prompt :-menu
+ :-shell-script-candidates compl
+ "repl mode: "
+ "xrepl-set-mode %val{text}")
}
}
define-command xrepl-send-command %{
evaluate-commands %sh{
+ transform="$(echo "$kak_opt_xrepl_mode_config" | jq -rj '.transform? // ""')"
value="$kak_selection"
- if ! [ -z "$kak_xrepl_input_transform" ]; then
- value=$(echo "$value" | "$kak_xrepl_input_transform")
+ if ! [ -z "$transform" ]; then
+ export kak_buffile="$kak_buffile"
+ export kak_selection="$kak_selection"
+ export kak_selection_desc="$kak_selection_desc"
+ value=$(echo "$value" | foooo=qwe sh -c "$transform")
fi
+ echo "info %{$value//$transform\n$kak_opt_xrepl_mode_config}"
echo "repl-send-text %{$value}"
}
}
define-command xrepl-send-keys -params 1.. %{
- nop %sh{ tmux send-keys -t "$kak_opt_tmux_repl_id" "$@" }
+ nop %sh{ tmux send-keys -t "$kak_opt_tmux_repl_id" "$@" }
}
define-command xrepl-quit %{
set-option global xrepl_running false
try %{ nop %sh{
- [ -z "$kak_opt_tmux_repl_id" ] && exit 0;
- tmux kill-pane -t "$kak_opt_tmux_repl_id";
+ if ! [ -z "$kak_opt_tmux_repl_id" ]; then
+ tmux kill-pane -t "$kak_opt_tmux_repl_id";
+ fi
} }
}
define-command xrepl-begin %{
- # TODO: Open if not running
evaluate-commands %sh{
if [ "$kak_opt_xrepl_running" = "false" ]; then
- echo "repl-new %opt{xrepl_init_cmd}"
- echo "nop %sh{ tmux last-pane }"
+ init_cmd="$(echo "$kak_opt_xrepl_mode_config" | jq -rj '.cmd? // ""')"
+ if [ -z "$init_cmd" ]; then init_cmd="$SHELL"; fi
echo "set-option global xrepl_running true"
+ echo "repl-new $init_cmd"
+ echo "nop %sh{ tmux last-pane }"
fi
}
}
@@ -57,8 +83,9 @@ declare-user-mode repl
map global normal <c-t> ': enter-user-mode repl<ret>'
map global repl <c-t> ': xrepl-begin<ret>'
map global repl t ': xrepl-begin<ret>'
-map global repl <ret> '<a-i>p: xrepl-send-command<ret>'
+map global repl <ret> '<c-s><a-i>p: xrepl-send-command<ret><c-o>'
map global repl l ': xrepl-send-command<ret>'
map global repl r ': xrepl-send-keys Enter<ret>'
map global repl c ': xrepl-send-keys C-c<ret>'
map global repl q ': xrepl-quit<ret>'
+map global repl <tab> ': xrepl-select<ret>'