[ESS] save commands to .Rhistory?
Vitalie Spinu
spinuvit.list at gmail.com
Fri Jul 15 11:03:03 CEST 2011
Dear Maruanne,
It should definitely work. Make sure you put the code after you load ess.
If not, tell me what is the command which is bound to C-up, (it
should be comint-previous-input). To see that, press C-h k C-up.
I also recommend using comint-previous-matching-input-from-input
instead of comint-previous-input. It looks only for those commands in
history which match some characters at begining of the line. For
instance if you have somewhere deep in history 'print("something")'
and you input 'pr" and invoke the command, it will find the
print("somehting").
I have it bound to M-p:
(define-key comint-mode-map [(meta ?p)]
'comint-previous-matching-input-from-input)
(define-key comint-mode-map [(meta ?n)]
'comint-next-matching-input-from-input)
Vitalie.
On Thu, Jul 14, 2011 at 6:40 PM, Marianne Promberger
<marianne.promberger at kcl.ac.uk> wrote:
> 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