emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Bug: [patch] Fix org-babel-result-to-file never expanding links when


From: John Herrlin
Subject: Re: 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 19:24:42 +0200
User-agent: mu4e 1.4.10; emacs 26.3

Hey Ihor,

Could not get the patch to work.

I used this use case.

(with-current-buffer
  (find-file "/tmp/tmp.org")
  (insert "* A\n** b\n** c\n\n   some text")
  (dired "~/")
  (make-indirect-buffer "tmp.org" "tmp-indirect")
  (switch-to-buffer "tmp-indirect")
  (goto-char (point-max))
  (funcall 'org-mode)
  (insert (concat "\n\n| default-directory | " default-directory " |\n"
                  "| org-link-file-path-type | " (symbol-name 
org-link-file-path-type) " |\n"
                  "| (expand-file-name default-directory) | " (expand-file-name 
default-directory) " |\n"
                  "| (buffer-file-name (buffer-base-buffer)) | " 
(buffer-file-name (buffer-base-buffer)) " |\n"))
  (org-table-align)
  (insert "\n\n#+BEGIN_SRC shell :results file :file script.sh
       echo \"#!/bin/bash\"
       echo \"echo Hey\"\n#+END_SRC")
  (org-babel-execute-src-block))

In my case the result is a relative link, but if I follow the link I end
up in the wrong place.

src_emacs-lisp{emacs-version} {{{results(=26.3=)}}}
src_emacs-lisp{org-version} {{{results(=9.3.7=)}}}

Best regards
John


Ihor Radchenko <yantar92@gmail.com> writes:

> 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
>
>      https://orgmode.org/manual/Feedback.html#Feedback
>
> 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.
>
> Best,
> Ihor
>
> 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)
>                     (file-relative-name
>                      (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))
>               result)
>             (if description (concat "[" description "]") "")))))
>
> 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/)


--
Mvh John



reply via email to

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