From 0df6be4992b4d8e38990ea3c63286fef9532410b Mon Sep 17 00:00:00 2001 From: Gokcehan Kara Date: Sun, 24 Jan 2016 15:18:14 +0200 Subject: [PATCH] add basic support for repl interaction in x11 Define x11-repl command that optionally takes the name of an interpreter to start it on a new window. Users then can select some text in the editor and use [x11-]send-text command to send it to the interpreter. Ideally the latter command should be bound to a key for easier interaction. Requires xsel and xdotool to work. --- rc/x11.kak | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/rc/x11.kak b/rc/x11.kak index f485a416..63c052c1 100644 --- a/rc/x11.kak +++ b/rc/x11.kak @@ -30,6 +30,28 @@ def -docstring 'create a new kak client for current session' \ setsid ${kak_opt_termcmd} "kak -c ${kak_session} ${kakoune_params}" < /dev/null > /dev/null 2>&1 & }} +def -docstring 'create a new window for repl interaction' \ + -params 0..1 \ + -command-completion \ + x11-repl %{ %sh{ + if [ -z "${kak_opt_termcmd}" ]; then + echo "echo -color Error 'termcmd option is not set'" + exit + fi + if [ $# -eq 0 ]; then cmd="bash"; else cmd="$1"; fi + setsid ${kak_opt_termcmd} ${cmd} -t kak_repl_window < /dev/null > /dev/null 2>&1 & +}} + +def x11-send-text -docstring "send selected text to the repl window" %{ + %sh{ + echo "${kak_selection}" | xsel -i + wid=$(xdotool getactivewindow) + xdotool search --name kak_repl_window windowactivate + xdotool key --clearmodifiers "Shift+Insert" + xdotool windowactivate $wid + } +} + def -docstring 'focus given client\'s window' \ -params 0..1 -client-completion \ x11-focus %{ %sh{ @@ -44,3 +66,5 @@ def -docstring 'focus given client\'s window' \ alias global focus x11-focus alias global new x11-new +alias global repl x11-repl +alias global send-text x11-send-text