aboutsummaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/marks.kak18
-rw-r--r--autoload/repl.kak102
2 files changed, 71 insertions, 49 deletions
diff --git a/autoload/marks.kak b/autoload/marks.kak
index 2f58c22..e1f7d72 100644
--- a/autoload/marks.kak
+++ b/autoload/marks.kak
@@ -1,3 +1,11 @@
+define-command marks-select -params 1 %{
+ evaluate-commands %sh{
+ mark=$("$kak_config/scripts/marks.fnl" get "${1:-0}")
+ [ -z "$mark" ] || echo "edit $mark"
+ }
+ marks-show
+}
+
define-command marks-add -params 1..2 %{
nop %sh{ "$kak_config/scripts/marks.fnl" add "$1" "$2" }
marks-show
@@ -29,17 +37,9 @@ define-command marks-show %{
}
}
-define-command marks-switch -params 1 %{
- evaluate-commands %sh{
- mark=$("$kak_config/scripts/marks.fnl" get "${1:-0}")
- [ -z "$mark" ] || echo "edit $mark"
- }
- marks-show
-}
-
declare-user-mode marks
map global user a ': enter-user-mode-with-count marks<ret>' -docstring 'Marks mode'
-map global user <space> ': marks-switch %val{count}<ret>' -docstring 'Switch marks'
+map global user <space> ': marks-select %val{count}<ret>' -docstring 'Select marks'
map global marks a ': marks-add %val{buffile} %opt{user_mode_count}<ret>' -docstring 'Create new mark from buffer'
map global marks d ': marks-delete %val{buffile}<ret>' -docstring 'Delete mark'
map global marks C ': marks-clear<ret>' -docstring 'Clear mark'
diff --git a/autoload/repl.kak b/autoload/repl.kak
index 3317e9f..10c2367 100644
--- a/autoload/repl.kak
+++ b/autoload/repl.kak
@@ -1,4 +1,17 @@
+declare-user-mode repl
+map global normal <c-t> ': enter-user-mode repl<ret>' -docstring 'Repl mode'
+map global repl <tab> ': enter-user-mode repl-mode-select<ret>' -docstring 'Select repl'
+map global repl <c-t> ': xrepl-begin<ret>' -docstring 'Start repl'
+map global repl t ': xrepl-begin<ret>' -docstring 'Start repl'
+map global repl l ': xrepl-send-command<ret>' -docstring 'Send to selection to repl'
+map global repl <ret> ': xrepl-send-paragraph<ret>' -docstring 'Send paragraph to repl'
+map global repl r ': xrepl-send-keys Enter<ret>' -docstring 'Send return key to repl'
+map global repl c ': xrepl-send-keys C-c<ret>' -docstring 'Send Ctrl+c interrupt to repl'
+map global repl p ': xrepl-send-prompt<ret>' -docstring 'Prompt for text to send to repl'
+map global repl q ': xrepl-quit<ret>' -docstring 'Quit repl'
+
declare-option bool xrepl_running false;
+declare-option str xrepl_current_name;
declare-option str xrepl_current_cmd;
declare-option str xrepl_current_transform;
declare-option bool xrepl_current_clear_screen false;
@@ -7,46 +20,67 @@ declare-option bool xrepl_current_clear_screen false;
# 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 3 %{
+define-command define-repl-mode -params 4 %{
# TODO: USe a hidden command and use for keymap
- map global repl-mode-select %arg{1} -docstring %arg{2} %sh{
+ 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>"
+ printf ": set global xrepl_current_name '$3'<ret>"
+ printf ": set global xrepl_current_cmd \"\$SHELL\"<ret>"
printf ": set global xrepl_current_transform \"\"<ret>"
printf ": set global xrepl_current_clear_screen false<ret>"
- printf ": evaluate-commands $(kak_escape "$(echo "$3" | tr '\n' ';')")<ret>"
+ printf ": evaluate-commands $(kak_escape "$(echo "$4" | tr '\n' ';')")<ret>"
+ # echo "$4" >> foobarity
+ # echo "$(kak_escape "$(echo "$4" | tr '\n' ';')")" >> foobarity
printf ": xrepl-begin<ret>"
}
}
-define-repl-mode n 'Node' %{
- set global xrepl_current_cmd 'node'
-}
-define-repl-mode s 'Shell' %{
- set global xrepl_current_cmd '$SHELL'
-}
-# TODO: Only cd inside sh
-define-repl-mode 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-repl-mode 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 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
+ }
}
-define-repl-mode a 'AI: Local' %{
- set global xrepl_current_cmd 'aichat'
+
+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
+ }
}
-define-repl-mode g 'AI: Gemini' %{
- set global xrepl_current_cmd 'gemini'
+
+hook global BufSetOption filetype=(?:javascript|typescript|jsx|tsx) %{
+ 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 %{
@@ -92,22 +126,10 @@ 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 "set-option global xrepl_running true"
echo "repl-new -l 45% $init_cmd"
echo "nop %sh{ tmux last-pane }"
fi
}
}
-
-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> ': xrepl-send-paragraph<ret>'
-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 p ': xrepl-send-prompt<ret>'
-map global repl <tab> ': enter-user-mode repl-mode-select<ret>'
-