I would like to work in ESS/R in emacs in a way similar to term mode. That is, I don't want the cursor move away from the command line when I try to copy some text from the R console. Also I would like to rebind the up arrow key to previous command.
1 Answers
Your way
The "previous" and "next" commands use respectively comint-previous-input
and comint-next-input
functions. They can be mapped to up
and down
arrow key:
(define-key comint-mode-map [up] 'comint-previous-input)
(define-key comint-mode-map [down] 'comint-next-input)
I am not aware of a solution to lock the cursor while a copy/paste.
If you really want a console behavior, maybe you should simply use a console as it will fit your wishes.
Bonus: the default Emacs way
I do not use R
, but I use octave
, clojure
and also bash
in Emacs. All these repl (Read–eval–print loop) behave the same way. For example, the arrow keys will simply move your cursor.
Here is a brief overview of my usage of a repl:
M->
will bring me to the bottom of the bufferC-<up>
will cycle along previous commandsC-<down>
will cycle along next commandsC-r
keywords
will search backward in the buffer. If the cursor is on a previous command,<enter>
will re-execute the command- for copy/paste I do not use the mouse, but
M-w
(copy) andC-y
(paste) where the cursor is.M-y
will replace your paste by previous copied entries.
Maybe, it changes your habits or shortcuts from other desktop applications. However, on the bright side, these repl behaves in a consistent way in Emacs. Each time you use a repl, these keys will do the job as intended.