emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Multiple (identical) RESULTS blocks of one code block?
@ 2015-03-09 10:04 Rainer M Krug
  2015-03-09 13:01 ` John Kitchin
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Rainer M Krug @ 2015-03-09 10:04 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi

Consider the following:

--8<---------------cut here---------------start------------->8---
* The calculation
#+NAME: testcode :exports both
#+begin_src R  :session test
runif(10)
#+end_src


* summary of the results
First time
#+RESULTS: testcode :exports both
|  0.772744940361008 |
|  0.170518629485741 |
| 0.0833237133920193 |
|  0.149035625392571 |
|  0.698798568220809 |
|  0.627075897762552 |
|  0.177144371205941 |
| 0.0476319056469947 |
|  0.289851602632552 |
| 0.0296813279855996 |

* and another
testthingy
#+RESULTS: testcode :exports both

--8<---------------cut here---------------end--------------->8---

If I update the calculation, the first results block is updated, but
not the second one. I would like to have two RESULTS blocks which
are both updated when the code block is evaluated.

Is this possible?

Thanks,

Rainer

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

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

* Re: Multiple (identical) RESULTS blocks of one code block?
  2015-03-09 10:04 Multiple (identical) RESULTS blocks of one code block? Rainer M Krug
@ 2015-03-09 13:01 ` John Kitchin
  2015-03-09 13:10   ` Sebastien Vauban
  2015-03-10  9:06   ` Rainer M Krug
  2015-03-09 16:34 ` Nicolas Goaziou
  2015-03-10  2:05 ` Aaron Ecay
  2 siblings, 2 replies; 10+ messages in thread
From: John Kitchin @ 2015-03-09 13:01 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: emacs-orgmode

I don't believe this is possible out of the box. The first RESULTS block
from the beginning of the buffer will be updated, and not the others.

You might be able to use a hook function to do this, something like:

#+BEGIN_SRC emacs-lisp
(defun update-results () (interactive)
  ;; get name of src block
  (let ((name (org-element-property :name (org-element-at-point)))
        (results))
    (when name
      (org-element-map (org-element-parse-buffer) 'fixed-width
        (lambda (object)
          (if results
              ;; replace value in block
              (setf
               (buffer-substring
                (org-element-property :begin  object)
                (org-element-property :end  object))
               results)
            ;; set results
            (setq results
                  (buffer-substring
                   (org-element-property :begin  object)
                   (org-element-property :end  object)))))))))
#+END_SRC


#+BEGIN_SRC emacs-lisp
(add-hook 'org-babel-after-execute-hook 'update-results)
#+END_SRC

This worked on a small test example, but I did not test it
thoroughly. your mileage might vary ;)


Rainer M Krug writes:

> Hi
>
> Consider the following:
>
> --8<---------------cut here---------------start------------->8---
> * The calculation
> #+NAME: testcode :exports both
> #+begin_src R  :session test
> runif(10)
> #+end_src
>
>
> * summary of the results
> First time
> #+RESULTS: testcode :exports both
> |  0.772744940361008 |
> |  0.170518629485741 |
> | 0.0833237133920193 |
> |  0.149035625392571 |
> |  0.698798568220809 |
> |  0.627075897762552 |
> |  0.177144371205941 |
> | 0.0476319056469947 |
> |  0.289851602632552 |
> | 0.0296813279855996 |
>
> * and another
> testthingy
> #+RESULTS: testcode :exports both
>
> --8<---------------cut here---------------end--------------->8---
>
> If I update the calculation, the first results block is updated, but
> not the second one. I would like to have two RESULTS blocks which
> are both updated when the code block is evaluated.
>
> Is this possible?
>
> Thanks,
>
> Rainer

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

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

* Re: Multiple (identical) RESULTS blocks of one code block?
  2015-03-09 13:01 ` John Kitchin
@ 2015-03-09 13:10   ` Sebastien Vauban
  2015-03-10  9:06   ` Rainer M Krug
  1 sibling, 0 replies; 10+ messages in thread
From: Sebastien Vauban @ 2015-03-09 13:10 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

John Kitchin wrote:
> Rainer M Krug writes:
>>
>> Consider the following:
>>
>> * The calculation
>> #+NAME: testcode :exports both
>> #+begin_src R  :session test
>> runif(10)
>> #+end_src
>>
>>
>> * summary of the results
>> First time
>> #+RESULTS: testcode :exports both
>> |  0.772744940361008 |
>> |  0.170518629485741 |
>> | 0.0833237133920193 |
>> |  0.149035625392571 |
>> |  0.698798568220809 |
>> |  0.627075897762552 |
>> |  0.177144371205941 |
>> | 0.0476319056469947 |
>> |  0.289851602632552 |
>> | 0.0296813279855996 |
>>
>> * and another
>> testthingy
>> #+RESULTS: testcode :exports both
>>
>> If I update the calculation, the first results block is updated, but
>> not the second one. I would like to have two RESULTS blocks which
>> are both updated when the code block is evaluated.
>>
>> Is this possible?
>
> I don't believe this is possible out of the box. The first RESULTS block
> from the beginning of the buffer will be updated, and not the others.
>
> You might be able to use a hook function to do this [...].

Another solution is to use the `echo' [1] code block to copy whatever
contents where you want it...

Best regards,
  Seb

[1] http://orgmode.org/cgit.cgi/org-mode.git/plain/doc/library-of-babel.org

-- 
Sebastien Vauban

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

* Re: Multiple (identical) RESULTS blocks of one code block?
  2015-03-09 10:04 Multiple (identical) RESULTS blocks of one code block? Rainer M Krug
  2015-03-09 13:01 ` John Kitchin
@ 2015-03-09 16:34 ` Nicolas Goaziou
  2015-03-10  2:05 ` Aaron Ecay
  2 siblings, 0 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2015-03-09 16:34 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: emacs-orgmode

Hello,

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

> Consider the following:
>
> * The calculation
> #+NAME: testcode :exports both
> #+begin_src R  :session test
> runif(10)
> #+end_src
>
>
> * summary of the results
> First time
> #+RESULTS: testcode :exports both
> |  0.772744940361008 |
> |  0.170518629485741 |
> | 0.0833237133920193 |
> |  0.149035625392571 |
> |  0.698798568220809 |
> |  0.627075897762552 |
> |  0.177144371205941 |
> | 0.0476319056469947 |
> |  0.289851602632552 |
> | 0.0296813279855996 |
>
> * and another
> testthingy
> #+RESULTS: testcode :exports both
>
>
> If I update the calculation, the first results block is updated, but
> not the second one. I would like to have two RESULTS blocks which
> are both updated when the code block is evaluated.
>
> Is this possible?

It isn't, but I think it is a reasonable expectation. Would you like to
provide a patch for that?


Regards,

-- 
Nicolas Goaziou

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

* Re: Multiple (identical) RESULTS blocks of one code block?
  2015-03-09 10:04 Multiple (identical) RESULTS blocks of one code block? Rainer M Krug
  2015-03-09 13:01 ` John Kitchin
  2015-03-09 16:34 ` Nicolas Goaziou
@ 2015-03-10  2:05 ` Aaron Ecay
  2015-03-10  9:02   ` Rainer M Krug
  2 siblings, 1 reply; 10+ messages in thread
From: Aaron Ecay @ 2015-03-10  2:05 UTC (permalink / raw)
  To: Rainer M Krug, emacs-orgmode

Hi Rainer,

2015ko martxoak 9an, Rainer M Krug-ek idatzi zuen:
>
> Hi
>
> Consider the following:
>
> --8<---------------cut here---------------start------------->8---
> * The calculation
> #+NAME: testcode :exports both

It looks like you’ve tried to put a header argument into the name.  Is
it merely an accident?  I ask because...

> #+begin_src R  :session test
> runif(10)
> #+end_src
>
>
> * summary of the results
> First time
> #+RESULTS: testcode :exports both
> |  0.772744940361008 |
> |  0.170518629485741 |
> | 0.0833237133920193 |
> |  0.149035625392571 |
> |  0.698798568220809 |
> |  0.627075897762552 |
> |  0.177144371205941 |
> | 0.0476319056469947 |
> |  0.289851602632552 |
> | 0.0296813279855996 |
>
> * and another
> testthingy
> #+RESULTS: testcode :exports both

...here it reoccurs, in identical format.  This is fine, interpreted
as just a weird block name (and not as an actual header argument).
But if you’re trying to allow the header arguments to vary for the two
result blocks I don’t think it will be very nice.  (It would require
re-evaluating the code block for each different combination of header
arguments, which would give unexpected behavior in the case of side
effects, etc. etc.)

Maybe it’s not very important, but I just figured I’d ask for
clarification.

Thanks,

--
Aaron Ecay

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

* Re: Multiple (identical) RESULTS blocks of one code block?
  2015-03-10  2:05 ` Aaron Ecay
@ 2015-03-10  9:02   ` Rainer M Krug
  0 siblings, 0 replies; 10+ messages in thread
From: Rainer M Krug @ 2015-03-10  9:02 UTC (permalink / raw)
  To: emacs-orgmode

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

Aaron Ecay <aaronecay@gmail.com> writes:

> Hi Rainer,
>
> 2015ko martxoak 9an, Rainer M Krug-ek idatzi zuen:
>>
>> Hi
>>
>> Consider the following:
>>
>> --8<---------------cut here---------------start------------->8---
>> * The calculation
>> #+NAME: testcode :exports both
>
> It looks like you’ve tried to put a header argument into the name.  Is
> it merely an accident?  I ask because...

Accident - the header argument should be behind the code block beginning
and not the NAME - sorry.

>
>> #+begin_src R  :session test
>> runif(10)
>> #+end_src
>>
>>
>> * summary of the results
>> First time
>> #+RESULTS: testcode :exports both
>> |  0.772744940361008 |
>> |  0.170518629485741 |
>> | 0.0833237133920193 |
>> |  0.149035625392571 |
>> |  0.698798568220809 |
>> |  0.627075897762552 |
>> |  0.177144371205941 |
>> | 0.0476319056469947 |
>> |  0.289851602632552 |
>> | 0.0296813279855996 |
>>
>> * and another
>> testthingy
>> #+RESULTS: testcode :exports both
>
> ...here it reoccurs, in identical format.  This is fine, interpreted
> as just a weird block name (and not as an actual header argument).
> But if you’re trying to allow the header arguments to vary for the two
> result blocks I don’t think it will be very nice.  (It would require
> re-evaluating the code block for each different combination of header
> arguments, which would give unexpected behavior in the case of side
> effects, etc. etc.)

I think I clud do this by using =#+CALL testcode= but this is not w=hat
I wanted.

>
> Maybe it’s not very important, but I just figured I’d ask for
> clarification.

Sure - I should be looking more carefully when typing.

Is my brain really that slow, as I am not a fast typer...

Cheers,

Rainer

>
> Thanks,
>
> --
> Aaron Ecay
>
>

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

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

* Re: Multiple (identical) RESULTS blocks of one code block?
  2015-03-09 13:01 ` John Kitchin
  2015-03-09 13:10   ` Sebastien Vauban
@ 2015-03-10  9:06   ` Rainer M Krug
  2015-03-10  9:35     ` Rainer M Krug
  1 sibling, 1 reply; 10+ messages in thread
From: Rainer M Krug @ 2015-03-10  9:06 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

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

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> I don't believe this is possible out of the box. The first RESULTS block
> from the beginning of the buffer will be updated, and not the others.
>
> You might be able to use a hook function to do this, something like:
>
> #+BEGIN_SRC emacs-lisp
> (defun update-results () (interactive)
>   ;; get name of src block
>   (let ((name (org-element-property :name (org-element-at-point)))
>         (results))
>     (when name
>       (org-element-map (org-element-parse-buffer) 'fixed-width
>         (lambda (object)
>           (if results
>               ;; replace value in block
>               (setf
>                (buffer-substring
>                 (org-element-property :begin  object)
>                 (org-element-property :end  object))
>                results)
>             ;; set results
>             (setq results
>                   (buffer-substring
>                    (org-element-property :begin  object)
>                    (org-element-property :end  object)))))))))
> #+END_SRC
> #+BEGIN_SRC emacs-lisp
> (add-hook 'org-babel-after-execute-hook 'update-results)
> #+END_SRC
>
> This worked on a small test example, but I did not test it
> thoroughly. your mileage might vary ;)

This looks nice - I will try it out and see how it goes.


>
>
> Rainer M Krug writes:
>
>> Hi
>>
>> Consider the following:
>>
>> --8<---------------cut here---------------start------------->8---
>> * The calculation
>> #+NAME: testcode :exports both
>> #+begin_src R  :session test
>> runif(10)
>> #+end_src
>>
>>
>> * summary of the results
>> First time
>> #+RESULTS: testcode :exports both
>> |  0.772744940361008 |
>> |  0.170518629485741 |
>> | 0.0833237133920193 |
>> |  0.149035625392571 |
>> |  0.698798568220809 |
>> |  0.627075897762552 |
>> |  0.177144371205941 |
>> | 0.0476319056469947 |
>> |  0.289851602632552 |
>> | 0.0296813279855996 |
>>
>> * and another
>> testthingy
>> #+RESULTS: testcode :exports both
>>
>> --8<---------------cut here---------------end--------------->8---
>>
>> If I update the calculation, the first results block is updated, but
>> not the second one. I would like to have two RESULTS blocks which
>> are both updated when the code block is evaluated.
>>
>> Is this possible?
>>
>> Thanks,
>>
>> Rainer
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>
>

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

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

* Re: Multiple (identical) RESULTS blocks of one code block?
  2015-03-10  9:06   ` Rainer M Krug
@ 2015-03-10  9:35     ` Rainer M Krug
       [not found]       ` <m2sidd2ems.fsf@andrew.cmu.edu>
  0 siblings, 1 reply; 10+ messages in thread
From: Rainer M Krug @ 2015-03-10  9:35 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

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

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

> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> I don't believe this is possible out of the box. The first RESULTS block
>> from the beginning of the buffer will be updated, and not the others.
>>
>> You might be able to use a hook function to do this, something like:
>>
>> #+BEGIN_SRC emacs-lisp
>> (defun update-results () (interactive)
>>   ;; get name of src block
>>   (let ((name (org-element-property :name (org-element-at-point)))
>>         (results))
>>     (when name
>>       (org-element-map (org-element-parse-buffer) 'fixed-width
>>         (lambda (object)
>>           (if results
>>               ;; replace value in block
>>               (setf
>>                (buffer-substring
>>                 (org-element-property :begin  object)
>>                 (org-element-property :end  object))
>>                results)
>>             ;; set results
>>             (setq results
>>                   (buffer-substring
>>                    (org-element-property :begin  object)
>>                    (org-element-property :end  object)))))))))
>> #+END_SRC
>> #+BEGIN_SRC emacs-lisp
>> (add-hook 'org-babel-after-execute-hook 'update-results)
>> #+END_SRC
>>
>> This worked on a small test example, but I did not test it
>> thoroughly. your mileage might vary ;)
>
> This looks nice - I will try it out and see how it goes.


I don't get it to work.

I put the following into my emacs.org and evaluated it:

--8<---------------cut here---------------start------------->8---
(defun rmk/update-multiple-results-blocks () (interactive)
       ;; get name of src block
       (let ((name (org-element-property :name (org-element-at-point)))
             (results))
         (when name
           (org-element-map (org-element-parse-buffer) 'fixed-width
             (lambda (object)
               (if results
                   ;; replace value in block
                   (setf
                    (buffer-substring
                     (org-element-property :begin  object)
                     (org-element-property :end  object))
                    results)
                 ;; set results
                 (setq results
                       (buffer-substring
                        (org-element-property :begin  object)
                        (org-element-property :end  object)))))))))

#+end_src

#+RESULTS:
: rmk/update-multiple-results-blocks

Add this function to =org-babel=after-execute-hook=
#+begin_src emacs-lisp 
(add-hook 'org-babel-after-execute-hook 'rmk/update-multiple-results-blocks)
#+end_src

#+RESULTS:
| rmk/update-multiple-results-blocks |
--8<---------------cut here---------------end--------------->8---


I am using the following org file to test it:

--8<---------------cut here---------------start------------->8---
* The calculation
#+NAME: testcode
#+begin_src R :session test
runif(10)
#+end_src

* summary of the results
First time
#+RESULTS: testcode
|  0.471471928292885 |
|  0.128247044514865 |
|  0.398714824113995 |
|  0.335577708436176 |
| 0.0184990330599248 |
|  0.952211205149069 |
|  0.367342215497047 |
|  0.581879974342883 |
|  0.440492485417053 |
| 0.0729096119757742 |


#+RESULTS: testcode
| 0.0095007149502635 |
| 0.0898537992034107 |
|  0.764667606214061 |
| 0.0309854068327695 |
|  0.510338442632928 |
|  0.220906731439754 |
|  0.589271233882755 |
|  0.966699115466326 |
| 0.0183747289702296 |
|  0.734954049577937 |
--8<---------------cut here---------------end--------------->8---

But only the first results block is updated. The function
=rmk/update-multiple-results-blocks= is executed.

I am using

,----
| Org-mode version 8.3beta (release_8.3beta-884-g9ed426 @ /Users/rainerkrug/.emacs.d/org-mode/lisp/)
| GNU Emacs 24.4.1 (x86_64-apple-darwin14.0.0, Carbon Version 157 AppKit 1343.16) of 2015-02-02 on Rainers-MacBook-Pro-4.local
`----

Any ideas what is going wrong?

Thanks,

Rainer


>
>
>>
>>
>> Rainer M Krug writes:
>>
>>> Hi
>>>
>>> Consider the following:
>>>
>>> --8<---------------cut here---------------start------------->8---
>>> * The calculation
>>> #+NAME: testcode :exports both
>>> #+begin_src R  :session test
>>> runif(10)
>>> #+end_src
>>>
>>>
>>> * summary of the results
>>> First time
>>> #+RESULTS: testcode :exports both
>>> |  0.772744940361008 |
>>> |  0.170518629485741 |
>>> | 0.0833237133920193 |
>>> |  0.149035625392571 |
>>> |  0.698798568220809 |
>>> |  0.627075897762552 |
>>> |  0.177144371205941 |
>>> | 0.0476319056469947 |
>>> |  0.289851602632552 |
>>> | 0.0296813279855996 |
>>>
>>> * and another
>>> testthingy
>>> #+RESULTS: testcode :exports both
>>>
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>> If I update the calculation, the first results block is updated, but
>>> not the second one. I would like to have two RESULTS blocks which
>>> are both updated when the code block is evaluated.
>>>
>>> Is this possible?
>>>
>>> Thanks,
>>>
>>> Rainer
>>
>> --
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu
>>
>>

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

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

* Re: Multiple (identical) RESULTS blocks of one code block?
       [not found]       ` <m2sidd2ems.fsf@andrew.cmu.edu>
@ 2015-03-10 13:31         ` Rainer M Krug
  2015-03-10 13:57           ` Rainer M Krug
  0 siblings, 1 reply; 10+ messages in thread
From: Rainer M Krug @ 2015-03-10 13:31 UTC (permalink / raw)
  To: emacs-orgmode

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

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> weird. I swear it worked in the little toy problem I made ;)
>
> I think this is a more robust function:
>
> #+BEGIN_SRC emacs-lisp
> (defun update-results ()
>   ;; get name of src block
>   (let* ((name (org-element-property :name (org-element-at-point)))
>         (results (save-excursion
>                    (goto-char (org-babel-find-named-result name))
>                    (forward-line)
>                    (buffer-substring
>                    (point) (org-element-property :end (org-element-at-point)))))
>         (begin))
>     (save-excursion
>       (goto-char (point-min))
>       (while (setq begin (org-babel-find-named-result name (point)))
>         (goto-char begin)
>         (forward-line)
>         (setf (buffer-substring
>                (point)
>                (org-element-property :end (org-element-at-point)))
>               results)))))
> #+END_SRC
>
> I tested this one on two examples ;)

And also on my example...

Thanks John

Works perfectly - added to my emacs.org.

Any chance that you could put this into a patch so that it could go into org?

Rainer

>
> Rainer M Krug writes:
>
>> Rainer M Krug <Rainer@krugs.de> writes:
>>
>>> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>>>
>>>> I don't believe this is possible out of the box. The first RESULTS block
>>>> from the beginning of the buffer will be updated, and not the others.
>>>>
>>>> You might be able to use a hook function to do this, something like:
>>>>
>>>> #+BEGIN_SRC emacs-lisp
>>>> (defun update-results () (interactive)
>>>>   ;; get name of src block
>>>>   (let ((name (org-element-property :name (org-element-at-point)))
>>>>         (results))
>>>>     (when name
>>>>       (org-element-map (org-element-parse-buffer) 'fixed-width
>>>>         (lambda (object)
>>>>           (if results
>>>>               ;; replace value in block
>>>>               (setf
>>>>                (buffer-substring
>>>>                 (org-element-property :begin  object)
>>>>                 (org-element-property :end  object))
>>>>                results)
>>>>             ;; set results
>>>>             (setq results
>>>>                   (buffer-substring
>>>>                    (org-element-property :begin  object)
>>>>                    (org-element-property :end  object)))))))))
>>>> #+END_SRC
>>>> #+BEGIN_SRC emacs-lisp
>>>> (add-hook 'org-babel-after-execute-hook 'update-results)
>>>> #+END_SRC
>>>>
>>>> This worked on a small test example, but I did not test it
>>>> thoroughly. your mileage might vary ;)
>>>
>>> This looks nice - I will try it out and see how it goes.
>>
>>
>> I don't get it to work.
>>
>> I put the following into my emacs.org and evaluated it:
>>
>> --8<---------------cut here---------------start------------->8---
>> (defun rmk/update-multiple-results-blocks () (interactive)
>>        ;; get name of src block
>>        (let ((name (org-element-property :name (org-element-at-point)))
>>              (results))
>>          (when name
>>            (org-element-map (org-element-parse-buffer) 'fixed-width
>>              (lambda (object)
>>                (if results
>>                    ;; replace value in block
>>                    (setf
>>                     (buffer-substring
>>                      (org-element-property :begin  object)
>>                      (org-element-property :end  object))
>>                     results)
>>                  ;; set results
>>                  (setq results
>>                        (buffer-substring
>>                         (org-element-property :begin  object)
>>                         (org-element-property :end  object)))))))))
>>
>> #+end_src
>>
>> #+RESULTS:
>> : rmk/update-multiple-results-blocks
>>
>> Add this function to =org-babel=after-execute-hook=
>> #+begin_src emacs-lisp
>> (add-hook 'org-babel-after-execute-hook 'rmk/update-multiple-results-blocks)
>> #+end_src
>>
>> #+RESULTS:
>> | rmk/update-multiple-results-blocks |
>> --8<---------------cut here---------------end--------------->8---
>>
>>
>> I am using the following org file to test it:
>>
>> --8<---------------cut here---------------start------------->8---
>> * The calculation
>> #+NAME: testcode
>> #+begin_src R :session test
>> runif(10)
>> #+end_src
>>
>> * summary of the results
>> First time
>> #+RESULTS: testcode
>> |  0.471471928292885 |
>> |  0.128247044514865 |
>> |  0.398714824113995 |
>> |  0.335577708436176 |
>> | 0.0184990330599248 |
>> |  0.952211205149069 |
>> |  0.367342215497047 |
>> |  0.581879974342883 |
>> |  0.440492485417053 |
>> | 0.0729096119757742 |
>>
>>
>> #+RESULTS: testcode
>> | 0.0095007149502635 |
>> | 0.0898537992034107 |
>> |  0.764667606214061 |
>> | 0.0309854068327695 |
>> |  0.510338442632928 |
>> |  0.220906731439754 |
>> |  0.589271233882755 |
>> |  0.966699115466326 |
>> | 0.0183747289702296 |
>> |  0.734954049577937 |
>> --8<---------------cut here---------------end--------------->8---
>>
>> But only the first results block is updated. The function
>> =rmk/update-multiple-results-blocks= is executed.
>>
>> I am using
>>
>> ,----
>> | Org-mode version 8.3beta (release_8.3beta-884-g9ed426 @ /Users/rainerkrug/.emacs.d/org-mode/lisp/)
>> | GNU Emacs 24.4.1 (x86_64-apple-darwin14.0.0, Carbon Version 157
>> | AppKit 1343.16) of 2015-02-02 on Rainers-MacBook-Pro-4.local
>> `----
>>
>> Any ideas what is going wrong?
>>
>> Thanks,
>>
>> Rainer
>>
>>
>>>
>>>
>>>>
>>>>
>>>> Rainer M Krug writes:
>>>>
>>>>> Hi
>>>>>
>>>>> Consider the following:
>>>>>
>>>>> --8<---------------cut here---------------start------------->8---
>>>>> * The calculation
>>>>> #+NAME: testcode :exports both
>>>>> #+begin_src R  :session test
>>>>> runif(10)
>>>>> #+end_src
>>>>>
>>>>>
>>>>> * summary of the results
>>>>> First time
>>>>> #+RESULTS: testcode :exports both
>>>>> |  0.772744940361008 |
>>>>> |  0.170518629485741 |
>>>>> | 0.0833237133920193 |
>>>>> |  0.149035625392571 |
>>>>> |  0.698798568220809 |
>>>>> |  0.627075897762552 |
>>>>> |  0.177144371205941 |
>>>>> | 0.0476319056469947 |
>>>>> |  0.289851602632552 |
>>>>> | 0.0296813279855996 |
>>>>>
>>>>> * and another
>>>>> testthingy
>>>>> #+RESULTS: testcode :exports both
>>>>>
>>>>> --8<---------------cut here---------------end--------------->8---
>>>>>
>>>>> If I update the calculation, the first results block is updated, but
>>>>> not the second one. I would like to have two RESULTS blocks which
>>>>> are both updated when the code block is evaluated.
>>>>>
>>>>> Is this possible?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Rainer
>>>>
>>>> --
>>>> Professor John Kitchin
>>>> Doherty Hall A207F
>>>> Department of Chemical Engineering
>>>> Carnegie Mellon University
>>>> Pittsburgh, PA 15213
>>>> 412-268-7803
>>>> @johnkitchin
>>>> http://kitchingroup.cheme.cmu.edu
>>>>
>>>>
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu

-- 
Rainer M. Krug

PGP: 0x0F52F982

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

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

* Re: Multiple (identical) RESULTS blocks of one code block?
  2015-03-10 13:31         ` Rainer M Krug
@ 2015-03-10 13:57           ` Rainer M Krug
  0 siblings, 0 replies; 10+ messages in thread
From: Rainer M Krug @ 2015-03-10 13:57 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: John Kitchin

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

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

> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> weird. I swear it worked in the little toy problem I made ;)
>>
>> I think this is a more robust function:
>>
>> #+BEGIN_SRC emacs-lisp
>> (defun update-results ()
>>   ;; get name of src block
>>   (let* ((name (org-element-property :name (org-element-at-point)))
>>         (results (save-excursion
>>                    (goto-char (org-babel-find-named-result name))
>>                    (forward-line)
>>                    (buffer-substring
>>                    (point) (org-element-property :end (org-element-at-point)))))
>>         (begin))
>>     (save-excursion
>>       (goto-char (point-min))
>>       (while (setq begin (org-babel-find-named-result name (point)))
>>         (goto-char begin)
>>         (forward-line)
>>         (setf (buffer-substring
>>                (point)
>>                (org-element-property :end (org-element-at-point)))
>>               results)))))
>> #+END_SRC
>>
>> I tested this one on two examples ;)
>
> And also on my example...
>
> Thanks John
>
> Works perfectly - added to my emacs.org.

Just realised that it produces an error if the code block has no name.

Cheers,

Rainer

>
> Any chance that you could put this into a patch so that it could go into org?
>
> Rainer
>
>>
>> Rainer M Krug writes:
>>
>>> Rainer M Krug <Rainer@krugs.de> writes:
>>>
>>>> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>>>>
>>>>> I don't believe this is possible out of the box. The first RESULTS block
>>>>> from the beginning of the buffer will be updated, and not the others.
>>>>>
>>>>> You might be able to use a hook function to do this, something like:
>>>>>
>>>>> #+BEGIN_SRC emacs-lisp
>>>>> (defun update-results () (interactive)
>>>>>   ;; get name of src block
>>>>>   (let ((name (org-element-property :name (org-element-at-point)))
>>>>>         (results))
>>>>>     (when name
>>>>>       (org-element-map (org-element-parse-buffer) 'fixed-width
>>>>>         (lambda (object)
>>>>>           (if results
>>>>>               ;; replace value in block
>>>>>               (setf
>>>>>                (buffer-substring
>>>>>                 (org-element-property :begin  object)
>>>>>                 (org-element-property :end  object))
>>>>>                results)
>>>>>             ;; set results
>>>>>             (setq results
>>>>>                   (buffer-substring
>>>>>                    (org-element-property :begin  object)
>>>>>                    (org-element-property :end  object)))))))))
>>>>> #+END_SRC
>>>>> #+BEGIN_SRC emacs-lisp
>>>>> (add-hook 'org-babel-after-execute-hook 'update-results)
>>>>> #+END_SRC
>>>>>
>>>>> This worked on a small test example, but I did not test it
>>>>> thoroughly. your mileage might vary ;)
>>>>
>>>> This looks nice - I will try it out and see how it goes.
>>>
>>>
>>> I don't get it to work.
>>>
>>> I put the following into my emacs.org and evaluated it:
>>>
>>> --8<---------------cut here---------------start------------->8---
>>> (defun rmk/update-multiple-results-blocks () (interactive)
>>>        ;; get name of src block
>>>        (let ((name (org-element-property :name (org-element-at-point)))
>>>              (results))
>>>          (when name
>>>            (org-element-map (org-element-parse-buffer) 'fixed-width
>>>              (lambda (object)
>>>                (if results
>>>                    ;; replace value in block
>>>                    (setf
>>>                     (buffer-substring
>>>                      (org-element-property :begin  object)
>>>                      (org-element-property :end  object))
>>>                     results)
>>>                  ;; set results
>>>                  (setq results
>>>                        (buffer-substring
>>>                         (org-element-property :begin  object)
>>>                         (org-element-property :end  object)))))))))
>>>
>>> #+end_src
>>>
>>> #+RESULTS:
>>> : rmk/update-multiple-results-blocks
>>>
>>> Add this function to =org-babel=after-execute-hook=
>>> #+begin_src emacs-lisp
>>> (add-hook 'org-babel-after-execute-hook 'rmk/update-multiple-results-blocks)
>>> #+end_src
>>>
>>> #+RESULTS:
>>> | rmk/update-multiple-results-blocks |
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>>
>>> I am using the following org file to test it:
>>>
>>> --8<---------------cut here---------------start------------->8---
>>> * The calculation
>>> #+NAME: testcode
>>> #+begin_src R :session test
>>> runif(10)
>>> #+end_src
>>>
>>> * summary of the results
>>> First time
>>> #+RESULTS: testcode
>>> |  0.471471928292885 |
>>> |  0.128247044514865 |
>>> |  0.398714824113995 |
>>> |  0.335577708436176 |
>>> | 0.0184990330599248 |
>>> |  0.952211205149069 |
>>> |  0.367342215497047 |
>>> |  0.581879974342883 |
>>> |  0.440492485417053 |
>>> | 0.0729096119757742 |
>>>
>>>
>>> #+RESULTS: testcode
>>> | 0.0095007149502635 |
>>> | 0.0898537992034107 |
>>> |  0.764667606214061 |
>>> | 0.0309854068327695 |
>>> |  0.510338442632928 |
>>> |  0.220906731439754 |
>>> |  0.589271233882755 |
>>> |  0.966699115466326 |
>>> | 0.0183747289702296 |
>>> |  0.734954049577937 |
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>> But only the first results block is updated. The function
>>> =rmk/update-multiple-results-blocks= is executed.
>>>
>>> I am using
>>>
>>> ,----
>>> | Org-mode version 8.3beta (release_8.3beta-884-g9ed426 @ /Users/rainerkrug/.emacs.d/org-mode/lisp/)
>>> | GNU Emacs 24.4.1 (x86_64-apple-darwin14.0.0, Carbon Version 157
>>> | AppKit 1343.16) of 2015-02-02 on Rainers-MacBook-Pro-4.local
>>> `----
>>>
>>> Any ideas what is going wrong?
>>>
>>> Thanks,
>>>
>>> Rainer
>>>
>>>
>>>>
>>>>
>>>>>
>>>>>
>>>>> Rainer M Krug writes:
>>>>>
>>>>>> Hi
>>>>>>
>>>>>> Consider the following:
>>>>>>
>>>>>> --8<---------------cut here---------------start------------->8---
>>>>>> * The calculation
>>>>>> #+NAME: testcode :exports both
>>>>>> #+begin_src R  :session test
>>>>>> runif(10)
>>>>>> #+end_src
>>>>>>
>>>>>>
>>>>>> * summary of the results
>>>>>> First time
>>>>>> #+RESULTS: testcode :exports both
>>>>>> |  0.772744940361008 |
>>>>>> |  0.170518629485741 |
>>>>>> | 0.0833237133920193 |
>>>>>> |  0.149035625392571 |
>>>>>> |  0.698798568220809 |
>>>>>> |  0.627075897762552 |
>>>>>> |  0.177144371205941 |
>>>>>> | 0.0476319056469947 |
>>>>>> |  0.289851602632552 |
>>>>>> | 0.0296813279855996 |
>>>>>>
>>>>>> * and another
>>>>>> testthingy
>>>>>> #+RESULTS: testcode :exports both
>>>>>>
>>>>>> --8<---------------cut here---------------end--------------->8---
>>>>>>
>>>>>> If I update the calculation, the first results block is updated, but
>>>>>> not the second one. I would like to have two RESULTS blocks which
>>>>>> are both updated when the code block is evaluated.
>>>>>>
>>>>>> Is this possible?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Rainer
>>>>>
>>>>> --
>>>>> Professor John Kitchin
>>>>> Doherty Hall A207F
>>>>> Department of Chemical Engineering
>>>>> Carnegie Mellon University
>>>>> Pittsburgh, PA 15213
>>>>> 412-268-7803
>>>>> @johnkitchin
>>>>> http://kitchingroup.cheme.cmu.edu
>>>>>
>>>>>
>>
>> --
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

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

end of thread, other threads:[~2015-03-10 13:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-09 10:04 Multiple (identical) RESULTS blocks of one code block? Rainer M Krug
2015-03-09 13:01 ` John Kitchin
2015-03-09 13:10   ` Sebastien Vauban
2015-03-10  9:06   ` Rainer M Krug
2015-03-10  9:35     ` Rainer M Krug
     [not found]       ` <m2sidd2ems.fsf@andrew.cmu.edu>
2015-03-10 13:31         ` Rainer M Krug
2015-03-10 13:57           ` Rainer M Krug
2015-03-09 16:34 ` Nicolas Goaziou
2015-03-10  2:05 ` Aaron Ecay
2015-03-10  9:02   ` 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).