diff options
Diffstat (limited to 'lisp/org/ob-gnuplot.el')
| -rw-r--r-- | lisp/org/ob-gnuplot.el | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lisp/org/ob-gnuplot.el b/lisp/org/ob-gnuplot.el index 40543d720b0..053d154610b 100644 --- a/lisp/org/ob-gnuplot.el +++ b/lisp/org/ob-gnuplot.el | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | ;; Author: Eric Schulte | 5 | ;; Author: Eric Schulte |
| 6 | ;; Keywords: literate programming, reproducible research | 6 | ;; Keywords: literate programming, reproducible research |
| 7 | ;; Homepage: http://orgmode.org | 7 | ;; Homepage: http://orgmode.org |
| 8 | ;; Version: 7.01 | 8 | ;; Version: 7.3 |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 11 | 11 | ||
| @@ -68,11 +68,11 @@ code." | |||
| 68 | (car pair) ;; variable name | 68 | (car pair) ;; variable name |
| 69 | (if (listp (cdr pair)) ;; variable value | 69 | (if (listp (cdr pair)) ;; variable value |
| 70 | (org-babel-gnuplot-table-to-data | 70 | (org-babel-gnuplot-table-to-data |
| 71 | (cdr pair) (make-temp-file "org-babel-gnuplot") params) | 71 | (cdr pair) (org-babel-temp-file "gnuplot-") params) |
| 72 | (cdr pair)))) | 72 | (cdr pair)))) |
| 73 | (org-babel-ref-variables params))) | 73 | (mapcar #'cdr (org-babel-get-header params :var)))) |
| 74 | 74 | ||
| 75 | (defun org-babel-expand-body:gnuplot (body params &optional processed-params) | 75 | (defun org-babel-expand-body:gnuplot (body params) |
| 76 | "Expand BODY according to PARAMS, return the expanded body." | 76 | "Expand BODY according to PARAMS, return the expanded body." |
| 77 | (save-window-excursion | 77 | (save-window-excursion |
| 78 | (let* ((vars (org-babel-gnuplot-process-vars params)) | 78 | (let* ((vars (org-babel-gnuplot-process-vars params)) |
| @@ -118,9 +118,9 @@ code." | |||
| 118 | ;; insert variables into code body: this should happen last | 118 | ;; insert variables into code body: this should happen last |
| 119 | ;; placing the variables at the *top* of the code in case their | 119 | ;; placing the variables at the *top* of the code in case their |
| 120 | ;; values are used later | 120 | ;; values are used later |
| 121 | (add-to-body (mapconcat | 121 | (add-to-body (mapconcat #'identity |
| 122 | (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair))) | 122 | (org-babel-variable-assignments:gnuplot params) |
| 123 | vars "\n")) | 123 | "\n")) |
| 124 | ;; replace any variable names preceded by '$' with the actual | 124 | ;; replace any variable names preceded by '$' with the actual |
| 125 | ;; value of the variable | 125 | ;; value of the variable |
| 126 | (mapc (lambda (pair) | 126 | (mapc (lambda (pair) |
| @@ -141,12 +141,15 @@ This function is called by `org-babel-execute-src-block'." | |||
| 141 | (save-window-excursion | 141 | (save-window-excursion |
| 142 | ;; evaluate the code body with gnuplot | 142 | ;; evaluate the code body with gnuplot |
| 143 | (if (string= session "none") | 143 | (if (string= session "none") |
| 144 | (let ((script-file (make-temp-file "org-babel-gnuplot-script"))) | 144 | (let ((script-file (org-babel-temp-file "gnuplot-script-"))) |
| 145 | (with-temp-file script-file | 145 | (with-temp-file script-file |
| 146 | (insert (concat body "\n"))) | 146 | (insert (concat body "\n"))) |
| 147 | (message "gnuplot \"%s\"" script-file) | 147 | (message "gnuplot \"%s\"" script-file) |
| 148 | (setq output | 148 | (setq output |
| 149 | (shell-command-to-string (format "gnuplot \"%s\"" script-file))) | 149 | (shell-command-to-string |
| 150 | (format | ||
| 151 | "gnuplot \"%s\"" | ||
| 152 | (org-babel-process-file-name script-file)))) | ||
| 150 | (message output)) | 153 | (message output)) |
| 151 | (with-temp-buffer | 154 | (with-temp-buffer |
| 152 | (insert (concat body "\n")) | 155 | (insert (concat body "\n")) |
| @@ -159,10 +162,7 @@ This function is called by `org-babel-execute-src-block'." | |||
| 159 | (defun org-babel-prep-session:gnuplot (session params) | 162 | (defun org-babel-prep-session:gnuplot (session params) |
| 160 | "Prepare SESSION according to the header arguments in PARAMS." | 163 | "Prepare SESSION according to the header arguments in PARAMS." |
| 161 | (let* ((session (org-babel-gnuplot-initiate-session session)) | 164 | (let* ((session (org-babel-gnuplot-initiate-session session)) |
| 162 | (vars (org-babel-ref-variables params)) | 165 | (var-lines (org-babel-variable-assignments:gnuplot params))) |
| 163 | (var-lines (mapcar | ||
| 164 | (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair))) | ||
| 165 | vars))) | ||
| 166 | (message "%S" session) | 166 | (message "%S" session) |
| 167 | (org-babel-comint-in-buffer session | 167 | (org-babel-comint-in-buffer session |
| 168 | (mapc (lambda (var-line) | 168 | (mapc (lambda (var-line) |
| @@ -180,6 +180,12 @@ This function is called by `org-babel-execute-src-block'." | |||
| 180 | (insert (org-babel-chomp body))) | 180 | (insert (org-babel-chomp body))) |
| 181 | buffer))) | 181 | buffer))) |
| 182 | 182 | ||
| 183 | (defun org-babel-variable-assignments:gnuplot (params) | ||
| 184 | "Return list of gnuplot statements assigning the block's variables" | ||
| 185 | (mapcar | ||
| 186 | (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair))) | ||
| 187 | (org-babel-gnuplot-process-vars params))) | ||
| 188 | |||
| 183 | (defvar gnuplot-buffer) | 189 | (defvar gnuplot-buffer) |
| 184 | (defun org-babel-gnuplot-initiate-session (&optional session params) | 190 | (defun org-babel-gnuplot-initiate-session (&optional session params) |
| 185 | "Initiate a gnuplot session. | 191 | "Initiate a gnuplot session. |