Browse Source

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.
Aaron Ecay 12 years ago
parent
commit
fe98647f14
1 changed files with 12 additions and 8 deletions
  1. 12 8
      lisp/ob-R.el

+ 12 - 8
lisp/ob-R.el

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