Fix org-babel-R-initiate-session

* lisp/ob-R.el (org-babel-R-initiate-session): handle case where the
  session buffer exists, but does not have a live process

If the session buffer exists, but the user has exited the R process
manually, then the (R) command will create a new buffer, then try to
rename it over the old buffer, causing an error.  The right thing to do
is to start R within the existing buffer.
This commit is contained in:
Aaron Ecay 2013-04-01 01:42:15 -04:00 committed by Eric Schulte
parent 2f39a704cf
commit fe98647f14
1 changed files with 12 additions and 8 deletions

View File

@ -209,14 +209,18 @@ This function is called by `org-babel-execute-src-block'."
(if (org-babel-comint-buffer-livep session) (if (org-babel-comint-buffer-livep session)
session session
(save-window-excursion (save-window-excursion
(require 'ess) (R) (save-excursion
(rename-buffer (when (get-buffer session)
(if (bufferp session) ;; Session buffer exists, but with dead process
(buffer-name session) (set-buffer session))
(if (stringp session) (require 'ess) (R)
session (rename-buffer
(buffer-name)))) (if (bufferp session)
(current-buffer)))))) (buffer-name session)
(if (stringp session)
session
(buffer-name))))
(current-buffer)))))))
(defun org-babel-R-associate-session (session) (defun org-babel-R-associate-session (session)
"Associate R code buffer with an R session. "Associate R code buffer with an R session.