emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Bug: Display Inline Images from Subdirectory [9.4.4 (9.4.4-33-g5450d


From: Kyle Meyer
Subject: Re: Bug: Display Inline Images from Subdirectory [9.4.4 (9.4.4-33-g5450d6-elpaplus @ /home/ded/.emacs.d/elpa/org-plus-contrib-20210322/)]
Date: Sat, 10 Apr 2021 16:54:50 -0400

Daniel E. Doherty writes:

> Nick,
>
> Thanks for trying this out.  I tried this again using emacs -Q with both
> emacs27 and emacs28, and I still get the same result, i.e., it produces
> the link but does not display it inline.  Both versions supported
> display of SVG graphics files.

Hmm, I see the same behavior you're describing: your custom function
doesn't trigger the inline display when :dir is used.

Let's look at the custom function...

> | (defun ded:org-babel-inline-display-subtree ()
> |   "Redisplay inline images in subtree if cursor in source block with 
>     :result graphics."
> |
> |   (when (org-in-src-block-p)
> |     (let (beg end)
> |       (save-mark-and-excursion
> |         (org-mark-subtree)
> |         (setq beg (point))
> |         (setq end (mark)))
> |       (when-let ((info (org-babel-get-src-block-info t))
> |                  (params (org-babel-process-params (nth 2 info)))
> |                  (result-params (cdr (assq :result-params params)))
> |                  ((member "graphics" result-params)))
> |         (org-display-inline-images nil nil beg end)))))
> |
> | (add-hook 'org-babel-after-execute-hook 
>   #'ded:org-babel-inline-display-subtree)

So, org-display-inline-images is probably the place to start debugging.
You can step through its execution [1] and compare the "no :dir" vs
":dir" cases.  When I did that, I noticed that a

  (expand-file-name "dot/lehman.svg")

leads to a non-existent "/path/to/dot/dot/lehman.svg" (note the
repeating "dot/").  That's because :dir temporarily changes the
directory, and org-babel-after-execute-hook executes in that context.

To work around that, you could avoid using org-babel-after-execute-hook
and instead advise org-babel-execute-src-block so that your function is
called afterward.  Another approach would be to let-bind the
default-directory in your function:

  (when (org-in-src-block-p)
    (let ((default-directory (if-let ((fname (buffer-file-name)))
                                 (file-name-directory fname)
                               default-directory))
          ...)
      ...))


[1] (info "(elisp)Instrumenting")



reply via email to

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