mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2025-02-01 20:54:25 +00:00
Babel now cleans up any temporary files created using org-babel-temp-file
* lisp/ob.el (org-babel-temporary-directory): variable to hold the value of the Babel temporary directory (org-babel-temp-file): replacement for make-temp-file with cleanup on exit of Emacs (org-babel-remove-temporary-directory): cleanup function run on exit of Emacs (kill-emacs-hook): now includes babel cleanup function * lisp/ob-C.el (org-babel-C-execute): using org-babel-temp-file instead of make-temp-file * lisp/ob-R.el (org-babel-R-assign-elisp): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-R-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-R-evaluate-session): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-asymptote.el (org-babel-execute:asymptote): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-clojure.el (org-babel-clojure-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ditaa.el (org-babel-execute:ditaa): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-dot.el (org-babel-execute:dot): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-gnuplot.el (org-babel-gnuplot-process-vars): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-execute:gnuplot): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-haskell.el (org-babel-load-session:haskell): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-haskell-export-to-lhs): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-latex.el (org-babel-execute:latex): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ledger.el (org-babel-execute:ledger): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-lisp.el (org-babel-execute:lisp): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-octave.el (org-babel-octave-evaluate-external-process): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-octave-evaluate-session): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-octave-import-elisp-from-file): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-perl.el (org-babel-perl-evaluate): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-python.el (org-babel-python-evaluate): using `org-babel-temp-file' instead of `make-temp-file' using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-ruby.el (org-babel-ruby-evaluate): using `org-babel-temp-file' instead of `make-temp-file' using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sass.el (org-babel-execute:sass): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sh.el (org-babel-sh-evaluate): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sql.el (org-babel-execute:sql): using `org-babel-temp-file' instead of `make-temp-file' * lisp/ob-sqlite.el (org-babel-execute:sqlite): using `org-babel-temp-file' instead of `make-temp-file' (org-babel-sqlite-expand-vars): using `org-babel-temp-file' instead of `make-temp-file'
This commit is contained in:
parent
58f0a4ed41
commit
7b00073f2d
@ -84,12 +84,12 @@ header arguments (calls `org-babel-C-expand')."
|
||||
"This function should only be called by `org-babel-execute:C'
|
||||
or `org-babel-execute:c++'."
|
||||
(let* ((processed-params (org-babel-process-params params))
|
||||
(tmp-src-file (make-temp-file "org-babel-C-src" nil
|
||||
(tmp-src-file (org-babel-temp-file "C-src-" nil
|
||||
(cond
|
||||
((equal org-babel-c-variant 'c) ".c")
|
||||
((equal org-babel-c-variant 'cpp) ".cpp"))))
|
||||
(tmp-bin-file (make-temp-file "org-babel-C-bin"))
|
||||
(tmp-out-file (make-temp-file "org-babel-C-out"))
|
||||
(tmp-bin-file (org-babel-temp-file "C-bin-"))
|
||||
(tmp-out-file (org-babel-temp-file "C-out-"))
|
||||
(cmdline (cdr (assoc :cmdline params)))
|
||||
(flags (cdr (assoc :flags params)))
|
||||
(full-body (org-babel-C-expand body params))
|
||||
@ -108,7 +108,7 @@ or `org-babel-execute:c++'."
|
||||
((lambda (results)
|
||||
(org-babel-reassemble-table
|
||||
(if (member "vector" (nth 2 processed-params))
|
||||
(let ((tmp-file (make-temp-file "ob-c")))
|
||||
(let ((tmp-file (org-babel-temp-file "c-")))
|
||||
(with-temp-file tmp-file (insert results))
|
||||
(org-babel-import-elisp-from-file tmp-file))
|
||||
(org-babel-read results))
|
||||
|
@ -139,7 +139,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||
(defun org-babel-R-assign-elisp (name value colnames-p rownames-p)
|
||||
"Construct R code assigning the elisp VALUE to a variable named NAME."
|
||||
(if (listp value)
|
||||
(let ((transition-file (make-temp-file "org-babel-R-import")))
|
||||
(let ((transition-file (org-babel-temp-file "R-import-")))
|
||||
;; ensure VALUE has an orgtbl structure (depth of at least 2)
|
||||
(unless (listp (car value)) (setq value (list value)))
|
||||
(with-temp-file (org-babel-maybe-remote-file transition-file)
|
||||
@ -235,7 +235,7 @@ string. If RESULT-TYPE equals 'value then return the value of the
|
||||
last statement in BODY, as elisp."
|
||||
(case result-type
|
||||
(value
|
||||
(let ((tmp-file (make-temp-file "org-babel-R-results-")))
|
||||
(let ((tmp-file (org-babel-temp-file "R-results-")))
|
||||
(org-babel-eval org-babel-R-command
|
||||
(format org-babel-R-wrapper-method
|
||||
body tmp-file
|
||||
@ -256,7 +256,7 @@ string. If RESULT-TYPE equals 'value then return the value of the
|
||||
last statement in BODY, as elisp."
|
||||
(case result-type
|
||||
(value
|
||||
(let ((tmp-file (make-temp-file "org-babel-R"))
|
||||
(let ((tmp-file (org-babel-temp-file "R-"))
|
||||
broke)
|
||||
(org-babel-comint-with-output (session org-babel-R-eoe-output)
|
||||
(insert (mapconcat
|
||||
|
@ -73,7 +73,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||
(match-string 1 out-file))
|
||||
"pdf"))
|
||||
(cmdline (cdr (assoc :cmdline params)))
|
||||
(in-file (make-temp-file "org-babel-asymptote"))
|
||||
(in-file (org-babel-temp-file "asymptote-"))
|
||||
(cmd (concat "asy "
|
||||
(if out-file
|
||||
(concat "-globalwrite -f " format " -o " out-file)
|
||||
|
@ -261,7 +261,7 @@ repl buffer."
|
||||
" "))))
|
||||
(case result-type
|
||||
(output (org-babel-eval cmd body))
|
||||
(value (let* ((tmp-file (make-temp-file "org-babel-clojure-results-")))
|
||||
(value (let* ((tmp-file (org-babel-temp-file "clojure-results-")))
|
||||
(org-babel-eval cmd (format org-babel-clojure-wrapper-method
|
||||
body tmp-file tmp-file))
|
||||
(org-babel-clojure-table-or-string
|
||||
|
@ -53,7 +53,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||
(let ((result-params (split-string (or (cdr (assoc :results params)) "")))
|
||||
(out-file (cdr (assoc :file params)))
|
||||
(cmdline (cdr (assoc :cmdline params)))
|
||||
(in-file (make-temp-file "org-babel-ditaa")))
|
||||
(in-file (org-babel-temp-file "ditaa-")))
|
||||
(unless (file-exists-p org-ditaa-jar-path)
|
||||
(error "Could not find ditaa.jar at %s" org-ditaa-jar-path))
|
||||
(with-temp-file in-file (insert body))
|
||||
|
@ -70,7 +70,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||
(out-file (cdr (assoc :file params)))
|
||||
(cmdline (cdr (assoc :cmdline params)))
|
||||
(cmd (or (cdr (assoc :cmd params)) "dot"))
|
||||
(in-file (make-temp-file "org-babel-dot")))
|
||||
(in-file (org-babel-temp-file "dot-")))
|
||||
(with-temp-file in-file
|
||||
(insert (org-babel-expand-body:dot body params processed-params)))
|
||||
(org-babel-eval (concat cmd " " in-file " " cmdline " -o " out-file) "")
|
||||
|
@ -68,7 +68,7 @@ code."
|
||||
(car pair) ;; variable name
|
||||
(if (listp (cdr pair)) ;; variable value
|
||||
(org-babel-gnuplot-table-to-data
|
||||
(cdr pair) (make-temp-file "org-babel-gnuplot") params)
|
||||
(cdr pair) (org-babel-temp-file "gnuplot") params)
|
||||
(cdr pair))))
|
||||
(org-babel-ref-variables params)))
|
||||
|
||||
@ -141,7 +141,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||
(save-window-excursion
|
||||
;; evaluate the code body with gnuplot
|
||||
(if (string= session "none")
|
||||
(let ((script-file (make-temp-file "org-babel-gnuplot-script")))
|
||||
(let ((script-file (org-babel-temp-file "gnuplot-script")))
|
||||
(with-temp-file script-file
|
||||
(insert (concat body "\n")))
|
||||
(message "gnuplot \"%s\"" script-file)
|
||||
|
@ -116,7 +116,7 @@ then create one. Return the initialized session."
|
||||
(save-window-excursion
|
||||
(let* ((buffer (org-babel-prep-session:haskell
|
||||
session params processed-params))
|
||||
(load-file (concat (make-temp-file "org-babel-haskell-load") ".hs")))
|
||||
(load-file (concat (org-babel-temp-file "haskell-load-") ".hs")))
|
||||
(with-temp-buffer
|
||||
(insert body) (write-file load-file)
|
||||
(haskell-mode) (inferior-haskell-load-file))
|
||||
@ -177,7 +177,7 @@ constructs (header arguments, no-web syntax etc...) are ignored."
|
||||
(concat "^\\([ \t]*\\)#\\+begin_src[ \t]haskell*\\(.*\\)?[\r\n]"
|
||||
"\\([^\000]*?\\)[\r\n][ \t]*#\\+end_src.*"))
|
||||
(base-name (file-name-sans-extension (buffer-file-name)))
|
||||
(tmp-file (make-temp-file "ob-haskell"))
|
||||
(tmp-file (org-babel-temp-file "haskell-"))
|
||||
(tmp-org-file (concat tmp-file ".org"))
|
||||
(tmp-tex-file (concat tmp-file ".tex"))
|
||||
(lhs-file (concat base-name ".lhs"))
|
||||
|
@ -70,7 +70,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||
(setq body (org-babel-expand-body:latex body params))
|
||||
(if (cdr (assoc :file params))
|
||||
(let* ((out-file (cdr (assoc :file params)))
|
||||
(tex-file (make-temp-file "org-babel-latex" nil ".tex"))
|
||||
(tex-file (org-babel-temp-file "latex-" nil ".tex"))
|
||||
(border (cdr (assoc :border params)))
|
||||
(fit (or (cdr (assoc :fit params)) border))
|
||||
(height (and fit (cdr (assoc :pdfheight params))))
|
||||
|
@ -50,8 +50,8 @@ called by `org-babel-execute-src-block'."
|
||||
(message "executing Ledger source code block")
|
||||
(let ((result-params (split-string (or (cdr (assoc :results params)) "")))
|
||||
(cmdline (cdr (assoc :cmdline params)))
|
||||
(in-file (make-temp-file "org-babel-ledger"))
|
||||
(out-file (make-temp-file "org-babel-ledger-output"))
|
||||
(in-file (org-babel-temp-file "ledger-"))
|
||||
(out-file (org-babel-temp-file "ledger-output-"))
|
||||
)
|
||||
(with-temp-file in-file (insert body))
|
||||
(message (concat "ledger -f " in-file " " cmdline))
|
||||
|
@ -74,7 +74,7 @@ This function is called by `org-babel-execute-src-block'"
|
||||
(save-window-excursion
|
||||
(cadr (slime-eval `(swank:eval-and-grab-output ,full-body))))
|
||||
;; external evaluation
|
||||
(let ((script-file (make-temp-file "ob-lisp-script")))
|
||||
(let ((script-file (org-babel-temp-file "lisp-script-")))
|
||||
(with-temp-file script-file
|
||||
(insert
|
||||
;; return the value or the output
|
||||
|
@ -178,7 +178,7 @@ value of the last statement in BODY, as elisp."
|
||||
org-babel-octave-shell-command)))
|
||||
(case result-type
|
||||
(output (org-babel-eval cmd body))
|
||||
(value (let ((tmp-file (make-temp-file "org-babel-results-")))
|
||||
(value (let ((tmp-file (org-babel-temp-file "results-")))
|
||||
(org-babel-eval
|
||||
cmd
|
||||
(format org-babel-octave-wrapper-method body tmp-file tmp-file))
|
||||
@ -188,8 +188,8 @@ value of the last statement in BODY, as elisp."
|
||||
(defun org-babel-octave-evaluate-session
|
||||
(session body result-type &optional matlabp)
|
||||
"Evaluate BODY in SESSION."
|
||||
(let* ((tmp-file (make-temp-file "org-babel-results-"))
|
||||
(wait-file (make-temp-file "org-babel-matlab-emacs-link-wait-signal-"))
|
||||
(let* ((tmp-file (org-babel-temp-file "results-"))
|
||||
(wait-file (org-babel-temp-file "matlab-emacs-link-wait-signal-"))
|
||||
(full-body
|
||||
(case result-type
|
||||
(output
|
||||
@ -246,7 +246,7 @@ value of the last statement in BODY, as elisp."
|
||||
"Import data from FILE-NAME.
|
||||
This removes initial blank and comment lines and then calls
|
||||
`org-babel-import-elisp-from-file'."
|
||||
(let ((temp-file (make-temp-file "org-babel-results-")) beg end)
|
||||
(let ((temp-file (org-babel-temp-file "results-")) beg end)
|
||||
(with-temp-file temp-file
|
||||
(insert-file-contents file-name)
|
||||
(re-search-forward "^[ \t]*[^# \t]" nil t)
|
||||
|
@ -107,7 +107,7 @@ return the value of the last statement in BODY, as elisp."
|
||||
(when session (error "Sessions are not supported for Perl."))
|
||||
(case result-type
|
||||
(output (org-babel-eval org-babel-perl-command body))
|
||||
(value (let ((tmp-file (make-temp-file "org-babel-perl-results-")))
|
||||
(value (let ((tmp-file (org-babel-temp-file "perl-results-")))
|
||||
(org-babel-eval
|
||||
org-babel-perl-command
|
||||
(format org-babel-perl-wrapper-method body tmp-file))
|
||||
|
@ -203,7 +203,7 @@ return the value of the last statement in BODY, as elisp."
|
||||
;; external process evaluation
|
||||
(case result-type
|
||||
(output (org-babel-eval org-babel-python-command body))
|
||||
(value (let ((tmp-file (make-temp-file "org-babel-python-results-")))
|
||||
(value (let ((tmp-file (org-babel-temp-file "python-results-")))
|
||||
(org-babel-eval org-babel-python-command
|
||||
(format
|
||||
(if (member "pp" result-params)
|
||||
@ -251,7 +251,7 @@ return the value of the last statement in BODY, as elisp."
|
||||
(if (or (member "code" result-params) (member "pp" result-params))
|
||||
results
|
||||
(org-babel-python-table-or-string results)))
|
||||
(let ((tmp-file (make-temp-file "org-babel-python-results-")))
|
||||
(let ((tmp-file (org-babel-temp-file "python-results-")))
|
||||
(org-babel-comint-with-output
|
||||
(buffer org-babel-python-eoe-indicator t body)
|
||||
(let ((comint-process-echoes nil))
|
||||
|
@ -186,7 +186,7 @@ return the value of the last statement in BODY, as elisp."
|
||||
;; external process evaluation
|
||||
(case result-type
|
||||
(output (org-babel-eval org-babel-ruby-command body))
|
||||
(value (let ((tmp-file (make-temp-file "org-babel-ruby-results-")))
|
||||
(value (let ((tmp-file (org-babel-temp-file "ruby-results-")))
|
||||
(org-babel-eval org-babel-ruby-command
|
||||
(format (if (member "pp" result-params)
|
||||
org-babel-ruby-pp-wrapper-method
|
||||
@ -221,7 +221,7 @@ return the value of the last statement in BODY, as elisp."
|
||||
(if (or (member "code" result-params) (member "pp" result-params))
|
||||
results
|
||||
(org-babel-ruby-table-or-string results)))
|
||||
(let* ((tmp-file (make-temp-file "org-babel-ruby-results-"))
|
||||
(let* ((tmp-file (org-babel-temp-file "ruby-results-"))
|
||||
(ppp (or (member "code" result-params)
|
||||
(member "pp" result-params))))
|
||||
(org-babel-comint-with-output
|
||||
|
@ -51,9 +51,9 @@
|
||||
This function is called by `org-babel-execute-src-block'."
|
||||
(let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
|
||||
(file (cdr (assoc :file params)))
|
||||
(out-file (or file (make-temp-file "org-babel-sass-out")))
|
||||
(out-file (or file (org-babel-temp-file "sass-out-")))
|
||||
(cmdline (cdr (assoc :cmdline params)))
|
||||
(in-file (make-temp-file "org-babel-sass-in"))
|
||||
(in-file (org-babel-temp-file "sass-in-"))
|
||||
(cmd (concat "sass " (or cmdline "") in-file " " out-file)))
|
||||
(with-temp-file in-file
|
||||
(insert (org-babel-expand-body:sass body params))) (shell-command cmd)
|
||||
|
@ -155,12 +155,12 @@ return the value of the last statement in BODY."
|
||||
(if (or (member "scalar" result-params)
|
||||
(member "output" result-params))
|
||||
results
|
||||
(let ((tmp-file (make-temp-file "org-babel-sh")))
|
||||
(let ((tmp-file (org-babel-temp-file "sh-")))
|
||||
(with-temp-file tmp-file (insert results))
|
||||
(org-babel-import-elisp-from-file tmp-file))))
|
||||
(if (not session)
|
||||
(org-babel-eval org-babel-sh-command (org-babel-trim body))
|
||||
(let ((tmp-file (make-temp-file "org-babel-sh")))
|
||||
(let ((tmp-file (org-babel-temp-file "sh-")))
|
||||
(mapconcat
|
||||
#'org-babel-sh-strip-weird-long-prompt
|
||||
(mapcar
|
||||
|
@ -60,9 +60,9 @@ This function is called by `org-babel-execute-src-block'."
|
||||
(processed-params (org-babel-process-params params))
|
||||
(cmdline (cdr (assoc :cmdline params)))
|
||||
(engine (cdr (assoc :engine params)))
|
||||
(in-file (make-temp-file "org-babel-sql-in"))
|
||||
(in-file (org-babel-temp-file "sql-in-"))
|
||||
(out-file (or (cdr (assoc :out-file params))
|
||||
(make-temp-file "org-babel-sql-out")))
|
||||
(org-babel-temp-file "sql-out-")))
|
||||
(command (case (intern engine)
|
||||
('mysql (format "mysql %s -e \"source %s\" > %s"
|
||||
(or cmdline "") in-file out-file))
|
||||
|
@ -73,7 +73,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||
(insert (org-babel-expand-body:sqlite
|
||||
body nil (list nil vars))))
|
||||
sql-file)
|
||||
(make-temp-file "ob-sqlite-sql")))
|
||||
(org-babel-temp-file "sqlite-sql-")))
|
||||
(cons "cmd" org-babel-sqlite3-command)
|
||||
(cons "header" (if headers-p "-header" "-noheader"))
|
||||
(cons "separator"
|
||||
@ -117,7 +117,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||
el
|
||||
(format "%S" el)))))))
|
||||
data-file)
|
||||
(make-temp-file "ob-sqlite-data"))
|
||||
(org-babel-temp-file "sqlite-data-"))
|
||||
(if (stringp val) val (format "%S" val))))
|
||||
(cdr pair))
|
||||
body)))
|
||||
|
25
lisp/ob.el
25
lisp/ob.el
@ -1658,6 +1658,31 @@ the remote connection."
|
||||
(concat "/" user (when user "@") host ":" file))
|
||||
file))
|
||||
|
||||
(defvar org-babel-temporary-directory
|
||||
(or (and (boundp 'org-babel-temporary-directory)
|
||||
org-babel-temporary-directory)
|
||||
(make-temp-file "babel-" t))
|
||||
"Directory to hold temporary files created to execute code blocks.
|
||||
Used by `org-babel-temp-file'. This directory will be removed on
|
||||
Emacs shutdown.")
|
||||
|
||||
(defun org-babel-temp-file (prefix &optional suffix)
|
||||
"Create a temporary file in the `org-babel-temporary-directory'.
|
||||
Passes PREFIX and SUFFIX directly to `make-temp-file' with the
|
||||
value of `temporary-file-directory' temporarily set to the value
|
||||
of `org-babel-temporary-directory'."
|
||||
(let ((temporary-file-directory (expand-file-name
|
||||
org-babel-temporary-directory
|
||||
temporary-file-directory)))
|
||||
(make-temp-file prefix suffix)))
|
||||
|
||||
(defun org-babel-remove-temporary-directory ()
|
||||
"Remove `org-babel-temporary-directory' on Emacs shutdown."
|
||||
(when (boundp 'org-babel-temporary-directory)
|
||||
(delete-directory org-babel-temporary-directory t)))
|
||||
|
||||
(add-hook 'kill-emacs-hook 'org-babel-remove-temporary-directory)
|
||||
|
||||
(provide 'ob)
|
||||
|
||||
;; arch-tag: 01a7ebee-06c5-4ee4-a709-e660d28c0af1
|
||||
|
Loading…
x
Reference in New Issue
Block a user