emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-redisplay-inline-images and export to HTML
@ 2014-07-21 22:12 Brett Viren
  2014-07-21 23:17 ` Nick Dokos
  0 siblings, 1 reply; 5+ messages in thread
From: Brett Viren @ 2014-07-21 22:12 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 3143 bytes --]

Someone recently posted a tip to add

  :post (org-redisplay-inline-images)

to a SRC block which generates an image in order to freshen the Emacs
buffer with the regenerated image each time the block is executed.  It
works *almost* fine but I have two problems which I hope someone can
help with.


1) Priming-the-pump

I'm using a document containing a GraphViz graph and running "dot" on it:

----------------------------------------------------------------------
#+BEGIN_SRC dot :cmd dot :cmdline -Tpng :file foo.png :exports results :post (org-redisplay-inline-images) 
  digraph "foo" {
    rankdir=LR;
    params -> builders;
    builders -> objects;
    objects -> file;
  }
#+END_SRC
----------------------------------------------------------------------

I do "C-c C-c" in the block and the buffer does not display any result.
I see the messages:

----------------------------------------------------------------------
No images to display inline
executing Dot code block...
Wrote /tmp/babel-11819Iqr/ob-input-11819Lrv
org-babel-ref-resolve: Reference 'No images to display inline' not found in this buffer
----------------------------------------------------------------------

If I do "C-c hh" to export to HTML I see:

----------------------------------------------------------------------
org-babel-exp processing...
No images to display inline [2 times]
executing Dot code block...
Wrote /tmp/babel-11819Iqr/ob-input-11819kTR
org-babel-ref-resolve: Reference 'No images to display inline' not found in this buffer
----------------------------------------------------------------------

And I get no HTML file produced.

If I now take out the :post and do "C-c C-c" I get this appearing just
after the SRC block as expected:

----------------------------------------------------------------------
#+RESULTS:
[[file:foo.png]]
----------------------------------------------------------------------

If I now add back the ":post" and do "C-c C-c" again I get the inlined
image.  I can now edit the SRC block and repeat the "C-c C-c" and I am
pleased to see the figure refresh each time.  It's great!  But, it needs
this "pump priming".


2) Post-priming, still no HTML export

After this "priming the pump" is done the second problem is that still a
"C-c hh" does not produce an exported HTML file.  Similar messages:

----------------------------------------------------------------------
org-babel-exp processing...
No images to display inline
Inline image display turned off
No images to display inline
executing Dot code block...
Wrote /tmp/babel-11819Iqr/ob-input-11819zYx
org-babel-ref-resolve: Reference 'No images to display inline' not found in this buffer
----------------------------------------------------------------------

Finally, if I remove the :post but leave the "#+RESULTS:" I can do 
a successful "C-c hh".  

So, the upshot is I have to keep adding and removing the :post to make
things work in different contexts.  This is obviously not so smooth.


Is there some way to both have my cake an eat it too?

Thanks!
-Brett.

[-- Attachment #2: Type: application/pgp-signature, Size: 180 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: org-redisplay-inline-images and export to HTML
  2014-07-21 22:12 org-redisplay-inline-images and export to HTML Brett Viren
@ 2014-07-21 23:17 ` Nick Dokos
  2014-07-22 13:57   ` Brett Viren
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Dokos @ 2014-07-21 23:17 UTC (permalink / raw)
  To: emacs-orgmode

Brett Viren <bv@bnl.gov> writes:

> Someone recently posted a tip to add
>
>   :post (org-redisplay-inline-images)
>
> to a SRC block which generates an image in order to freshen the Emacs
> buffer with the regenerated image each time the block is executed.  It
> works *almost* fine but I have two problems which I hope someone can
> help with.
>
>
> 1) Priming-the-pump
>    ...
>
> 2) Post-priming, still no HTML export
>
>    ...
>
> So, the upshot is I have to keep adding and removing the :post to make
> things work in different contexts.  This is obviously not so smooth.
>
>
> Is there some way to both have my cake an eat it too?
>

The :post trick works by side-effect: org-redisplay-inline-images does
what it says and it returns the string that `message' prints in the echo
area. Unfortunately, on export, :post is processed further with the
result that the meaningless string is passed to org-babel-ref-resolve
as a reference to be resolved - with predictable results[fn:1].

I think you'd be better off with the tip that Rick Frankel posted in
the same thread:

--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC emacs-lisp
(add-hook 'org-babel-after-execute-hook
(lambda () (org-display-inline-images nil t)))
#+END_SRC
--8<---------------cut here---------------end--------------->8---

That's executed after you evaluate the block so it displays any
image(s) produced. And it does not interfere with export.

Footnotes:

[fn:1] Assuming 20-20 hindsight of course...

Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: org-redisplay-inline-images and export to HTML
  2014-07-21 23:17 ` Nick Dokos
@ 2014-07-22 13:57   ` Brett Viren
  2014-07-22 15:40     ` Nick Dokos
  0 siblings, 1 reply; 5+ messages in thread
From: Brett Viren @ 2014-07-22 13:57 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

Nick Dokos <ndokos@gmail.com> writes:

> I think you'd be better off with the tip that Rick Frankel posted in
> the same thread:
>
> #+BEGIN_SRC emacs-lisp
> (add-hook 'org-babel-after-execute-hook
> (lambda () (org-display-inline-images nil t)))
> #+END_SRC

Thanks Nick (and Rick).  I changed this to use the "re" version:

#+BEGIN_SRC emacs-lisp
(add-hook 'org-babel-after-execute-hook
	  (lambda () (org-redisplay-inline-images)))
#+END_SRC

and it works great!  

-Brett.

[-- Attachment #2: Type: application/pgp-signature, Size: 180 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: org-redisplay-inline-images and export to HTML
  2014-07-22 13:57   ` Brett Viren
@ 2014-07-22 15:40     ` Nick Dokos
       [not found]       ` <8761ip5rml.fsf-/Z0n3E7Cx4sTdff2QS34phcY2uh10dtjAL8bYrjMMd8@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Dokos @ 2014-07-22 15:40 UTC (permalink / raw)
  To: emacs-orgmode

Brett Viren <bv@bnl.gov> writes:

> Nick Dokos <ndokos@gmail.com> writes:
>
>> I think you'd be better off with the tip that Rick Frankel posted in
>> the same thread:
>>
>> #+BEGIN_SRC emacs-lisp
>> (add-hook 'org-babel-after-execute-hook
>> (lambda () (org-display-inline-images nil t)))
>> #+END_SRC
>
> Thanks Nick (and Rick).  I changed this to use the "re" version:
>
> #+BEGIN_SRC emacs-lisp
> (add-hook 'org-babel-after-execute-hook
> 	  (lambda () (org-redisplay-inline-images)))
> #+END_SRC
>
> and it works great!  
>

It should work with the non-"re" version as well (and it is more
efficient that way - particularly if you call it with refresh == t).

Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Live refresh of inline images with org-display-inline-images stopped working
       [not found]       ` <8761ip5rml.fsf-/Z0n3E7Cx4sTdff2QS34phcY2uh10dtjAL8bYrjMMd8@public.gmane.org>
@ 2015-01-22 13:34         ` Sebastien Vauban
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastien Vauban @ 2015-01-22 13:34 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode-mXXj517/zsQ

Nick Dokos wrote:
> Brett Viren <bv-IGkKxAqZmp0@public.gmane.org> writes:
>> Nick Dokos <ndokos-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>>
>>> I think you'd be better off with the tip that Rick Frankel posted in
>>> the same thread:
>>>
>>> #+BEGIN_SRC emacs-lisp
>>> (add-hook 'org-babel-after-execute-hook
>>> (lambda () (org-display-inline-images nil t)))
>>> #+END_SRC
>>
>> Thanks Nick (and Rick).  I changed this to use the "re" version:
>>
>> #+BEGIN_SRC emacs-lisp
>> (add-hook 'org-babel-after-execute-hook
>> 	  (lambda () (org-redisplay-inline-images)))
>> #+END_SRC
>>
>> and it works great!  
>
> It should work with the non-"re" version as well (and it is more
> efficient that way - particularly if you call it with refresh == t).

As experienced by wdkmls [1], I noticed that the non-"re" version
stopped working -- preferred as it was the most efficient one.

OTOH, the "re" version does work as expected.

Best regards,
  Seb

[1] http://emacs.stackexchange.com/questions/3302/live-refresh-of-inline-images-with-org-display-inline-images

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-01-22 13:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-21 22:12 org-redisplay-inline-images and export to HTML Brett Viren
2014-07-21 23:17 ` Nick Dokos
2014-07-22 13:57   ` Brett Viren
2014-07-22 15:40     ` Nick Dokos
     [not found]       ` <8761ip5rml.fsf-/Z0n3E7Cx4sTdff2QS34phcY2uh10dtjAL8bYrjMMd8@public.gmane.org>
2015-01-22 13:34         ` Live refresh of inline images with org-display-inline-images stopped working Sebastien Vauban

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).