From 1e8107faf725e287a2b648618a46d65e2ed24eaa Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 11 Jan 2010 08:47:29 -0700 Subject: [PATCH 1/2] babel: improve doc strings for org-babel-execute-buffer and org-babel-execute-subtree --- contrib/babel/lisp/org-babel.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/org-babel.el index 74bf596cd..e3ce6b114 100644 --- a/contrib/babel/lisp/org-babel.el +++ b/contrib/babel/lisp/org-babel.el @@ -294,7 +294,8 @@ results already exist." t))) (defun org-babel-execute-buffer (&optional arg) - "Replace EVAL snippets in the entire buffer." + "Call `org-babel-execute-src-block' on every source block in +the current buffer." (interactive "P") (save-excursion (goto-char (point-min)) @@ -304,7 +305,8 @@ results already exist." (goto-char (match-end 0))))) (defun org-babel-execute-subtree (&optional arg) - "Replace EVAL snippets in the entire subtree." + "Call `org-babel-execute-src-block' on every source block in +the current subtree." (interactive "P") (save-excursion (org-narrow-to-subtree) From aa72dfc54ff544ce152d429051865382f954e745 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 11 Jan 2010 10:14:30 -0700 Subject: [PATCH 2/2] 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 f9e0d0048..1fe282625 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 baed606e2..79edfbc4e 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 b896a340e..2053f3e8d 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 aceb41ae7..388fa655a 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 1bea4e684..27de42f4a 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 2caaa0e64..129323a72 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