summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Davison <davison@stats.ox.ac.uk>2010-08-18 14:07:13 -0400
committerDan Davison <davison@stats.ox.ac.uk>2010-08-18 15:13:57 -0400
commit23ab61d93c1c1fd99851c9a3438cdf0064f7e886 (patch)
tree789426a8f670ec6de45c6185beb0bfb70e2514f0
parentad7d9c43c821ef19839442fa543cc1ccef7a3689 (diff)
downloadorg-mode-23ab61d93c1c1fd99851c9a3438cdf0064f7e886.tar.gz
babel: refactor `org-babel-switch-to-session'
* ob.el (org-babel-initiate-session): new function derived from previous `org-babel-switch-to-session' (org-babel-switch-to-session): refactored to use new `org-babel-initiate-session' This breaks the original `org-babel-switch-to-session' into a new function `org-babel-initiate-session' and `org-babel-switch-to-session'.
-rw-r--r--lisp/ob.el31
1 files changed, 19 insertions, 12 deletions
diff --git a/lisp/ob.el b/lisp/ob.el
index 596c859..8557f09 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -434,11 +434,11 @@ session."
(end-of-line 1)))
;;;###autoload
-(defun org-babel-switch-to-session (&optional arg info)
- "Switch to the session of the current source-code block.
+(defun org-babel-initiate-session (&optional arg info)
+ "Initiate session for current code block.
If called with a prefix argument then evaluate the header arguments
-for the source block before entering the session. Copy the body
-of the source block to the kill ring."
+for the code block before entering the session. Copy the body
+of the code block to the kill ring."
(interactive "P")
(let* ((info (or info (org-babel-get-src-block-info)))
(lang (nth 0 info))
@@ -454,16 +454,23 @@ of the source block to the kill ring."
(error "This block is not using a session!"))
(unless (fboundp cmd)
(error "No org-babel-initiate-session function for %s!" lang))
- ;; copy body to the kill ring
(with-temp-buffer (insert (org-babel-trim body))
(copy-region-as-kill (point-min) (point-max)))
- ;; if called with a prefix argument, then process header arguments
- (unless (fboundp cmd2)
- (error "No org-babel-prep-session function for %s!" lang))
- (when arg (funcall cmd2 session params))
- ;; just to the session using pop-to-buffer
- (pop-to-buffer (funcall cmd session params))
- (end-of-line 1)))
+ (when arg
+ (unless (fboundp cmd2)
+ (error "No org-babel-prep-session function for %s!" lang))
+ (funcall cmd2 session params))
+ (funcall cmd session params)))
+
+;;;###autoload
+(defun org-babel-switch-to-session (&optional arg info)
+ "Switch to the session of the current code block.
+Uses `org-babel-initiate-session' to start the session. If called
+with a prefix argument then this is passed on to
+`org-babel-initiate-session'."
+ (interactive "P")
+ (pop-to-buffer (org-babel-initiate-session arg info))
+ (end-of-line 1))
(defalias 'org-babel-pop-to-session 'org-babel-switch-to-session)