From 6857093df26af908d85dfb1e9512f1a838b2ffd7 Mon Sep 17 00:00:00 2001 From: Eric S Fraga Date: Thu, 7 Dec 2017 06:56:41 +0000 Subject: [PATCH] allow gnuplot to generate plots in different directories * lisp/ob-gnuplot.el (org-babel-expand-body:gnuplot) if the org buffer is associated with a file, direct gnuplot to change to the directory for that file. --- lisp/ob-gnuplot.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lisp/ob-gnuplot.el b/lisp/ob-gnuplot.el index b0743f604..241f1d3a4 100644 --- a/lisp/ob-gnuplot.el +++ b/lisp/ob-gnuplot.el @@ -116,6 +116,8 @@ code." (timefmt (cdr (assq :timefmt params))) (time-ind (or (cdr (assq :timeind params)) (when timefmt 1))) + (directory (and (buffer-file-name) + (file-name-directory (buffer-file-name)))) (add-to-body (lambda (text) (setq body (concat text "\n" body))))) ;; append header argument settings to body (when title (funcall add-to-body (format "set title '%s'" title))) @@ -161,7 +163,10 @@ code." (format "\\$%s" (car pair)) (cdr pair) body))) vars) (when prologue (funcall add-to-body prologue)) - (when epilogue (setq body (concat body "\n" epilogue)))) + (when epilogue (setq body (concat body "\n" epilogue))) + ;; Setting the directory needs to be done first so that + ;; subsequent 'output' directive goes to the right place. + (when directory (funcall add-to-body (format "cd '%s'" directory)))) body)) (defun org-babel-execute:gnuplot (body params) -- 2.15.0