[ESS] save commands to .Rhistory?

Vitalie Spinu spinuvit.list at gmail.com
Mon Jul 11 17:28:27 CEST 2011


Marianne Promberger <marianne.promberger at kcl.ac.uk> writes:

> Dear list,
>
> In an R process buffer in Emacs/ESS, I can cycle through the history
> of previous commands with C-uparrow.
>
> But the history only contains commands entered directly in the R
> process buffer. Commands sent from a command file to the process eg
> via C-c C-c do not get added to the history.
>

Hi Marianne,

This was discussed before. And as far as I could remember everyone seems to
agree that inputing all the commands into the history is a bad idea. Think
about sending regions or  function definitions.

What is meaningful though is that the command specifically designed to send
R-commands one by one - ess-eval-line-and-step (C-c C-n) - should input the
command into the history.

Fortunately it's easy to modify ess-eval-line-and-step to achieve what you
want. Put this into your .emacs:


(defun ess-eval-line-and-step (&optional simple-next even-empty invisibly)
  "Evaluate the current line visibly and step to the \"next\" line.
\"next\" = the next line with non-comment code _unless_ SIMPLE-NEXT is non-nil,
possibly via prefix arg.  If 2nd arg EVEN-EMPTY [prefix as well],
also send empty lines.	When the variable `ess-eval-empty' is non-nil
both SIMPLE-NEXT and EVEN-EMPTY are interpreted as true."
  ;; From an idea by Rod Ball (rod at marcam.dsir.govt.nz)
  (interactive "P\nP"); prefix sets BOTH !
  (save-excursion
    (ess-force-buffer-current "Process to load into: ")
    (let ((string (buffer-substring (point-at-bol) (point-at-eol))))
      ;; go to end of process buffer so user can see result
      (with-current-buffer (process-buffer (get-process ess-current-process-name))
        (comint-add-to-input-history string))
      (ess-eval-linewise string
			 invisibly 'eob (or even-empty ess-eval-empty))))
  (if (or simple-next ess-eval-empty)
      (forward-line 1)
    (ess-next-code-line 1)))


You can bind it to something more handy:

(define-key ess-mode-map [(control meta ?j)]   'ess-eval-line-and-step)

Cheers,
Vitalie.


> The same pattern holds for which commands are, or are not, in the
> local .Rhistory file after q().
>
> I would like commands sent from an external command file to show up in
> the history, too.
>
> Possible?
>
> Thanks,
>
> Marianne



More information about the ESS-help mailing list