diff options
Diffstat (limited to 'lisp/org/ob-gnuplot.el')
| -rw-r--r-- | lisp/org/ob-gnuplot.el | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/lisp/org/ob-gnuplot.el b/lisp/org/ob-gnuplot.el index 5d07366e774..55c415320d6 100644 --- a/lisp/org/ob-gnuplot.el +++ b/lisp/org/ob-gnuplot.el | |||
| @@ -87,46 +87,45 @@ code." | |||
| 87 | (timefmt (plist-get params :timefmt)) | 87 | (timefmt (plist-get params :timefmt)) |
| 88 | (time-ind (or (plist-get params :timeind) | 88 | (time-ind (or (plist-get params :timeind) |
| 89 | (when timefmt 1))) | 89 | (when timefmt 1))) |
| 90 | (add-to-body (lambda (text) (setq body (concat text "\n" body)))) | ||
| 90 | output) | 91 | output) |
| 91 | (flet ((add-to-body (text) | 92 | ;; append header argument settings to body |
| 92 | (setq body (concat text "\n" body)))) | 93 | (when title (funcall add-to-body (format "set title '%s'" title))) ;; title |
| 93 | ;; append header argument settings to body | 94 | (when lines (mapc (lambda (el) (funcall add-to-body el)) lines)) ;; line |
| 94 | (when title (add-to-body (format "set title '%s'" title))) ;; title | 95 | (when sets |
| 95 | (when lines (mapc (lambda (el) (add-to-body el)) lines)) ;; line | 96 | (mapc (lambda (el) (funcall add-to-body (format "set %s" el))) sets)) |
| 96 | (when sets | 97 | (when x-labels |
| 97 | (mapc (lambda (el) (add-to-body (format "set %s" el))) sets)) | 98 | (funcall add-to-body |
| 98 | (when x-labels | 99 | (format "set xtics (%s)" |
| 99 | (add-to-body | 100 | (mapconcat (lambda (pair) |
| 100 | (format "set xtics (%s)" | 101 | (format "\"%s\" %d" (cdr pair) (car pair))) |
| 101 | (mapconcat (lambda (pair) | 102 | x-labels ", ")))) |
| 102 | (format "\"%s\" %d" (cdr pair) (car pair))) | 103 | (when y-labels |
| 103 | x-labels ", ")))) | 104 | (funcall add-to-body |
| 104 | (when y-labels | 105 | (format "set ytics (%s)" |
| 105 | (add-to-body | 106 | (mapconcat (lambda (pair) |
| 106 | (format "set ytics (%s)" | 107 | (format "\"%s\" %d" (cdr pair) (car pair))) |
| 107 | (mapconcat (lambda (pair) | 108 | y-labels ", ")))) |
| 108 | (format "\"%s\" %d" (cdr pair) (car pair))) | 109 | (when time-ind |
| 109 | y-labels ", ")))) | 110 | (funcall add-to-body "set xdata time") |
| 110 | (when time-ind | 111 | (funcall add-to-body (concat "set timefmt \"" |
| 111 | (add-to-body "set xdata time") | 112 | (or timefmt |
| 112 | (add-to-body (concat "set timefmt \"" | 113 | "%Y-%m-%d-%H:%M:%S") "\""))) |
| 113 | (or timefmt | 114 | (when out-file (funcall add-to-body (format "set output \"%s\"" out-file))) |
| 114 | "%Y-%m-%d-%H:%M:%S") "\""))) | 115 | (when term (funcall add-to-body (format "set term %s" term))) |
| 115 | (when out-file (add-to-body (format "set output \"%s\"" out-file))) | 116 | ;; insert variables into code body: this should happen last |
| 116 | (when term (add-to-body (format "set term %s" term))) | 117 | ;; placing the variables at the *top* of the code in case their |
| 117 | ;; insert variables into code body: this should happen last | 118 | ;; values are used later |
| 118 | ;; placing the variables at the *top* of the code in case their | 119 | (funcall add-to-body (mapconcat #'identity |
| 119 | ;; values are used later | 120 | (org-babel-variable-assignments:gnuplot params) |
| 120 | (add-to-body (mapconcat #'identity | 121 | "\n")) |
| 121 | (org-babel-variable-assignments:gnuplot params) | 122 | ;; replace any variable names preceded by '$' with the actual |
| 122 | "\n")) | 123 | ;; value of the variable |
| 123 | ;; replace any variable names preceded by '$' with the actual | 124 | (mapc (lambda (pair) |
| 124 | ;; value of the variable | 125 | (setq body (replace-regexp-in-string |
| 125 | (mapc (lambda (pair) | 126 | (format "\\$%s" (car pair)) (cdr pair) body))) |
| 126 | (setq body (replace-regexp-in-string | 127 | vars)) |
| 127 | (format "\\$%s" (car pair)) (cdr pair) body))) | 128 | body)) |
| 128 | vars)) | ||
| 129 | body))) | ||
| 130 | 129 | ||
| 131 | (defun org-babel-execute:gnuplot (body params) | 130 | (defun org-babel-execute:gnuplot (body params) |
| 132 | "Execute a block of Gnuplot code. | 131 | "Execute a block of Gnuplot code. |
| @@ -183,7 +182,7 @@ This function is called by `org-babel-execute-src-block'." | |||
| 183 | buffer))) | 182 | buffer))) |
| 184 | 183 | ||
| 185 | (defun org-babel-variable-assignments:gnuplot (params) | 184 | (defun org-babel-variable-assignments:gnuplot (params) |
| 186 | "Return list of gnuplot statements assigning the block's variables" | 185 | "Return list of gnuplot statements assigning the block's variables." |
| 187 | (mapcar | 186 | (mapcar |
| 188 | (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair))) | 187 | (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair))) |
| 189 | (org-babel-gnuplot-process-vars params))) | 188 | (org-babel-gnuplot-process-vars params))) |