[ESS] save commands to .Rhistory?

Marianne Promberger marianne.promberger at kcl.ac.uk
Thu Jul 14 18:40:23 CEST 2011


Hi Vitalie,

Vitalie Spinu <spinuvit.list at gmail.com> 11-Jul-11 16:28:
> Marianne Promberger <marianne.promberger at kcl.ac.uk> writes:

> > 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.
>
> [...]
> Fortunately it's easy to modify ess-eval-line-and-step to achieve what you
> want. Put this into your .emacs:
>
> [Cont'd below]

Many thanks. I've added to my ~/.emacs and it partly works. It puts
things into .Rhistory but they are not immediately available in the R
process buffer with C-uparrow.

This is already a step forward but getting it to work with C-uparrow
would be even better, in case anyone knows.

Thanks

Marianne


> (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

-- 
Marianne Promberger PhD
King's College London
London SE1 9RT
GnuPG/PGP public key ID 80AD9916
.tex .bib .R .Rnw files welcome
Times for meetings: http://promberger.info/plan



More information about the ESS-help mailing list