From: "Daniel E. Doherty" <ded@ddoherty.net>
To: Kyle Meyer <kyle@kyleam.com>
Cc: emacs-orgmode@gnu.org
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: Tue, 13 Apr 2021 08:21:40 -0500 [thread overview]
Message-ID: <87eefejp0m.fsf@ddoherty.net> (raw)
In-Reply-To: <87tuodoo6d.fsf@kyleam.com>
Kyle,
Thanks for the excellent sleuthing. Nailed it.
I took your second suggestion, and ended up with the following (for
those interested), which works like a charm:
=================================
(setq org-startup-with-inline-images t)
(require 'subr-x)
(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
(default-directory (if-let ((fname (buffer-file-name)))
(file-name-directory fname)
default-directory)))
(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)
========================
On Sat, Apr 10 2021, Kyle Meyer wrote:
> 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")
--
====================================================
Daniel E. Doherty
Law Offices of Daniel E. Doherty
7300 W. 110th Street, Suite 930
Overland Park, KS 66210
913.338.7182 (Phone)
913.338.7164 (FAX)
ded@ddoherty.net
prev parent reply other threads:[~2021-04-13 13:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-06 21:34 Bug: Display Inline Images from Subdirectory [9.4.4 (9.4.4-33-g5450d6-elpaplus @ /home/ded/.emacs.d/elpa/org-plus-contrib-20210322/)] Daniel E. Doherty
2021-04-07 1:14 ` Nick Dokos
2021-04-08 11:57 ` Daniel E. Doherty
2021-04-10 20:54 ` Kyle Meyer
2021-04-13 13:21 ` Daniel E. Doherty [this message]
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87eefejp0m.fsf@ddoherty.net \
--to=ded@ddoherty.net \
--cc=emacs-orgmode@gnu.org \
--cc=kyle@kyleam.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).