Function: org-babel-result-to-file
org-babel-result-to-file is a byte-compiled function defined in
ob-core.el.gz.
Signature
(org-babel-result-to-file RESULT &optional DESCRIPTION TYPE)
Documentation
Convert RESULT into an Org link with optional DESCRIPTION.
If the default-directory is different from the containing
file's directory then expand relative links.
If the optional TYPE is passed as attachment and the path is a
descendant of the DEFAULT-DIRECTORY, the generated link will be
specified as an an "attachment:" style link.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ob-core.el.gz
(defun org-babel-result-to-file (result &optional description type)
"Convert RESULT into an Org link with optional DESCRIPTION.
If the `default-directory' is different from the containing
file's directory then expand relative links.
If the optional TYPE is passed as `attachment' and the path is a
descendant of the DEFAULT-DIRECTORY, the generated link will be
specified as an an \"attachment:\" style link."
(when (stringp result)
(let* ((result-file-name (expand-file-name result))
(base-file-name (buffer-file-name (buffer-base-buffer)))
(base-directory (and buffer-file-name
(file-name-directory base-file-name)))
(same-directory?
(and base-file-name
(not (string= (expand-file-name default-directory)
(expand-file-name
base-directory)))))
(request-attachment (eq type 'attachment))
(attach-dir (let* ((default-directory base-directory)
(dir (org-attach-dir nil t)))
(when dir
(expand-file-name dir))))
(in-attach-dir (and request-attachment
attach-dir
(string-prefix-p
attach-dir
result-file-name))))
(format "[[%s:%s]%s]"
(pcase type
((and 'attachment (guard in-attach-dir)) "attachment")
(_ "file"))
(if (and request-attachment in-attach-dir)
(file-relative-name
result-file-name
(file-name-as-directory attach-dir))
(if (and default-directory
base-file-name same-directory?)
(if (eq org-link-file-path-type 'adaptive)
(file-relative-name
result-file-name
(file-name-directory
base-file-name))
result-file-name)
result))
(if description (concat "[" description "]") "")))))