emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Auto-refreshing rendered images from org-babel
@ 2014-02-05 17:19 E Sabof
  2014-02-05 23:34 ` Bastien
  0 siblings, 1 reply; 14+ messages in thread
From: E Sabof @ 2014-02-05 17:19 UTC (permalink / raw)
  To: Org-mode

I have the org snippet below. What I would like, is to see the rendered image when I press C-c C-c. I can achieve this with the elisp snippet below. Is there a "proper", or at least a better way of doing this?

Evgeni


#+BEGIN_SRC dot :file files/graphviz/example1.png
digraph test {
    size="6,5";
    home [label = "Home"];
    prod [label = "Products"];
    news [label = "News"];
    cont [label = "Contact"];

    home -> {prod news cont}
}
#+END_SRC


(org-babel-do-load-languages
 'org-babel-load-languages
 '((dot . t)
   ))

(defadvice org-babel-execute:dot (after refresh-images activate)
  (run-with-timer 1 nil 'org-display-inline-images))

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-05 17:19 Auto-refreshing rendered images from org-babel E Sabof
@ 2014-02-05 23:34 ` Bastien
  2014-02-06  5:51   ` E Sabof
  0 siblings, 1 reply; 14+ messages in thread
From: Bastien @ 2014-02-05 23:34 UTC (permalink / raw)
  To: E Sabof; +Cc: Org-mode

E Sabof <esabof@gmail.com> writes:

> I have the org snippet below. What I would like, is to see the
> rendered image when I press C-c C-c. I can achieve this with the elisp
> snippet below. Is there a "proper", or at least a better way of doing
> this?

Not tested but should work:

(add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)

HTH,

-- 
 Bastien

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-05 23:34 ` Bastien
@ 2014-02-06  5:51   ` E Sabof
  2014-02-06  8:45     ` Bastien
  0 siblings, 1 reply; 14+ messages in thread
From: E Sabof @ 2014-02-06  5:51 UTC (permalink / raw)
  To: Bastien; +Cc: Org-mode

Thanks. I've changed it to the version below, which covers my needs. I think it would make sense as a (default?) feature for ob-dot, ob-ditaa, and any other babel language that renders images.

Evgeni

;; Must be defined in a lexical environment
(defun es-org-babel-refresh-images-after-execution ()
  (let (refresh-and-remove-self)
    (setq refresh-and-remove-self
          (lambda ()
            (org-redisplay-inline-images)
            (remove-hook 'org-babel-after-execute-hook
                         refresh-and-remove-self)))
    (add-hook 'org-babel-after-execute-hook refresh-and-remove-self)))

(defadvice org-babel-execute:dot (after refresh-images activate)
  (es-org-babel-refresh-images-after-execution))


Bastien <bzg@gnu.org> writes:

> E Sabof <esabof@gmail.com> writes:
>
>> I have the org snippet below. What I would like, is to see the
>> rendered image when I press C-c C-c. I can achieve this with the elisp
>> snippet below. Is there a "proper", or at least a better way of doing
>> this?
>
> Not tested but should work:
>
> (add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)
>
> HTH,

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06  5:51   ` E Sabof
@ 2014-02-06  8:45     ` Bastien
  2014-02-06  9:06       ` E Sabof
  0 siblings, 1 reply; 14+ messages in thread
From: Bastien @ 2014-02-06  8:45 UTC (permalink / raw)
  To: E Sabof; +Cc: Org-mode

E Sabof <esabof@gmail.com> writes:

> Thanks. I've changed it to the version below, which covers my needs.

Thanks.  Why is it more useful than

(add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)

?

-- 
 Bastien

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06  8:45     ` Bastien
@ 2014-02-06  9:06       ` E Sabof
  2014-02-06  9:10         ` Bastien
  0 siblings, 1 reply; 14+ messages in thread
From: E Sabof @ 2014-02-06  9:06 UTC (permalink / raw)
  To: Bastien; +Cc: Org-mode

Bastien <bzg@gnu.org> writes:

> Thanks.  Why is it more useful than
>
> (add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)
>
> ?

It's more targeted -- I don't use dot that often, and I'd rather not have an additional side effect when executing any org-babel snippet.

Evgeni

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06  9:06       ` E Sabof
@ 2014-02-06  9:10         ` Bastien
  2014-02-06  9:39           ` E Sabof
  0 siblings, 1 reply; 14+ messages in thread
From: Bastien @ 2014-02-06  9:10 UTC (permalink / raw)
  To: E Sabof; +Cc: Org-mode

E Sabof <esabof@gmail.com> writes:

> It's more targeted -- I don't use dot that often, and I'd rather not
> have an additional side effect when executing any org-babel snippet.

Ok, thanks.  I'd rather have ob-dot.el and friends have their own
hooks (e.g. org-babel-execute:dot-hook).  But I'm not yet convince,
as `org-redisplay-inline-images' is already bound to `C-c C-x C-M-v'.

-- 
 Bastien

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06  9:10         ` Bastien
@ 2014-02-06  9:39           ` E Sabof
  2014-02-06  9:46             ` Rainer M Krug
  0 siblings, 1 reply; 14+ messages in thread
From: E Sabof @ 2014-02-06  9:39 UTC (permalink / raw)
  To: Bastien; +Cc: Org-mode


Bastien <bzg@altern.org> writes:

> Ok, thanks.  I'd rather have ob-dot.el and friends have their own
> hooks (e.g. org-babel-execute:dot-hook).  But I'm not yet convince,
> as `org-redisplay-inline-images' is already bound to `C-c C-x C-M-v'.

I'm not a heavy babel user, but maybe something like this could be run from each time babel evaluates a block. A person wanting to run code for one language, but not another seems reasonable.

(let* ((language (the-language-being-executed)))
  (run-hooks (intern (format "org-babel-execute:%s-hook" language))))

Alternatively a variable similar to org-babel-last-executed-language could be set before the existing hook runs, and customizations could be made from there.

Evgeni

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06  9:39           ` E Sabof
@ 2014-02-06  9:46             ` Rainer M Krug
  2014-02-06  9:52               ` Bastien
  2014-02-06 12:22               ` Eric S Fraga
  0 siblings, 2 replies; 14+ messages in thread
From: Rainer M Krug @ 2014-02-06  9:46 UTC (permalink / raw)
  To: E Sabof, Bastien; +Cc: Org-mode

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



On 02/06/14, 10:39 , E Sabof wrote:
> 
> Bastien <bzg@altern.org> writes:
> 
>> Ok, thanks.  I'd rather have ob-dot.el and friends have their own 
>> hooks (e.g. org-babel-execute:dot-hook).  But I'm not yet
>> convince, as `org-redisplay-inline-images' is already bound to `C-c
>> C-x C-M-v'.
> 
> I'm not a heavy babel user, but maybe something like this could be
> run from each time babel evaluates a block. A person wanting to run
> code for one language, but not another seems reasonable.
> 
> (let* ((language (the-language-being-executed))) (run-hooks (intern
> (format "org-babel-execute:%s-hook" language))))
> 
> Alternatively a variable similar to org-babel-last-executed-language
> could be set before the existing hook runs, and customizations could
> be made from there.

I would go one step further - the possibility to define
org-babel-after-execute-hook as a header argument. This would make it
possible to refresh the inline images only after certain blocks are
executed and not after others.

Cheers,

Rainer

> 
> Evgeni
> 

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 560 bytes --]

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06  9:46             ` Rainer M Krug
@ 2014-02-06  9:52               ` Bastien
  2014-02-06 10:09                 ` Rainer M Krug
  2014-02-06 12:22               ` Eric S Fraga
  1 sibling, 1 reply; 14+ messages in thread
From: Bastien @ 2014-02-06  9:52 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Org-mode, E Sabof

Rainer M Krug <Rainer@krugs.de> writes:

> I would go one step further - the possibility to define
> org-babel-after-execute-hook as a header argument. This would make it
> possible to refresh the inline images only after certain blocks are
> executed and not after others.

Well, I'm a bit reluctant to go in this directions... this is more
code, while I guess the real problem was that nobody knew C-c C-x C-M-v.

-- 
 Bastien

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06  9:52               ` Bastien
@ 2014-02-06 10:09                 ` Rainer M Krug
  2014-02-06 10:22                   ` Bastien
  0 siblings, 1 reply; 14+ messages in thread
From: Rainer M Krug @ 2014-02-06 10:09 UTC (permalink / raw)
  To: Bastien; +Cc: Org-mode, E Sabof

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



On 02/06/14, 10:52 , Bastien wrote:
> Rainer M Krug <Rainer@krugs.de> writes:
> 
>> I would go one step further - the possibility to define
>> org-babel-after-execute-hook as a header argument. This would make it
>> possible to refresh the inline images only after certain blocks are
>> executed and not after others.
> 
> Well, I'm a bit reluctant to go in this directions... this is more
> code, while I guess the real problem was that nobody knew C-c C-x C-M-v.

True - but the per code block hooks would open many possibilities, e.g.
automated conversions, automatic uploads, post-process created files via
a script, etc.


Rainer

> 

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 560 bytes --]

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06 10:09                 ` Rainer M Krug
@ 2014-02-06 10:22                   ` Bastien
  2014-02-06 10:26                     ` Rainer M Krug
  0 siblings, 1 reply; 14+ messages in thread
From: Bastien @ 2014-02-06 10:22 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Org-mode, E Sabof

Rainer M Krug <Rainer@krugs.de> writes:

> True - but the per code block hooks would open many possibilities, e.g.
> automated conversions, automatic uploads, post-process created files via
> a script, etc.

So, being as conservative as core maintainers tend to become, I'll
wait for a real use-case for a real need to be expressed here :)

-- 
 Bastien

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06 10:22                   ` Bastien
@ 2014-02-06 10:26                     ` Rainer M Krug
  0 siblings, 0 replies; 14+ messages in thread
From: Rainer M Krug @ 2014-02-06 10:26 UTC (permalink / raw)
  To: Bastien; +Cc: Org-mode, E Sabof

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



On 02/06/14, 11:22 , Bastien wrote:
> Rainer M Krug <Rainer@krugs.de> writes:
> 
>> True - but the per code block hooks would open many possibilities, e.g.
>> automated conversions, automatic uploads, post-process created files via
>> a script, etc.
> 
> So, being as conservative as core maintainers tend to become, I'll
> wait for a real use-case for a real need to be expressed here :)

Good approach.

Cheers,

Rainer

> 

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 560 bytes --]

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06  9:46             ` Rainer M Krug
  2014-02-06  9:52               ` Bastien
@ 2014-02-06 12:22               ` Eric S Fraga
  2014-02-06 13:24                 ` Rainer M Krug
  1 sibling, 1 reply; 14+ messages in thread
From: Eric S Fraga @ 2014-02-06 12:22 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Bastien, Org-mode, E Sabof

Rainer M Krug <Rainer@krugs.de> writes:
> I would go one step further - the possibility to define
> org-babel-after-execute-hook as a header argument. This would make it
> possible to refresh the inline images only after certain blocks are
> executed and not after others.

Doesn't the :post header argument give you this functionality, sort of?
You could link to an emacs lisp src block which does what you want...

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.2.5h-585-g5f0ca0

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

* Re: Auto-refreshing rendered images from org-babel
  2014-02-06 12:22               ` Eric S Fraga
@ 2014-02-06 13:24                 ` Rainer M Krug
  0 siblings, 0 replies; 14+ messages in thread
From: Rainer M Krug @ 2014-02-06 13:24 UTC (permalink / raw)
  To: E Sabof, Bastien, Org-mode

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



On 02/06/14, 13:22 , Eric S Fraga wrote:
> Rainer M Krug <Rainer@krugs.de> writes:
>> I would go one step further - the possibility to define
>> org-babel-after-execute-hook as a header argument. This would make it
>> possible to refresh the inline images only after certain blocks are
>> executed and not after others.
> 
> Doesn't the :post header argument give you this functionality, sort of?
> You could link to an emacs lisp src block which does what you want...

Didn't know about this one - thanks for pointing it out. As I see it, it
would not only work "sort of" but exactly.

Rainer

> 

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 560 bytes --]

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

end of thread, other threads:[~2014-02-06 13:25 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-05 17:19 Auto-refreshing rendered images from org-babel E Sabof
2014-02-05 23:34 ` Bastien
2014-02-06  5:51   ` E Sabof
2014-02-06  8:45     ` Bastien
2014-02-06  9:06       ` E Sabof
2014-02-06  9:10         ` Bastien
2014-02-06  9:39           ` E Sabof
2014-02-06  9:46             ` Rainer M Krug
2014-02-06  9:52               ` Bastien
2014-02-06 10:09                 ` Rainer M Krug
2014-02-06 10:22                   ` Bastien
2014-02-06 10:26                     ` Rainer M Krug
2014-02-06 12:22               ` Eric S Fraga
2014-02-06 13:24                 ` Rainer M Krug

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