From aa72dfc54ff544ce152d429051865382f954e745 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 11 Jan 2010 10:14:30 -0700 Subject: [PATCH] babel: implement org-babel-load-session:* for R, clojure, gnuplot, python, ruby and sh --- contrib/babel/lisp/langs/org-babel-R.el | 12 +++++++++++- contrib/babel/lisp/langs/org-babel-clojure.el | 9 +++++++++ contrib/babel/lisp/langs/org-babel-gnuplot.el | 17 ++++++++++++++--- contrib/babel/lisp/langs/org-babel-python.el | 12 +++++++++++- contrib/babel/lisp/langs/org-babel-ruby.el | 13 +++++++++++-- contrib/babel/lisp/langs/org-babel-sh.el | 12 +++++++++++- 6 files changed, 67 insertions(+), 8 deletions(-) diff --git a/contrib/babel/lisp/langs/org-babel-R.el b/contrib/babel/lisp/langs/org-babel-R.el index f9e0d004..1fe28262 100644 --- a/contrib/babel/lisp/langs/org-babel-R.el +++ b/contrib/babel/lisp/langs/org-babel-R.el @@ -59,7 +59,17 @@ called by `org-babel-execute-src-block'." "Prepare SESSION according to the header arguments specified in PARAMS." (let* ((session (org-babel-R-initiate-session session)) (vars (org-babel-ref-variables params))) - (mapc (lambda (pair) (org-babel-R-assign-elisp session (car pair) (cdr pair))) vars))) + (mapc (lambda (pair) (org-babel-R-assign-elisp session (car pair) (cdr pair))) vars) + session)) + +(defun org-babel-load-session:R (session body params) + "Load BODY into SESSION." + (save-window-excursion + (let ((buffer (org-babel-prep-session:R session params))) + (with-current-buffer buffer + (goto-char (process-mark (get-buffer-process (current-buffer)))) + (insert (org-babel-chomp body))) + buffer))) ;; helper functions diff --git a/contrib/babel/lisp/langs/org-babel-clojure.el b/contrib/babel/lisp/langs/org-babel-clojure.el index baed606e..79edfbc4 100644 --- a/contrib/babel/lisp/langs/org-babel-clojure.el +++ b/contrib/babel/lisp/langs/org-babel-clojure.el @@ -140,6 +140,15 @@ specifying a var of the same value." vars))) session-buf)) +(defun org-babel-load-session:clojure (session body params) + "Load BODY into SESSION." + (save-window-excursion + (let ((buffer (org-babel-prep-session:clojure session params))) + (with-current-buffer buffer + (goto-char (point-max)) + (insert (org-babel-chomp body))) + buffer))) + (defvar org-babel-clojure-buffers '()) (defvar org-babel-clojure-pending-sessions '()) diff --git a/contrib/babel/lisp/langs/org-babel-gnuplot.el b/contrib/babel/lisp/langs/org-babel-gnuplot.el index b896a340..2053f3e8 100644 --- a/contrib/babel/lisp/langs/org-babel-gnuplot.el +++ b/contrib/babel/lisp/langs/org-babel-gnuplot.el @@ -143,14 +143,25 @@ called by `org-babel-execute-src-block'." "Prepare SESSION according to the header arguments specified in PARAMS." (let* ((session (org-babel-gnuplot-initiate-session session)) (vars (org-babel-ref-variables params)) - (var-lines (mapconc + (var-lines (mapcar (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair))) vars))) + (message "%S" session) (org-babel-comint-in-buffer session (mapc (lambda (var-line) (insert var-line) (comint-send-input nil t) (org-babel-comint-wait-for-output session) - (sit-for .1) (goto-char (point-max))) var-lines)))) + (sit-for .1) (goto-char (point-max))) var-lines)) + session)) + +(defun org-babel-load-session:gnuplot (session body params) + "Load BODY into SESSION." + (save-window-excursion + (let ((buffer (org-babel-prep-session:gnuplot session params))) + (with-current-buffer buffer + (goto-char (process-mark (get-buffer-process (current-buffer)))) + (insert (org-babel-chomp body))) + buffer))) (defun org-babel-gnuplot-initiate-session (&optional session) "If there is not a current inferior-process-buffer in SESSION @@ -158,7 +169,7 @@ then create. Return the initialized session. The current `gnuplot-mode' doesn't provide support for multiple sessions." (unless (string= session "none") (save-window-excursion (gnuplot-send-string-to-gnuplot "" "line") - (current-buffer)))) + gnuplot-buffer))) (defun org-babel-gnuplot-quote-timestamp-field (s) "Convert field S from timestamp to Unix time and export to gnuplot." diff --git a/contrib/babel/lisp/langs/org-babel-python.el b/contrib/babel/lisp/langs/org-babel-python.el index aceb41ae..388fa655 100644 --- a/contrib/babel/lisp/langs/org-babel-python.el +++ b/contrib/babel/lisp/langs/org-babel-python.el @@ -69,7 +69,17 @@ called by `org-babel-execute-src-block'." (org-babel-comint-in-buffer session (mapc (lambda (var) (move-end-of-line 1) (insert var) (comint-send-input nil t) - (org-babel-comint-wait-for-output session)) var-lines)))) + (org-babel-comint-wait-for-output session)) var-lines)) + session)) + +(defun org-babel-load-session:python (session body params) + "Load BODY into SESSION." + (save-window-excursion + (let ((buffer (org-babel-prep-session:python session params))) + (with-current-buffer buffer + (goto-char (process-mark (get-buffer-process (current-buffer)))) + (insert (org-babel-chomp body))) + buffer))) ;; helper functions diff --git a/contrib/babel/lisp/langs/org-babel-ruby.el b/contrib/babel/lisp/langs/org-babel-ruby.el index 1bea4e68..27de42f4 100644 --- a/contrib/babel/lisp/langs/org-babel-ruby.el +++ b/contrib/babel/lisp/langs/org-babel-ruby.el @@ -76,13 +76,22 @@ called by `org-babel-execute-src-block'." (car pair) (org-babel-ruby-var-to-ruby (cdr pair)))) vars))) - ;; (message "vars=%S" vars) ;; debugging (org-babel-comint-in-buffer session (sit-for .5) (goto-char (point-max)) (mapc (lambda (var) (insert var) (comint-send-input nil t) (org-babel-comint-wait-for-output session) - (sit-for .1) (goto-char (point-max))) var-lines)))) + (sit-for .1) (goto-char (point-max))) var-lines)) + session)) + +(defun org-babel-load-session:ruby (session body params) + "Load BODY into SESSION." + (save-window-excursion + (let ((buffer (org-babel-prep-session:ruby session params))) + (with-current-buffer buffer + (goto-char (process-mark (get-buffer-process (current-buffer)))) + (insert (org-babel-chomp body))) + buffer))) ;; helper functions diff --git a/contrib/babel/lisp/langs/org-babel-sh.el b/contrib/babel/lisp/langs/org-babel-sh.el index 2caaa0e6..129323a7 100644 --- a/contrib/babel/lisp/langs/org-babel-sh.el +++ b/contrib/babel/lisp/langs/org-babel-sh.el @@ -66,7 +66,17 @@ function is called by `org-babel-execute-src-block'." (org-babel-comint-in-buffer session (mapc (lambda (var) (insert var) (comint-send-input nil t) - (org-babel-comint-wait-for-output session)) var-lines)))) + (org-babel-comint-wait-for-output session)) var-lines)) + session)) + +(defun org-babel-load-session:sh (session body params) + "Load BODY into SESSION." + (save-window-excursion + (let ((buffer (org-babel-prep-session:sh session params))) + (with-current-buffer buffer + (goto-char (process-mark (get-buffer-process (current-buffer)))) + (insert (org-babel-chomp body))) + buffer))) ;; helper functions -- 2.11.4.GIT