From 935b69e0659653ac3e17a3c2132c7499abc2dc57 Mon Sep 17 00:00:00 2001 From: Aaron Ecay Date: Tue, 22 Apr 2014 14:54:55 -0400 Subject: [PATCH] Replace org-babel-*-graphical-output-file with generic version * lisp/ob-core.el (org-babel-graphical-output-file): New generic function. * lisp/ob-R.el (org-babel-R-graphical-output-file): Delete specific version. (org-babel-expand-body:R): Use generic version. * lisp/ob-maxima.el (org-babel-maxima-graphical-output-file): Delete specific version. (org-babel-maxima-expand): Use generic version. * lisp/ob-octave.el (org-babel-octave-graphical-output-file): Delete specific version (org-babel-execute:octave): Use generic version. --- lisp/ob-R.el | 9 ++------- lisp/ob-core.el | 7 +++++++ lisp/ob-maxima.el | 7 +------ lisp/ob-octave.el | 11 +++-------- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 780d99f9c..1c71e0406 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -96,7 +96,7 @@ this variable.") (defun org-babel-expand-body:R (body params &optional graphics-file) "Expand BODY according to PARAMS, return the expanded body." (let ((graphics-file - (or graphics-file (org-babel-R-graphical-output-file params)))) + (or graphics-file (org-babel-graphical-output-file params)))) (mapconcat #'identity (append (when (cdr (assoc :prologue params)) @@ -117,7 +117,7 @@ This function is called by `org-babel-execute-src-block'." (cdr (assoc :session params)) params)) (colnames-p (cdr (assoc :colnames params))) (rownames-p (cdr (assoc :rownames params))) - (graphics-file (org-babel-R-graphical-output-file params)) + (graphics-file (org-babel-graphical-output-file params)) (full-body (let ((inside (list (org-babel-expand-body:R body params graphics-file)))) @@ -251,11 +251,6 @@ current code buffer." (process-name (get-buffer-process session))) (ess-make-buffer-current)) -(defun org-babel-R-graphical-output-file (params) - "Name of file to which R should send graphical output." - (and (member "graphics" (cdr (assq :result-params params))) - (cdr (assq :file params)))) - (defvar org-babel-R-graphics-devices '((:bmp "bmp" "filename") (:jpg "jpeg" "filename") diff --git a/lisp/ob-core.el b/lisp/ob-core.el index d80ea4c59..1348f04f5 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2890,6 +2890,13 @@ For the format of SAFE-LIST, see `org-babel-safe-header-args'." (member (cdr pair) (cdr entry))) (t nil))))))) + +;;; Used by backends: R, Maxima, Octave. +(defun org-babel-graphical-output-file (params) + "File where a babel block should send graphical output, per PARAMS." + (and (member "graphics" (cdr (assq :result-params params))) + (cdr (assq :file params)))) + (provide 'ob-core) ;; Local variables: diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el index 7435f1d32..5d4ec18cc 100644 --- a/lisp/ob-maxima.el +++ b/lisp/ob-maxima.el @@ -52,7 +52,7 @@ (mapconcat 'identity (list ;; graphic output - (let ((graphic-file (org-babel-maxima-graphical-output-file params))) + (let ((graphic-file (org-babel-graphical-output-file params))) (if graphic-file (format "set_plot_option ([gnuplot_term, png]); set_plot_option ([gnuplot_out_file, %S]);" @@ -113,11 +113,6 @@ of the same value." (format "%S: %s$" var (org-babel-maxima-elisp-to-maxima val)))) -(defun org-babel-maxima-graphical-output-file (params) - "Name of file to which maxima should send graphical output." - (and (member "graphics" (cdr (assq :result-params params))) - (cdr (assq :file params)))) - (defun org-babel-maxima-elisp-to-maxima (val) "Return a string of maxima code which evaluates to VAL." (if (listp val) diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el index 8cc66b6f9..1e6102c89 100644 --- a/lisp/ob-octave.el +++ b/lisp/ob-octave.el @@ -84,16 +84,16 @@ end") body params (org-babel-variable-assignments:octave params))) (result (org-babel-octave-evaluate session - (if (org-babel-octave-graphical-output-file params) + (if (org-babel-graphical-output-file params) (mapconcat 'identity (list "set (0, \"defaultfigurevisible\", \"off\");" full-body - (format "print -dpng %s" (org-babel-octave-graphical-output-file params))) + (format "print -dpng %s" (org-babel-graphical-output-file params))) "\n") full-body) result-type matlabp))) - (if (org-babel-octave-graphical-output-file params) + (if (org-babel-graphical-output-file params) nil (org-babel-reassemble-table result @@ -268,11 +268,6 @@ This removes initial blank and comment lines and then calls (match-string 1 string) string)) -(defun org-babel-octave-graphical-output-file (params) - "Name of file to which maxima should send graphical output." - (and (member "graphics" (cdr (assq :result-params params))) - (cdr (assq :file params)))) - (provide 'ob-octave)