emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* babel result chain outdated/inconsistent using var
@ 2016-04-06 12:01 Daniele Pizzolli
  2016-04-06 12:54 ` Nicolas Goaziou
  0 siblings, 1 reply; 9+ messages in thread
From: Daniele Pizzolli @ 2016-04-06 12:01 UTC (permalink / raw)
  To: Org-mode

Hello,

is possible to update the “#+RESULTS: pid” when the block “#+NAME:
echo-pid” is evaluated in the following snippet?

This will lead to a consistent document generation with “M-x
org-babel-execute-buffer” or by hitting “C-c C-c” on “#+NAME:
echo-pid”.  Using the cache does not make sense: the process is
generating different output every time.

The info at “M-: (info "(org) Specific header arguments")” does not
mention something useful.

* Intro

** pid

#+NAME: pid
#+BEGIN_SRC shell :results value :cache no
printf '%s' "${$}"
#+END_SRC

The following result is usually outdated/inconsistent!

#+RESULTS: pid
: 25272

** echo pid

#+NAME: echo-pid
#+BEGIN_SRC shell :var DATA=pid :results value
printf '%s' "${DATA}"
#+END_SRC

#+RESULTS: echo-pid
: 25273

The code block in pid is evaluated every time, but the results are
used only to populate the pid variable and non for updating the
results in the buffer:

#+BEGIN_EXAMPLE
executing Shell code block (pid)...
Wrote /tmp/babel-4889iZN/ob-input-4889CyZ
"25273"
executing Shell code block (echo-pid)...
Wrote /tmp/babel-4889iZN/ob-input-48892ay
Code block evaluation complete.
#+END_EXAMPLE

This was tested with Org-mode version 8.3.4 release_8.3.4-705-g716e33.

Thanks in advance for your suggestions,
Daniele

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

* Re: babel result chain outdated/inconsistent using var
  2016-04-06 12:01 babel result chain outdated/inconsistent using var Daniele Pizzolli
@ 2016-04-06 12:54 ` Nicolas Goaziou
  2016-04-06 13:27   ` Daniele Pizzolli
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2016-04-06 12:54 UTC (permalink / raw)
  To: Daniele Pizzolli; +Cc: Org-mode

Hello,

Daniele Pizzolli <dan@toel.it> writes:

> is possible to update the “#+RESULTS: pid” when the block “#+NAME:
> echo-pid” is evaluated in the following snippet?

Without `org-babel-execute-buffer', I don't think so.

> This will lead to a consistent document generation with “M-x
> org-babel-execute-buffer” or by hitting “C-c C-c” on “#+NAME:
> echo-pid”.

I'm not convinced that this behaviour should be enforced. If I C-c C-c
on a block, I expect only the results of the block to be updated, not
some other part of the document I am editing. 

Also, what if the other block is in another document? I don't think it
should be updated either.

What is the harm in using `org-babel-execute-buffer' for your use case?

Regards,

-- 
Nicolas Goaziou

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

* Re: babel result chain outdated/inconsistent using var
  2016-04-06 12:54 ` Nicolas Goaziou
@ 2016-04-06 13:27   ` Daniele Pizzolli
  2016-04-06 19:27     ` Nicolas Goaziou
  0 siblings, 1 reply; 9+ messages in thread
From: Daniele Pizzolli @ 2016-04-06 13:27 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org-mode

On Wed, Apr 06 2016, Nicolas Goaziou wrote:

> Hello,
>
> Daniele Pizzolli <dan@toel.it> writes:
>
>> is possible to update the “#+RESULTS: pid” when the block “#+NAME:
>> echo-pid” is evaluated in the following snippet?
>
> Without `org-babel-execute-buffer', I don't think so.

Hello,

Thanks Nicolas for the reply.  Ok, but `org-babel-execute-buffer'
produces an inconsistent document right now.

>> This will lead to a consistent document generation with “M-x
>> org-babel-execute-buffer” or by hitting “C-c C-c” on “#+NAME:
>> echo-pid”.
>
> I'm not convinced that this behaviour should be enforced. If I C-c C-c
> on a block, I expect only the results of the block to be updated, not
> some other part of the document I am editing.

Mmm, the same reasoning can be used for arguing about the current
behaviour: If I C-c C-c on a block, I expect only the code of the
block to be executed, not some other part of the document I am
editing.  This behaviour will fix my issue.

I agree that neither case should be enforced, but the user should be
in charge to choose.  A reasonable default behaviour will be to not
re-execute the other code block if the previous result is already
present.

> Also, what if the other block is in another document? I don't think it
> should be updated either.

But should it be either executed?

> What is the harm in using `org-babel-execute-buffer' for your use case?

Right now it does not produce a consistent document, that should be
desirable.

I do not have a strong preference about the solution (reuse without
re-execute, or update the other result) but for sure, right now there
is no way to produce a consistent document.

I tried for a workaround, adding `:eval query'

#+NAME: pid
#+BEGIN_SRC shell :results value :cache no :eval query
printf '%s' "${$}"
#+END_SRC

and then discarding the execution, but instead of reusing the actual
result it pass `nil'... no luck.

Thanks again,
Daniele

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

* Re: babel result chain outdated/inconsistent using var
  2016-04-06 13:27   ` Daniele Pizzolli
@ 2016-04-06 19:27     ` Nicolas Goaziou
  2016-04-07  8:12       ` Daniele Pizzolli
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2016-04-06 19:27 UTC (permalink / raw)
  To: Daniele Pizzolli; +Cc: Org-mode

Daniele Pizzolli <dan@toel.it> writes:

> Thanks Nicolas for the reply.  Ok, but `org-babel-execute-buffer'
> produces an inconsistent document right now.

This is because you ask it to. See below.

> Mmm, the same reasoning can be used for arguing about the current
> behaviour: If I C-c C-c on a block, I expect only the code of the
> block to be executed, not some other part of the document I am
> editing.  This behaviour will fix my issue.

You are explicitly asking for a re-execution of a remote source block:

  :var DATA=pid

If you are only interested in the results, you should name them, and use
that instead, e.g.

  #+NAME: pid
  #+BEGIN_SRC shell :results value :cache no
  printf '%s' "${$}"
  #+END_SRC

  The following result is usually outdated/inconsistent!

  #+NAME: pid-result
  #+RESULTS: pid
  : 21867

  #+NAME: echo-pid
  #+BEGIN_SRC shell :var DATA=pid-result :results value
  printf '%s' "${DATA}"
  #+END_SRC

  #+RESULTS: echo-pid
  : 21867


Regards,

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

* Re: babel result chain outdated/inconsistent using var
  2016-04-06 19:27     ` Nicolas Goaziou
@ 2016-04-07  8:12       ` Daniele Pizzolli
  2016-04-07  8:50         ` Nicolas Goaziou
  0 siblings, 1 reply; 9+ messages in thread
From: Daniele Pizzolli @ 2016-04-07  8:12 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org-mode

On Wed, Apr 06 2016, Nicolas Goaziou wrote:

> Daniele Pizzolli writes:
>
>> Thanks Nicolas for the reply.  Ok, but `org-babel-execute-buffer'
>> produces an inconsistent document right now.
>
> This is because you ask it to. See below.
>
>> Mmm, the same reasoning can be used for arguing about the current
>> behaviour: If I C-c C-c on a block, I expect only the code of the
>> block to be executed, not some other part of the document I am
>> editing.  This behaviour will fix my issue.
>
> You are explicitly asking for a re-execution of a remote source block:
>
>   :var DATA=pid
>
> If you are only interested in the results, you should name them, and use
> that instead, e.g.

Hello,

Oh, thanks Nicolas for the tip.  But it does not work in a reliable
manner.

Calling `org-babel-execute-buffer' in the following snippet, raises:
(error "Reference `pid-result' not found in this buffer")

#+NAME: pid
#+BEGIN_SRC shell :results value :cache no
printf '%s' "${$}"
#+END_SRC

#+NAME: pid-result
#+RESULTS: pid

#+NAME: echo-pid
#+BEGIN_SRC shell :var DATA=pid-result :results value
printf '%s' "${DATA}"
#+END_SRC

#+RESULTS: echo-pid

Using the C-c C-c on the blocks also does not work...  unless you also
do a C-c C-c on `#+NAME: pid-result' which is cumbersome if you have a
chain of blocks and results.  Do you think that this can be fixed
easily?

Thanks in advance,
Daniele

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

* Re: babel result chain outdated/inconsistent using var
  2016-04-07  8:12       ` Daniele Pizzolli
@ 2016-04-07  8:50         ` Nicolas Goaziou
  2016-04-07  9:22           ` Daniele Pizzolli
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2016-04-07  8:50 UTC (permalink / raw)
  To: Daniele Pizzolli; +Cc: Org-mode

Hello,

Daniele Pizzolli <dan@toel.it> writes:

> #+NAME: pid-result
> #+RESULTS: pid
> #+NAME: echo-pid
> #+BEGIN_SRC shell :var DATA=pid-result :results value
> printf '%s' "${DATA}" #+END_SRC
>
> #+RESULTS: echo-pid

You are giving two names to the block, which is not possible. 

I don't know what you are trying to do here but you seem to confuse
blocks with their results. They can be named independently.

Regards,

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

* Re: babel result chain outdated/inconsistent using var
  2016-04-07  8:50         ` Nicolas Goaziou
@ 2016-04-07  9:22           ` Daniele Pizzolli
  2016-04-07  9:50             ` Nicolas Goaziou
  0 siblings, 1 reply; 9+ messages in thread
From: Daniele Pizzolli @ 2016-04-07  9:22 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org-mode

On Thu, Apr 07 2016, Nicolas Goaziou wrote:

> Hello,
>
> Daniele Pizzolli writes:
>
>> #+NAME: pid-result
>> #+RESULTS: pid
>> #+NAME: echo-pid
>> #+BEGIN_SRC shell :var DATA=pid-result :results value
>> printf '%s' "${DATA}" #+END_SRC
>>
>> #+RESULTS: echo-pid
>
> You are giving two names to the block, which is not possible.

Hello,

Sorry for the confusion, I deleted one line more than the result ones.
I guess a new line or a comment or a text is enough to separate the
blocks.

> I don't know what you are trying to do here but you seem to confuse
> blocks with their results. They can be named independently.

I copied your example without the results, here is the updated
version, and even with a comment between the block produces the same
error `(error "Reference `pid-result' not found in this buffer")'
after calling `org-babel-execute-buffer'

#+NAME: pid
#+BEGIN_SRC shell :results value :cache no
printf '%s' "${$}"
#+END_SRC

#+NAME: pid-result
#+RESULTS: pid

# Some comment is required here to separate blocks, but it does not
# work either

#+NAME: echo-pid
#+BEGIN_SRC shell :var DATA=pid-result :results value
printf '%s' "${DATA}"
#+END_SRC

#+RESULTS: echo-pid

Do I am missing something else?  Thanks again for your assistance.
Daniele

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

* Re: babel result chain outdated/inconsistent using var
  2016-04-07  9:22           ` Daniele Pizzolli
@ 2016-04-07  9:50             ` Nicolas Goaziou
  2016-04-07 11:16               ` Daniele Pizzolli
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2016-04-07  9:50 UTC (permalink / raw)
  To: Daniele Pizzolli; +Cc: Org-mode

Daniele Pizzolli <dan@toel.it> writes:

> Do I am missing something else?  Thanks again for your assistance.

There seems to be an issue with cache. Call `M-x
org-element-reset-cache' before calling `org-babel-execute-buffer'.

Regards,

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

* Re: babel result chain outdated/inconsistent using var
  2016-04-07  9:50             ` Nicolas Goaziou
@ 2016-04-07 11:16               ` Daniele Pizzolli
  0 siblings, 0 replies; 9+ messages in thread
From: Daniele Pizzolli @ 2016-04-07 11:16 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org-mode

On Thu, Apr 07 2016, Nicolas Goaziou wrote:

> Daniele Pizzolli writes:
>
>> Do I am missing something else?  Thanks again for your assistance.
>
> There seems to be an issue with cache. Call `M-x
> org-element-reset-cache' before calling `org-babel-execute-buffer'.

Hello,

thanks, to be precise this is required to be iterated for every empty
(without result output) named result block (if they are in chain) in
the buffer.

Not straightforward but I can live with that workaround.  Once all the
result block are populated, `M-x org-babel-execute-buffer' updates the
results in a consistent way without the need of `M-x
org-element-reset-cache' call.

Thanks Nicolas for your support,
Daniele

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

end of thread, other threads:[~2016-04-07 11:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-06 12:01 babel result chain outdated/inconsistent using var Daniele Pizzolli
2016-04-06 12:54 ` Nicolas Goaziou
2016-04-06 13:27   ` Daniele Pizzolli
2016-04-06 19:27     ` Nicolas Goaziou
2016-04-07  8:12       ` Daniele Pizzolli
2016-04-07  8:50         ` Nicolas Goaziou
2016-04-07  9:22           ` Daniele Pizzolli
2016-04-07  9:50             ` Nicolas Goaziou
2016-04-07 11:16               ` Daniele Pizzolli

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