User manual

Chapter 4: Interacting with the ESS process 28
4.3 Command History
ESS provides easy-to-use facilities for re-executing or editing previous commands. An input
history of the last few commands is maintained (by default the last 500 commands are
stored, although this can be changed by setting the variable comint-input-ring-size in
inferior-ess-mode-hook.) The simplest history commands simply select the next and
previous commands in the input history:
M-p comint-previous-input Select the previous command in the input history.
M-n comint-next-input Select the next command in the input history.
For example, pressing M-p once will re-enter the last command into the process buffer after
the prompt but does not send it to the ESS process, thus allowing editing or correction of
the command before the ESS process sees it. Once corrections have been made, press RET
to send the edited command to the ESS process.
If you want to select a particular command from the history by matching it against a
regular expression (see Section “Syntax of Regular Expression” in The GNU Emacs Refer-
ence Manual), to search for a particular variable name for example, these commands are
also available:
M-r comint-history-isearch-backward-regexp Prompt for a regular expression,
and search backwards through the input history for a command matching the
expression.
A common type of search is to find the last command that began with a particular sequence
of characters; the following two commands provide an easy way to do this:
C-c M-r comint-previous-matching-input-from-input Select the previous command
in the history which matches the string typed so far.
C-c M-s comint-next-matching-input-from-input Select the next command in the
history which matches the string typed so far.
Instead of prompting for a regular expression to match against, as they instead select
commands starting with those characters already entered. For instance, if you wanted to
re-execute the last attach() command, you may only need to type att and then C-c M-r
and RET.
See Section “Shell History Ring” in The GNU Emacs Reference Manual, for a more
detailed discussion of the history mechanism, and do experiment with the In/Out menu to
explore the possibilities.
Many ESS users like to have even easier access to these, and recommend to add something
like
(eval-after-load "comint"
’(progn
(define-key comint-mode-map [up]
’comint-previous-matching-input-from-input)
(define-key comint-mode-map [down]
’comint-next-matching-input-from-input)
;; also recommended for ESS use --