[ESS] Eval line or region from r-help mails in gnus buffers.
Vitaly S.
spinuvit.list at gmail.com
Fri Aug 6 14:51:04 CEST 2010
Dear ESS community,
I've just wrote a function to evaluate line or region directly from
the r-help mails (in my case gnus article buffers).
Here it is, in case anyone else is interested in this sort of behavior.
(defun ess-eval-line-or-region-gnus ()
"Evaluate a line or a region from r-help gnus article, depending on whether
the selection is active. Cleans the region/line with
ess-transcript-clean-buffer first. Works from any buffer in emacs."
(interactive)
(save-excursion
(let ((is-region (and transient-mark-mode mark-active)))
(let ((start (if is-region (region-beginning)
(line-beginning-position)))
(end (if is-region (region-end)
(line-end-position)))
(curbuff (current-buffer))
(tbuf (get-buffer-create "*ess.gnus.trns*")))
(set-buffer tbuf)
(R-transcript-mode)
(toggle-read-only -1)
(mark-whole-buffer)
(delete-region (mark) (point))
(insert-buffer-substring curbuff start end)
(goto-char (point-min))
(while (re-search-forward "^>[> +]+" nil t)
(replace-match "> "))
(ess-transcript-clean-buffer)
(ess-eval-buffer nil)
)
)
)
(goto-char (region-end))
(move-beginning-of-line 2)
(ess-show-buffer (buffer-name (process-buffer (get-ess-process ess-current-process-name t))))
)
Bind it to C-j
(define-key gnus-article-mode-map [(control j)] 'ess-eval-line-or-region-gnus)
Cheers,
Vitaly.
More information about the ESS-help
mailing list