mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.94k stars 716 forks source link

repl-send-text sends text to the Kakoune client's terminal, not the REPL terminal (X11/dwm) #4050

Open malte-v opened 3 years ago

malte-v commented 3 years ago
  1. Open a new repl (repl-new ghci)
  2. A new terminal window with the specified REPL opens
  3. Move focus back to the Kakoune client and execute repl-send-text isometext
  4. "sometext" appears in the Kakoune buffer; REPL prompt remains empty; no new messages in the *debug* buffer; dwm highlights the currently active tag (like it highlights the tag with the webbrowser when you click on a link in another program)

Kakoune rev: 26cf5cd1dce362a34593fcf5994c961f8aa53bc0 (latest master at the time of writing) Window manager: dwm in X11 Terminal emulator: Alacritty

Screwtapello commented 3 years ago

The :x11-repl-send-text command (which is the implementation of repl-send-text that's used outside tmux and the kitty terminal emulator) works by copying the text to the X11 clipboard, switching the keyboard focus to the target terminal, and sending a <s-insert> keypress to paste the text from the clipboard into the terminal. If your window manager doesn't allow programs to switch the keyboard focus, the X11 REPL mode is never going to work for you.

Instead, you might like to try running Kakoune inside tmux (to use the tmux REPL implementation), inside kitty (another OpenGL accelerated terminal emulator like Alacritty), or a third-party plugin like kakoune-repl-buffer which tries to provide a REPL inside a Kakoune buffer rather than trying to interface with an external terminal emulator.

malte-v commented 3 years ago

I think the problem is that Alacritty somehow doesn't respond to the Shift+Insert keystroke sent from the script. The following works for me:

xdotool type --window <window id of the REPL terminal> --delay 000000.1 "<expression to be evaluated>"
xdotool key --window <window id of the REPL terminal> Return

Upside is that it doesn't use the clipboard, downside is that it literally types the expression into the terminal; Alacritty can handle a "1 nanosecond" delay though (I doubt that it is actually one nanosecond, but whatever).

Correction: Alacritty does react to Shift+Insert when typed from a physical keyboard, but not when simulated by xdotool. Other keys, like Return, work fine.