aboutsummaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2026-03-21 23:03:12 +0530
committerAkshay Nair <phenax5@gmail.com>2026-03-21 23:03:12 +0530
commita7d4c8d5ca59d977642b04688869d98632f1805d (patch)
treea3ef215481fc43d9443365c318ff507e8464ffd9 /autoload
parenta88e917a5f1e089397b3b0e759d0a7e60d6cf8ca (diff)
downloadkakoune-config-a7d4c8d5ca59d977642b04688869d98632f1805d.tar.gz
kakoune-config-a7d4c8d5ca59d977642b04688869d98632f1805d.zip
Fix repl module + refactor custom modes
Diffstat (limited to 'autoload')
-rw-r--r--autoload/repl/repl.kak (renamed from autoload/repl.kak)119
-rw-r--r--autoload/repl/repl_modes.kak67
-rw-r--r--autoload/snippets/typescript.kak9
3 files changed, 129 insertions, 66 deletions
diff --git a/autoload/repl.kak b/autoload/repl/repl.kak
index d7b43d9..bd47a67 100644
--- a/autoload/repl.kak
+++ b/autoload/repl/repl.kak
@@ -11,7 +11,7 @@ map global repl p ': xrepl-send-prompt<ret>' -docstring 'Prompt for text to send
map global repl q ': xrepl-quit<ret>' -docstring 'Quit repl'
declare-option bool xrepl_running false;
-# declare-option int xrepl_tmux_repl_id;
+declare-option str xrepl_tmux_id;
declare-option str xrepl_current_name;
declare-option str xrepl_current_cmd;
declare-option str xrepl_current_transform;
@@ -19,15 +19,28 @@ declare-option str xrepl_current_split_size;
declare-option bool xrepl_current_split_vertical false;
declare-option bool xrepl_current_clear_screen false;
+# TODO: "Custom" repl mode
# TODO: Use register set to selection (paragraph) instead of selection
# TODO: Add env
-# TODO: Migrate curly
# TODO: Preserve original selection with send paragraph
-# TODO: Sometimes repl stops working (tmux repl id changed?)
declare-user-mode repl-mode-select
define-command define-repl-mode -params 4 %{
# TODO: Use a hidden command and use for keymap
+ # define-command %sh{ echo "repl-mode--$2" } %{
+ # xrepl-quit
+ # set global xrepl_current_name %arg{3}
+ # set global xrepl_current_cmd "$SHELL"
+ # set global xrepl_current_transform ""
+ # set global xrepl_current_split_size '45%'
+ # set global xrepl_current_split_vertical false
+ # set global xrepl_current_clear_screen false
+ # evaluate-commands %sh{
+ # kak_escape() { printf "'"; printf '%s' "$1" | sed "s/'/''/g"; printf "'"; }
+ # kak_escape "$(echo "$4" | tr '\n' ';')"
+ # }
+ # xrepl-begin
+ # }
map %arg{1} repl-mode-select %arg{2} -docstring %arg{3} %sh{
kak_escape() { printf "'"; printf '%s' "$1" | sed "s/'/''/g"; printf "'"; }
printf ": xrepl-quit<ret>"
@@ -42,63 +55,8 @@ define-command define-repl-mode -params 4 %{
}
}
-define-repl-mode global s 'Shell' %{ set global xrepl_current_cmd '$SHELL' }
-define-repl-mode global n 'Node' %{ set global xrepl_current_cmd 'node' }
-define-repl-mode global a 'AI: Local' %{ set global xrepl_current_cmd 'aichat' }
-define-repl-mode global g 'AI: Gemini' %{ set global xrepl_current_cmd 'gemini' }
-
-hook global BufSetOption filetype=haskell %{
- define-repl-mode buffer h 'Haskell: cabal test' %{
- set global xrepl_current_cmd 'cabal test'
- set global xrepl_current_clear_screen true
- }
-}
-
-hook global BufSetOption filetype=ruby %{
- define-repl-mode buffer r 'Rspec' %{
- # TODO: Make generic
- set global xrepl_current_cmd 'docker compose exec shape-api -T sh'
- set global xrepl_current_transform 'cat > /dev/null
- path="$kak_buffile"
- if [ $kak_cursor_line -gt 5 ]; then
- path="$path:$kak_cursor_line"
- fi
- echo "rspec -fd $path"
- '
- set global xrepl_current_clear_screen true
- }
-}
-
-hook global BufSetOption filetype=clojure %{
- # TODO: Just temporary for messing around. Remove module name
- map buffer repl r ': repl-send-text %{(require ''[pluribus.core :as p] :reload)}; xrepl-send-keys Enter<ret>' -docstring 'Cljs reload'
- define-repl-mode buffer j 'Clojurescript repl' %{
- set global xrepl_current_cmd 'clj -M -m cljs.main --repl-opts "{:launch-browser false}" --compile pluribus.core --repl'
- set global xrepl_current_split_size 30%%
- set global xrepl_current_split_vertical true
- }
-}
-
-hook global BufSetOption filetype=(?:javascript|typescript|jsx|tsx) %{
- # TODO: Search for root cypress config file and cd into it
- define-repl-mode buffer c 'Cypress' %{
- set global xrepl_current_cmd '$SHELL'
- set global xrepl_current_transform 'cat > /dev/null
- echo "npx cypress run --headless --e2e --spec ''$kak_buffile'';"
- '
- set global xrepl_current_clear_screen true
- }
- define-repl-mode global j 'Jest' %{
- set global xrepl_current_cmd '$SHELL'
- set global xrepl_current_transform 'cat > /dev/null
- echo "sh -c \\"cd ''$(dirname "$kak_buffile")''; npx jest --runTestsByPath ''$kak_buffile''\\";"
- '
- set global xrepl_current_clear_screen true
- }
-}
-
define-command xrepl-send-prompt %{
- prompt -buffer-completion 'Send to repl: ' %{ repl-send-text %val{text} }
+ prompt -buffer-completion 'Send to repl: ' %{ xrepl-send-text %val{text} }
}
define-command xrepl-send-command %{
@@ -110,10 +68,11 @@ define-command xrepl-send-command %{
transform="$kak_opt_xrepl_current_transform"
value="$kak_selection"
if ! [ -z "$transform" ]; then
- export kak_buffile kak_selection kak_selection_desc kak_cursor_line kak_cursor_column
+ # Available values in transform script
+ export kak_buffile kak_selection kak_selection_desc kak_cursor_line kak_cursor_column kak_config
value=$(echo "$kak_selection" | sh -c "$transform")
fi
- echo -e "repl-send-text %{$value\n}"
+ echo -e "xrepl-send-text %{$value\n}"
}
}
@@ -123,14 +82,14 @@ define-command xrepl-send-paragraph %{
}
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_xrepl_tmux_id" "$@" }
}
define-command xrepl-quit %{
set-option global xrepl_running false
try %{ nop %sh{
- if ! [ -z "$kak_opt_tmux_repl_id" ]; then
- tmux kill-pane -t "$kak_opt_tmux_repl_id";
+ if ! [ -z "$kak_opt_xrepl_tmux_id" ]; then
+ tmux kill-pane -t "$kak_opt_xrepl_tmux_id";
fi
} }
}
@@ -140,11 +99,39 @@ define-command xrepl-begin %{
if [ "$kak_opt_xrepl_running" = "false" ]; then
init_cmd="$kak_opt_xrepl_current_cmd"
if [ -z "$init_cmd" ]; then init_cmd="$SHELL"; fi
- echo "info %opt{xrepl_current_name}"
+ # echo "info %opt{xrepl_current_name}"
echo "set-option global xrepl_running true"
- cmd=$([ "$kak_opt_xrepl_current_split_vertical" == "true" ] && echo "tmux-repl-vertical" || echo "tmux-repl-horizontal")
+ cmd=$([ "$kak_opt_xrepl_current_split_vertical" == "true" ] && echo "tmux-xrepl-vertical" || echo "tmux-xrepl-horizontal")
echo "$cmd -l $kak_opt_xrepl_current_split_size $init_cmd"
echo "nop %sh{ tmux last-pane }"
fi
}
}
+
+define-command -hidden -params 1.. tmux-xrepl-impl %{
+ evaluate-commands %sh{
+ if [ -z "$TMUX" ]; then
+ echo 'fail This command is only available in a tmux session'
+ exit
+ fi
+ tmux_args="split-window $1 -t ${kak_client_env_TMUX_PANE}"
+ shift
+ repl_pane_id=$(tmux $tmux_args -P -F '#{pane_id}' "$@")
+ printf "set-option current xrepl_tmux_id '%s'" "$repl_pane_id"
+ }
+}
+
+define-command tmux-xrepl-vertical -params 0.. %{ tmux-xrepl-impl '-v' %arg{@} }
+define-command tmux-xrepl-horizontal -params 0.. %{ tmux-xrepl-impl '-h' %arg{@} }
+
+define-command xrepl-send-text -params 0..1 %{
+ evaluate-commands %sh{
+ if [ $# -eq 0 ]; then
+ tmux set-buffer -b kak_selection -- "${kak_selection}"
+ else
+ tmux set-buffer -b kak_selection -- "$1"
+ fi
+ tmux paste-buffer -b kak_selection -t "$kak_opt_xrepl_tmux_id" ||
+ echo 'fail tmux-send-text: failed to send text, see *debug* buffer for details'
+ }
+}
diff --git a/autoload/repl/repl_modes.kak b/autoload/repl/repl_modes.kak
new file mode 100644
index 0000000..f059789
--- /dev/null
+++ b/autoload/repl/repl_modes.kak
@@ -0,0 +1,67 @@
+define-repl-mode global s 'Shell' %{ set global xrepl_current_cmd '$SHELL' }
+define-repl-mode global n 'Node' %{ set global xrepl_current_cmd 'node' }
+define-repl-mode global a 'AI: Claude' %{ set global xrepl_current_cmd 'claude' }
+
+# TODO: doesnt work
+# define-repl-mode global C 'Custom' %{
+# prompt -shell-completion 'Command: ' '
+# set global xrepl_current_cmd "node"
+# '
+# }
+
+hook global BufSetOption filetype=haskell %{
+ define-repl-mode buffer h 'Haskell: cabal test' %{
+ set global xrepl_current_cmd 'cabal test'
+ set global xrepl_current_clear_screen true
+ }
+}
+
+hook global BufSetOption filetype=ruby %{
+ # TODO: Make generic
+ define-repl-mode buffer c 'Rails console' %{
+ set global xrepl_current_cmd "just server-rails c"
+ }
+ define-repl-mode buffer r 'Rspec' %{
+ set global xrepl_current_cmd '$SHELL'
+ set global xrepl_current_transform 'cat > /dev/null
+ path="$kak_buffile"
+ if [ $kak_cursor_line -gt 5 ]; then
+ path="$path:$kak_cursor_line"
+ fi
+ KAK_BUNDLE_EXEC=${KAK_BUNDLE_EXEC:-"bundle exec"}
+ echo "$KAK_BUNDLE_EXEC rspec -fd $path"
+ '
+ set global xrepl_current_clear_screen true
+ }
+}
+
+hook global BufSetOption filetype=(?:javascript|typescript|jsx|tsx) %{
+ # TODO: Search for root cypress config file and cd into it
+ # set global xrepl_current_cmd '(echo "::$kak_config::" | tee foob) && '
+ define-repl-mode buffer c 'Cypress' %{
+ set global xrepl_current_cmd '$SHELL'
+ set global xrepl_current_transform 'cat > /dev/null
+ cypress_config_files="cypress.config.json cypress.config.ts cypress.config.js"
+ project=$($kak_config/scripts/utils.sh find_closest "$kak_buffile" $cypress_config_files)
+ echo "npx cypress run --headless --e2e -P" "''$project''" "--spec ''$kak_buffile'';"
+ '
+ set global xrepl_current_clear_screen true
+ }
+ define-repl-mode global j 'Jest' %{
+ set global xrepl_current_cmd '$SHELL'
+ set global xrepl_current_transform 'cat > /dev/null
+ echo "sh -c \\"cd ''$(dirname "$kak_buffile")''; npx jest --runTestsByPath ''$kak_buffile''\\";"
+ '
+ set global xrepl_current_clear_screen true
+ }
+}
+
+hook global BufSetOption filetype=clojure %{
+ # TODO: Just temporary for messing around. Remove module name
+ map buffer repl r ': xrepl-send-text %{(require ''[pluribus.core :as p] :reload)}; xrepl-send-keys Enter<ret>' -docstring 'Cljs reload'
+ define-repl-mode buffer j 'Clojurescript repl' %{
+ set global xrepl_current_cmd 'clj -M -m cljs.main --repl-opts "{:launch-browser false}" --compile pluribus.core --repl'
+ set global xrepl_current_split_size 30%%
+ set global xrepl_current_split_vertical true
+ }
+}
diff --git a/autoload/snippets/typescript.kak b/autoload/snippets/typescript.kak
index f2d3e8f..4b17109 100644
--- a/autoload/snippets/typescript.kak
+++ b/autoload/snippets/typescript.kak
@@ -1,6 +1,7 @@
hook global BufSetOption filetype=(?:javascript|typescript|jsx|tsx) %{
define-snippet buffer snip-react-component
define-snippet buffer snip-react-usestate
+ define-snippet buffer snip-function
}
define-command snip-react-usestate %{
@@ -25,3 +26,11 @@ define-command snip-react-component %{
execute-keys "<ret>};<esc>kwlt;"
}
}
+
+define-command snip-function %{
+ prompt 'Name: ' %{
+ execute-keys "<esc>,iconst %val{text} = () => {<ret>"
+ execute-keys " return 0;"
+ execute-keys "<ret>};<esc>kwlt;"
+ }
+}