0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 22:47:56 +00:00

adding org-babel-load-in-session-maybe bound to Meta-Up (currently only for Haskell)

This commit is contained in:
Eric Schulte 2009-09-24 21:58:28 -06:00
parent 0fa8a7feac
commit 3f1be49a04
2 changed files with 37 additions and 2 deletions

View file

@ -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))))

View file

@ -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