Org-mode mailing list
 help / color / Atom feed
From: Ihor Radchenko <>
Subject: Bug: [patch] Fix org-babel-result-to-file never expanding links when babel is evaluated in indirect buffer [9.3.7 (release_9.3.7-728-g1efc4e @ /home/yantar92/.emacs.d/straight/build/org/)]
Date: Fri, 31 Jul 2020 16:49:40 +0800
Message-ID: <87eeos3w7v.fsf@localhost> (raw)

[-- Attachment #1: Type: text/plain, Size: 889 bytes --]

Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

Your bug report will be posted to the Org mailing list.

I noticed that org-babel-result-to-file never expands file: links in
src block results when ran from indirect buffer and default-directory
is not same with base buffer file's directory. This is against the
docstring stating that

> If the `default-directory' is different from the containing
> file's directory then expand relative links.

The misbehavior happens because buffer-file-name variable is always
nil in indirect buffers. We need to call (file-name-directory
(buffer-file-name (buffer-base-buffer))) instead.

The patch is attached.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-babel-eval-indirect.patch --]
[-- Type: text/x-diff, Size: 1200 bytes --]

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index f86282f0f..d37eef5f9 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2561,16 +2561,16 @@ If the `default-directory' is different from the containing
 file's directory then expand relative links."
   (when (stringp result)
     (let ((same-directory?
-	   (and buffer-file-name
+	   (and (buffer-file-name (buffer-base-buffer))
 		(not (string= (expand-file-name default-directory)
-			      (expand-file-name
-			       (file-name-directory buffer-file-name)))))))
+			    (expand-file-name
+			     (file-name-directory (buffer-file-name (buffer-base-buffer)))))))))
       (format "[[file:%s]%s]"
-	      (if (and default-directory buffer-file-name same-directory?)
+	      (if (and default-directory (buffer-file-name (buffer-base-buffer)) same-directory?)
 		  (if (eq org-link-file-path-type 'adaptive)
 		       (expand-file-name result default-directory)
-		       (file-name-directory (buffer-file-name)))
+		       (file-name-directory (buffer-file-name (buffer-base-buffer))))
 		    (expand-file-name result default-directory))
 	      (if description (concat "[" description "]") "")))))

[-- Attachment #3: Type: text/plain, Size: 485 bytes --]

Emacs  : GNU Emacs 28.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
 of 2020-07-27
Package: Org mode version 9.3.7 (release_9.3.7-728-g1efc4e @ /home/yantar92/.emacs.d/straight/build/org/)

Ihor Radchenko,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong University, Xi'an, China

             reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31  8:49 Ihor Radchenko [this message]
2020-07-31 17:24 ` John Herrlin
2020-07-31 23:32   ` Ihor Radchenko
2020-08-01 16:33     ` John Herrlin
2020-08-02  4:36       ` Ihor Radchenko
2020-08-02 19:24         ` John Herrlin
2020-08-02 22:50           ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eeos3w7v.fsf@localhost \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Org-mode mailing list

Archives are clonable:
	git clone --mirror list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ \
	public-inbox-index list

Example config snippet for mirrors

Newsgroups are available over NNTP:

AGPL code for this site: git clone