emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <ndokos@gmail.com>
To: 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, 06 Apr 2021 21:14:39 -0400	[thread overview]
Message-ID: <87blaq6glc.fsf@alphaville.usersys.redhat.com> (raw)
In-Reply-To: <8735w3kshh.fsf@ddoherty.net>

"Daniel E. Doherty" <ded@ddoherty.net> writes:

> I have a hook function (cribbed from Emacs Stack Exchange) to re-display 
> inline images in the current subtree after execution of a source block 
> if the header argument contains, ':results graphics'.  As its last 
> action, it calls:
>
> (org-display-inline-images nil nil beg end)
>
> where beg and end have been set to the bounds of the current subtree.
>
> This works perfectly if the image file is in the current directory.  For
> example, here is a block that displays as expected:
>
> #+begin_SRC dot :file lehman.svg :cmdline -Kdot -Tsvg :results graphics
>   digraph lehman {
>     Thomas [shape=circle];
>     TideWater [shape = box, label="Tide Water\nSecurities\n(Issuer)"];
>     Lehman [shape = box];
>     Thomas -> TideWater [label="Director"];
>     Lehman -> TideWater [label="Shareholder"];
>     Thomas -> Lehman [label="Partner"];
>   }
> #+end_SRC
>
>
> However, if I add a :dir header, it ceases to work:
>
> #+begin_SRC dot :dir dot :file lehman.svg :cmdline -Kdot -Tsvg :results 
>  graphics
>   digraph lehman {
>     Thomas [shape=circle];
>     TideWater [shape = box, label="Tide Water\nSecurities\n(Issuer)"];
>     Lehman [shape = box];
>     Thomas -> TideWater [label="Director"];
>     Lehman -> TideWater [label="Shareholder"];
>     Thomas -> Lehman [label="Partner"];
>   }
> #+end_SRC
>
>
> #+RESULTS:
> [[file:dot/lehman.svg]]
>
> I have run edebug on the function, and the only difference I can detect
> is the location of the image file in a subdirectory called 'dot'.
>
> Here is my hook function, just for the record:
>
> #+begin_SRC emacs-lisp
>   (setq org-startup-with-inline-images t)
>   (require 'subr-x)
>   (defun ded:org-babel-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-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-display-subtree)
> #+end_SRC
>

FWIW, this works fine for me: Org mode version 9.4.4 (release_9.4.4-231-gf46925 @ /home/nick/elisp/org-mode/lisp/)

The only things I had to do was 1) to make the above into a tree by
adding a headline (otherwise, I guess org-mark-subtree would complain:
Not in a subtree) and 2) create the dot subdirectory.

-- 
Nick

"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler



  reply	other threads:[~2021-04-07  1:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 21:34 Daniel E. Doherty
2021-04-07  1:14 ` Nick Dokos [this message]
2021-04-08 11:57   ` Daniel E. Doherty
2021-04-10 20:54     ` Kyle Meyer
2021-04-13 13:21       ` Daniel E. Doherty

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=87blaq6glc.fsf@alphaville.usersys.redhat.com \
    --to=ndokos@gmail.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/)]' \
    /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

Code repositories for project(s) associated with this 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).