Browse Source

fixed ob-python to work with newest Emacs

* lisp/ob-python.el (org-babel-python-with-earmufs): Add earmufs to a
  buffer name.
  (org-babel-python-without-earmufs): Remove earmufs from a buffer name.
  (org-babel-python-initiate-session-by-key): Set the buffer name in a
  way which is understandable by the new python.el
Eric Schulte 12 years ago
parent
commit
993e3ee621
1 changed files with 20 additions and 3 deletions
  1. 20 3
      lisp/ob-python.el

+ 20 - 3
lisp/ob-python.el

@@ -157,6 +157,20 @@ Emacs-lisp table, otherwise return the results as a string."
   "Return the buffer associated with SESSION."
   (cdr (assoc session org-babel-python-buffers)))
 
+(defun org-babel-python-with-earmufs (session)
+  (let ((name (if (stringp session) session (format "%s" session))))
+    (if (and (string= "*" (substring name 0 1))
+	     (string= "*" (substring name (- (length name) 1))))
+	name
+      (format "*%s*" name))))
+
+(defun org-babel-python-without-earmufs (session)
+  (let ((name (if (stringp session) session (format "%s" session))))
+    (if (and (string= "*" (substring name 0 1))
+	     (string= "*" (substring name (- (length name) 1))))
+	(substring name 1 (- (length name) 1))
+      name)))
+
 (defvar py-default-interpreter)
 (defun org-babel-python-initiate-session-by-key (&optional session)
   "Initiate a python session.
@@ -170,8 +184,11 @@ then create.  Return the initialized session."
        ((and (eq 'python org-babel-python-mode)
 	     (fboundp 'run-python)) ; python.el
 	(if (version< "24.1" emacs-version)
-	    (let ((python-shell-buffer-name python-buffer))
-	      (run-python org-babel-python-command))
+	    (progn
+	      (unless python-buffer (org-babel-python-with-earmufs session))
+	      (let ((python-shell-buffer-name
+		     (org-babel-python-without-earmufs python-buffer)))
+		(run-python org-babel-python-command)))
 	  (run-python)))
        ((and (eq 'python-mode org-babel-python-mode)
 	     (fboundp 'py-shell)) ; python-mode.el
@@ -187,7 +204,7 @@ then create.  Return the initialized session."
 			  (concat "Python-" (symbol-name session))))
 	       (py-which-bufname bufname))
 	  (py-shell)
-	  (setq python-buffer (concat "*" bufname "*"))))
+	  (setq python-buffer (org-babel-python-earmufs bufname))))
        (t
 	(error "No function available for running an inferior Python")))
       (setq org-babel-python-buffers