Trying to run Kakoune repl with st and dwm

Hi,

Since some time I try to use the repl-functions of Kakoune. I am working with dwm and with st as terminal-emulator and would like to use the Repl of R. Though :repl works quite well (at least if I am invoking a R-Repl) I run into problems if I try to send texts to said repl via :send-text. I select some text inside the kak-buffer, run :send-text and nothing appears in my repl-window.

Examining the debug-buffer I find the following error:

shell stderr: <<<
There are no windows in the stack
Invalid window '%1'
Usage: windowactivate [options] [window=%1]
--sync    - only exit once the window is active (is visible + active)
If no window is given, %1 is used. See WINDOW STACK in xdotool(1)
>>>

I examined a little bit the x11.kak and tried to model the process in the shell. So I invoked the following couple of commands:

printf %s\\n "3+4" | xsel -i
set wid=$(xdotool getactivewindow)
xdotool search --name kak_repl_window windowactivate
xdotool key --clearmodifiers "Shift+Insert"

I see that here, the string piped in xsel is not pasted in the aforementioned window but in the primary one. So I guess that here the error lies… he does not seem to activate the window (though he seems to detect it correctly). Does someone know how to fix that?

I am working on a Pinebook pro in Manjaro Linux and use Kakoune v2020.01.16.

Thanks in advance!

You can try to send the key to a specific window with the --window parameter, so that you do not rely on windowactivate to send the key.

You can also merge the xdotool calls into a single one to leverage the window stack.

xdotool search --name kak_repl_window windowactivate --sync key --clearmodifiers Shift+Insert
1 Like

Thanks alot, I can now send commands to the repl-window! the only thing I am currently noticing is that it takes quite a while (approximately 15 seconds) until the strings are being sent. If I activate the repl-window (i.e. move my mouse above that one) the process gets greatly accelerated, though.

If I had to guess, I’d say that maybe xdotool is politely asking dwm to activate a particular window through some mechanism that dwm doesn’t implement because it’s aggressively minimalist, and then after a timeout xdotool tries to do the same thing less politely. Moving your mouse over the target window probably tricks xdotool into thinking its polite request worked.

However, looking at the xdotool manpage it looks like you don’t strictly need to activate a window in order to send keys to it. Does this command-line work?

xdotool search --name kak_repl_window key --clearmodifiers Shift+Insert

(i.e. without windowactivate --sync, causing key to target the window found by search)

2 Likes

The windowactivate command looks to not be needed yep. The search command saves the result in the window stack, and the key command sends keys to the window in the stack or the active window if there is no stack.

1 Like

Great, without windowactivate it goes now as fast as lightning! Thanks alot!

@PgieseQS Do you mind sending a PR for the fix?

Done, hope everything is ok (did it on my commute to work).

1 Like