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: Nick Dokos
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
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

"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 via email to

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