diff options
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/+init.kak | 5 | ||||
| -rw-r--r-- | autoload/git.kak | 36 | ||||
| -rw-r--r-- | autoload/repl.kak | 64 |
3 files changed, 93 insertions, 12 deletions
diff --git a/autoload/+init.kak b/autoload/+init.kak index d2a4233..66374c4 100644 --- a/autoload/+init.kak +++ b/autoload/+init.kak @@ -33,6 +33,7 @@ add-highlighter global/ show-matching -previous hook global RegisterModified '/' %{ add-highlighter -override global/search regex "%reg{/}" 0:search } map global user '<esc>' ':set-register slash ""<ret>' map global user '/' '/(?i)' +map global user 'r' '*%s<ret>' # Preserve count for user modes (look for alternatives) # TODO: Reset count on modechange? @@ -56,13 +57,15 @@ hook global ModeChange .*:insert:.* %{ try %{ # Tmux window mode declare-user-mode win map global normal <c-w> ':enter-user-mode win<ret>' -docstring 'Window mode' -map global win q ':quit<ret>' -docstring 'Find files' +map global win q ':quit<ret>' -docstring 'Quit' map global win v ':tmux-terminal-horizontal kak -c %val{session}<ret>' -docstring 'Split vertical' map global win s ':tmux-terminal-vertical kak -c %val{session}<ret>' -docstring 'Split horizontal' map global win h ':nop %sh{tmux select-pane -L}<ret>' -docstring 'Jump left' map global win j ':nop %sh{tmux select-pane -D}<ret>' -docstring 'Jump down' map global win k ':nop %sh{tmux select-pane -U}<ret>' -docstring 'Jump up' map global win l ':nop %sh{tmux select-pane -R}<ret>' -docstring 'Jump right' +map global win z ':wq<ret>' + # Clipboard management mappings map global user y "<a-|> xclip -selection clipboard<ret>" -docstring "yank the selection into the clipboard" diff --git a/autoload/git.kak b/autoload/git.kak index 86f6d76..6f4015c 100644 --- a/autoload/git.kak +++ b/autoload/git.kak @@ -1,26 +1,40 @@ -define-command gitui -params .. %{ connect terminal env "EDITOR=kcr edit" gitu %arg{@} } +define-command gitui -params .. %{ + connect terminal env "EDITOR=kak -c %val{session}" "VISUAL=kak -c %val{session}" gitu %arg{@} +} declare-user-mode git -map global user g ':enter-user-mode git<ret>' -docstring 'Git mode' -map global git s ':gitui<ret>' -docstring 'Git tui' -map global git A ':git add %val{buffile}<ret>' -docstring 'Add file' -map global git c ':git add commit<ret>' -docstring 'Commit' -map global git C ':git add commit --amend<ret>' -docstring 'Amend commit' +map global user g ': enter-user-mode git<ret>' -docstring 'Git mode' +map global git s ': gitui<ret>' -docstring 'Git tui' +map global git A ': git add %val{buffile}<ret>' -docstring 'Add file' +map global git c ': git add commit<ret>' -docstring 'Commit' +map global git C ': git add commit --amend<ret>' -docstring 'Amend commit' # Hunk -map global git n ':git next-hunk<ret>' -docstring 'Next hunk' -map global git p ':git prev-hunk<ret>' -docstring 'Previous hunk' +map global git n ': git next-hunk<ret>' -docstring 'Next hunk' +map global git p ': git prev-hunk<ret>' -docstring 'Previous hunk' +map global git h ': git-toggle-diff<ret>' -docstring 'Toggle hunk indicators' set-option global git_diff_add_char "+" set-option global git_diff_del_char "-" set-option global git_diff_mod_char "~" set-option global git_diff_top_char "^" +define-command git-toggle-diff %{ + try %{ remove-highlighter window/git-diff } catch %{ git show-diff } +} + +# TODO: Toggle this hook global -group git-diff-if-repo EnterDirectory .* %{ - # TODO: Disable git hunk highlight for non-git repos remove-hooks global git-diff - hook global -group git-diff ModeChange .*:.*:normal %{ try %{git show-diff} } - hook global -group git-diff WinCreate .* %{ try %{git show-diff} } + evaluate-commands %sh{ + if (git rev-parse --is-inside-work-tree >/dev/null 2>&1); then + echo " + hook global -group git-diff ModeChange .*:.*:normal %{ try %{git update-diff} } + hook global -group git-diff WinCreate .* %{ try %{git update-diff} } + hook global -group git-diff BufReload .* %{ try %{git update-diff} } + " + fi + } } # Git window actions diff --git a/autoload/repl.kak b/autoload/repl.kak new file mode 100644 index 0000000..31922f0 --- /dev/null +++ b/autoload/repl.kak @@ -0,0 +1,64 @@ +declare-option str xrepl_init_cmd "$SHELL"; +declare-option str xrepl_input_transform; +declare-option bool xrepl_running false; + +declare-option str-list xrepl_modes; + +set-option -add global xrepl_modes "node" +declare-option str xrepl_init_cmd_node "node" + +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)'" + } +} + +define-command xrepl-send-command %{ + evaluate-commands %sh{ + value="$kak_selection" + if ! [ -z "$kak_xrepl_input_transform" ]; then + value=$(echo "$value" | "$kak_xrepl_input_transform") + fi + echo "repl-send-text %{$value}" + } +} + +define-command xrepl-send-keys -params 1.. %{ + 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"; + } } +} + +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 }" + echo "set-option global xrepl_running true" + 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> '<a-i>p: xrepl-send-command<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>' |
