"Press" key inside an interactive function
I need to programmatically press a key inside an interactive function. Here's a diagram of what I have so far:
(defun answer-to-life-the-universe-and-everything ()
(interactive)
(insert "(* 6 7)")
;; Need to automagically press the RETURN key here
)
My use case: In the REPL buffer, I often need to execute a long command. I can use the above code to create an interactive function that inserts the line I want, but I still need to press RETURN manually for the REPL to read it. Terminating the line with \ n or \ r won't do what I need.
How can I do this inside my interactive function definition?
source to share
The easiest way to do this is to find out which command has a key enter
in the REPL, and then call that command in your interactive function. (To find out, go to the REPL buffer and press C-h k <return>
.)
For example, it is enter
attached to inferior-ess-send-input
when using the R
REPL through ess
, so this command inserts a line and hits enter:
(defun try-this ()
(interactive)
(insert "print(\"hi\")")
(inferior-ess-send-input))
source to share