emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals-release/org cc5427b7ef 1/2: org-babel-result-to-file: F


From: ELPA Syncer
Subject: [elpa] externals-release/org cc5427b7ef 1/2: org-babel-result-to-file: Fix results file inside attachment dir
Date: Wed, 7 Dec 2022 06:57:56 -0500 (EST)

branch: externals-release/org
commit cc5427b7ef67bea835f61568479e69d44003ba2f
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-babel-result-to-file: Fix results file inside attachment dir
    
    * lisp/ob-core.el (org-babel-result-to-file): When file path in the
    result contains attachment dir, reduce the path to relative file name
    when generating attachment: link.
    * testing/lisp/test-ob.el (test-ob-core/dir-attach): Add test.
    
    Reported-by: Johan Tolö <johan@toloe.se>
    Link: https://orgmode.org/list/875yesnia6.fsf@toloe.se
---
 lisp/ob-core.el         |  8 +++++---
 testing/lisp/test-ob.el | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 5b78ee946f..069fc442fd 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2692,8 +2692,8 @@ specified as an an \"attachment:\" style link."
            (same-directory?
            (and base-file-name
                 (not (string= (expand-file-name default-directory)
-                              (expand-file-name
-                               base-directory)))))
+                            (expand-file-name
+                             base-directory)))))
            (request-attachment (eq type 'attachment))
            (attach-dir (let* ((default-directory base-directory)
                               (dir (org-attach-dir nil t)))
@@ -2709,7 +2709,9 @@ specified as an an \"attachment:\" style link."
                 ((and 'attachment (guard in-attach-dir)) "attachment")
                 (_ "file"))
               (if (and request-attachment in-attach-dir)
-                  (file-relative-name result-file-name)
+                  (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)
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index e4090d6d8b..c8dbd44f44 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -1954,6 +1954,23 @@ nil
      (file-exists-p (format "%s/test.txt" (org-attach-dir nil t)))
      (string= (buffer-substring-no-properties (point) (line-end-position))
               "[[attachment:test.txt]]"))))
+  ;; Strip attach dir from the file path.
+  (should
+   (org-test-with-temp-text-in-file
+    "* heading
+:PROPERTIES:
+:DIR:      custom-attach-dir
+:END:
+
+<point>#+begin_src elisp :results value file
+\"custom-attach-dir/test.txt\"
+#+end_src"
+    (message "DIR: %s" (org-attach-dir t))
+    (org-babel-execute-src-block)
+    (goto-char (org-babel-where-is-src-block-result))
+    (forward-line)
+     (string= (buffer-substring-no-properties (point) (line-end-position))
+              "[[attachment:test.txt]]")))
   (should-error
    (org-test-with-temp-text-in-file
     "* 'attach with no ID or DIR



reply via email to

[Prev in Thread] Current Thread [Next in Thread]