summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2009-09-24 21:58:28 -0600
committerEric Schulte <schulte.eric@gmail.com>2009-09-24 21:58:49 -0600
commit3f1be49a04ecee2497c2f616d3aa606f96113433 (patch)
treea8a8d00ae0e167182d92bcd1187fd28efe48c179
parent0fa8a7feacbd5f0fcab697eac3f9bd9c6a4917fa (diff)
downloadorg-mode-3f1be49a04ecee2497c2f616d3aa606f96113433.tar.gz
adding org-babel-load-in-session-maybe bound to Meta-Up (currently only for Haskell)
-rw-r--r--contrib/babel/lisp/langs/org-babel-haskell.el14
-rw-r--r--contrib/babel/lisp/org-babel.el25
2 files changed, 37 insertions, 2 deletions
diff --git a/contrib/babel/lisp/langs/org-babel-haskell.el b/contrib/babel/lisp/langs/org-babel-haskell.el
index 3c788db..ab6cb71 100644
--- a/contrib/babel/lisp/langs/org-babel-haskell.el
+++ b/contrib/babel/lisp/langs/org-babel-haskell.el
@@ -87,6 +87,16 @@ then create. Return the initialized session."
;; TODO: make it possible to have multiple sessions
(run-haskell) (current-buffer))
+(defun org-babel-load-session:haskell (session body params)
+ "Load BODY into SESSION."
+ (save-window-excursion
+ (let* ((buffer (org-babel-prep-session:haskell session params))
+ (load-file (concat (make-temp-file "org-babel-haskell-load") ".hs")))
+ (with-temp-buffer
+ (insert body) (write-file load-file)
+ (haskell-mode) (inferior-haskell-load-file))
+ buffer)))
+
(defun org-babel-prep-session:haskell (session params)
"Prepare SESSION according to the header arguments specified in PARAMS."
(save-window-excursion
@@ -98,10 +108,10 @@ then create. Return the initialized session."
(car pair)
(org-babel-ruby-var-to-ruby (cdr pair))))
vars "\n"))
- (load-file (concat (make-temp-file "org-babel-haskell-load") ".hs")))
+ (vars-file (concat (make-temp-file "org-babel-haskell-vars") ".hs")))
(when vars
(with-temp-buffer
- (insert var-lines) (write-file load-file)
+ (insert var-lines) (write-file vars-file)
(haskell-mode) (inferior-haskell-load-file)))
(current-buffer))))
diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/org-babel.el
index 448c188..5a3e7f2 100644
--- a/contrib/babel/lisp/org-babel.el
+++ b/contrib/babel/lisp/org-babel.el
@@ -61,6 +61,15 @@ to `org-open-at-point'."
(interactive "P")
(or (call-interactively #'org-babel-open-src-block-result) ad-do-it))
+(defun org-babel-load-in-session-maybe ()
+ "Detect if this is context for a org-babel src-block and if so
+then run `org-babel-load-in-session'."
+ (interactive)
+ (let ((info (org-babel-get-src-block-info)))
+ (if info (progn (org-babel-load-in-session current-prefix-arg info) t) nil)))
+
+(add-hook 'org-metaup-hook 'org-babel-load-in-session-maybe)
+
(defun org-babel-pop-to-session-maybe ()
"Detect if this is context for a org-babel src-block and if so
then run `org-babel-pop-to-session'."
@@ -181,6 +190,22 @@ the header arguments specified at the source code block."
(org-babel-insert-result result result-params)
(case result-type (output nil) (value result))))
+(defun org-babel-load-in-session (&optional arg info)
+ "Load the body of the current source-code block. Evaluate the
+header arguments for the source block before entering the
+session. After loading the body this pops open the session."
+ (interactive)
+ (let* ((info (or info (org-babel-get-src-block-info)))
+ (lang (first info))
+ (body (second info))
+ (params (third info))
+ (session (cdr (assoc :session params))))
+ (unless (member lang org-babel-interpreters)
+ (error "Language is not in `org-babel-interpreters': %s" lang))
+ ;; if called with a prefix argument, then process header arguments
+ (pop-to-buffer (funcall (intern (concat "org-babel-load-session:" lang)) session body params))
+ (move-end-of-line 1)))
+
(defun org-babel-pop-to-session (&optional arg info)
"Pop to the session of the current source-code block. If
called with a prefix argument then evaluate the header arguments