mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-23 07:18:53 +00:00
org-babel: Refactor temporary directory usage
* lisp/ob-core.el (org-babel-temp-directory): Fix return value for remote directory. (org-babel-temp-file): Simplify using `org-babel-temp-directory'. Fix incorrect file location when PREFIX is "". (org-babel-temp-stable-directory): New macro returning suitable temporary stable directory. (org-babel-temp-stable-file): Simplify using `org-babel-temp-stable-directory'. Fix incorrect file location when PREFIX is "". * lisp/ob-java.el (org-babel-execute:java): Use `org-babel-temp-directory'. Reported-by: Ferdinand Pieper <fer@pie.tf> Link: https://orgmode.org/list/87r0yz7u9q.fsf_-_@pie.tf
This commit is contained in:
parent
2f5e7103e5
commit
69e3a4db3d
@ -3276,7 +3276,8 @@ Emacs shutdown.")
|
||||
(defmacro org-babel-temp-directory ()
|
||||
"Return temporary directory suitable for `default-directory'."
|
||||
`(if (file-remote-p default-directory)
|
||||
org-babel-remote-temporary-directory
|
||||
(concat (file-remote-p default-directory)
|
||||
org-babel-remote-temporary-directory)
|
||||
(or (and org-babel-temporary-directory
|
||||
(file-exists-p org-babel-temporary-directory)
|
||||
org-babel-temporary-directory)
|
||||
@ -3287,42 +3288,31 @@ Emacs shutdown.")
|
||||
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'."
|
||||
(if (file-remote-p default-directory)
|
||||
(let ((prefix
|
||||
(concat (file-remote-p default-directory)
|
||||
(expand-file-name
|
||||
prefix org-babel-remote-temporary-directory))))
|
||||
(make-temp-file prefix nil suffix))
|
||||
(let ((temporary-file-directory
|
||||
(or (and org-babel-temporary-directory
|
||||
(file-exists-p org-babel-temporary-directory)
|
||||
org-babel-temporary-directory)
|
||||
temporary-file-directory)))
|
||||
(make-temp-file prefix nil suffix))))
|
||||
(make-temp-file
|
||||
(concat (file-name-as-directory (org-babel-temp-directory)) prefix)
|
||||
nil
|
||||
suffix))
|
||||
|
||||
(defmacro org-babel-temp-stable-directory ()
|
||||
"Return temporary stable directory."
|
||||
`(let ((org-babel-temporary-directory org-babel-temporary-stable-directory))
|
||||
(org-babel-temp-directory)))
|
||||
|
||||
(defun org-babel-temp-stable-file (data prefix &optional suffix)
|
||||
"Create a temporary file in the `org-babel-remove-temporary-stable-directory'.
|
||||
The file name is stable with respect to DATA. The file name is
|
||||
constructed like the following: PREFIXDATAhashSUFFIX."
|
||||
(if (file-remote-p default-directory)
|
||||
(let* ((prefix
|
||||
(concat (file-remote-p default-directory)
|
||||
(expand-file-name
|
||||
prefix org-babel-temporary-stable-directory)))
|
||||
(path (concat prefix (format "%s" (sxhash data)) (or suffix ""))))
|
||||
(with-temp-file path)
|
||||
path)
|
||||
(let* ((temporary-file-directory
|
||||
(or (and org-babel-temporary-stable-directory
|
||||
(file-exists-p org-babel-temporary-stable-directory)
|
||||
org-babel-temporary-stable-directory)
|
||||
temporary-file-directory))
|
||||
(path (concat
|
||||
(expand-file-name
|
||||
prefix org-babel-temporary-stable-directory)
|
||||
(format "%s" (sxhash data)) (or suffix ""))))
|
||||
(with-temp-file path)
|
||||
path)))
|
||||
(let ((path
|
||||
(format
|
||||
"%s%s%s%s"
|
||||
(file-name-as-directory (org-babel-temp-stable-directory))
|
||||
prefix
|
||||
(sxhash data)
|
||||
(or suffix ""))))
|
||||
;; Create file.
|
||||
(with-temp-file path)
|
||||
;; Return it.
|
||||
path))
|
||||
|
||||
(defun org-babel-remove-temporary-directory ()
|
||||
"Remove `org-babel-temporary-directory' on Emacs shutdown."
|
||||
|
@ -194,13 +194,10 @@ replaced in this string.")
|
||||
(packagename (if (string-match-p "\\." fullclassname)
|
||||
(file-name-base fullclassname)))
|
||||
;; the base dir that contains the top level package dir
|
||||
(basedir (file-name-as-directory (if run-from-temp
|
||||
(if (file-remote-p default-directory)
|
||||
(concat
|
||||
(file-remote-p default-directory)
|
||||
org-babel-remote-temporary-directory)
|
||||
(org-babel-temp-directory))
|
||||
default-directory)))
|
||||
(basedir (file-name-as-directory
|
||||
(if run-from-temp
|
||||
(org-babel-temp-directory)
|
||||
default-directory)))
|
||||
;; the dir to write the source file
|
||||
(packagedir (if (and (not run-from-temp) packagename)
|
||||
(file-name-as-directory
|
||||
|
Loading…
Reference in New Issue
Block a user