all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How is the return value of `org-babel-execute:FOO` interpreted?
@ 2021-10-02 13:27 Kodi Arfer
  0 siblings, 0 replies; 8+ messages in thread
From: Kodi Arfer @ 2021-10-02 13:27 UTC (permalink / raw)
  To: emacs-orgmode

I have an `org-babel-execute` function for the Hy programming language that seems to have partly broken when I upgraded Org (from 9.1.14 to 9.4.6). It has code to write a plot to a file when a `:file` argument is given to the code block. It returns `nil` in this case, and previously, Org would automatically insert a link to the file in the results block, as desired. Now, however, the `nil` is printed in the results block. So I guess have to edit the function to return a link instead, but I can't find documentation for how Org interprets the return value of an `org-babel-execute` function: as I vaguely recall, you have to use a certain cons structure to produce a table, another to produce a link, and so on. So the concrete question in this case is: what do I return to put a link in the document?

Here's my code in case it's helpful, but it isn't pretty: https://github.com/Kodiologist/Daylight/blob/37e38d216ffe41ad3537522c40ccf1cdb134bbbc/daylight.el#L430


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

* How is the return value of `org-babel-execute:FOO` interpreted?
@ 2021-10-02 16:43 Kodi Arfer
  2021-10-03  9:38 ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Kodi Arfer @ 2021-10-02 16:43 UTC (permalink / raw)
  To: emacs-orgmode

I have an `org-babel-execute` function for the Hy programming language that seems to have partly broken when I upgraded Org (from 9.1.14 to 9.4.6). It has code to write a plot to a file when a `:file` argument is given to the code block. It returns `nil` in this case, and previously, Org would automatically insert a link to the file in the results block, as desired. Now, however, the `nil` is printed in the results block. So I guess have to edit the function to return a link instead, but I can't find documentation for how Org interprets the return value of an `org-babel-execute` function: as I vaguely recall, you have to use a certain cons structure to produce a table, another to produce a link, and so on. So the concrete question in this case is: what do I return to put a link in the document?

Here's my code in case it's helpful, but it isn't pretty: https://github.com/Kodiologist/Daylight/blob/37e38d216ffe41ad3537522c40ccf1cdb134bbbc/daylight.el#L430


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

* Re: How is the return value of `org-babel-execute:FOO` interpreted?
  2021-10-02 16:43 How is the return value of `org-babel-execute:FOO` interpreted? Kodi Arfer
@ 2021-10-03  9:38 ` Ihor Radchenko
  2021-10-03 12:03   ` Kodi Arfer
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2021-10-03  9:38 UTC (permalink / raw)
  To: Kodi Arfer; +Cc: emacs-orgmode

Kodi Arfer <listu@arfer.net> writes:

> I have an `org-babel-execute` function for the Hy programming language that seems to have partly broken when I upgraded Org (from 9.1.14 to 9.4.6). It has code to write a plot to a file when a `:file` argument is given to the code block. It returns `nil` in this case, and previously, Org would automatically insert a link to the file in the results block, as desired. Now, however, the `nil` is printed in the results block. So I guess have to edit the function to return a link instead, but I can't find documentation for how Org interprets the return value of an `org-babel-execute` function: as I vaguely recall, you have to use a certain cons structure to produce a table, another to produce a link, and so on. So the concrete question in this case is: what do I return to put a link in the document?

I just tested using ob-gnuplot and :file link is correctly inserted when
org-babel-execute:gnuplot returns nil.

Are you sure that you have :file parameter in the source block you tried
to execute?

Best,
Ihor



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

* Re: How is the return value of `org-babel-execute:FOO` interpreted?
  2021-10-03  9:38 ` Ihor Radchenko
@ 2021-10-03 12:03   ` Kodi Arfer
  2021-10-03 12:20     ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Kodi Arfer @ 2021-10-03 12:03 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On 2021 Oct 03 Sun 5:38:10 AM -0400, Ihor Radchenko <yantar92@gmail.com> wrote:
> Kodi Arfer <listu@arfer.net> writes:
>> I have an `org-babel-execute` function for the Hy programming
>> language that seems to have partly broken when I upgraded Org (from
>> 9.1.14 to 9.4.6). …
> 
> I just tested using ob-gnuplot and :file link is correctly inserted when
> org-babel-execute:gnuplot returns nil.
> 
> Are you sure that you have :file parameter in the source block you tried
> to execute?

Yes, this is my code block:

#+begin_src hy :file g/foo.png
(plt.scatter [1 2 3] [4 5 -9])
#+end_src

And it looks like `org-babel-execute:hy` is indeed receiving the argument, since `(message "%s" (assq :file (org-babel-process-params params)))` prints "(:file . g/foo.png)".


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

* Re: How is the return value of `org-babel-execute:FOO` interpreted?
  2021-10-03 12:03   ` Kodi Arfer
@ 2021-10-03 12:20     ` Ihor Radchenko
  2021-10-03 12:39       ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2021-10-03 12:20 UTC (permalink / raw)
  To: Kodi Arfer; +Cc: emacs-orgmode

Kodi Arfer <listu@arfer.net> writes:

>> Are you sure that you have :file parameter in the source block you tried
>> to execute?
>
> Yes, this is my code block:
>
> #+begin_src hy :file g/foo.png
> (plt.scatter [1 2 3] [4 5 -9])
> #+end_src

What about

#+begin_src hy :results file :file g/foo.png
(plt.scatter [1 2 3] [4 5 -9])
#+end_src

?

Best,
Ihor


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

* Re: How is the return value of `org-babel-execute:FOO` interpreted?
  2021-10-03 12:20     ` Ihor Radchenko
@ 2021-10-03 12:39       ` Ihor Radchenko
  2021-10-03 12:49         ` Kodi Arfer
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2021-10-03 12:39 UTC (permalink / raw)
  To: Kodi Arfer; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

> Kodi Arfer <listu@arfer.net> writes:
>
>>> Are you sure that you have :file parameter in the source block you tried
>>> to execute?
>>
>> Yes, this is my code block:
>>
>> #+begin_src hy :file g/foo.png
>> (plt.scatter [1 2 3] [4 5 -9])
>> #+end_src
>
> What about
>
> #+begin_src hy :results file :file g/foo.png
> (plt.scatter [1 2 3] [4 5 -9])
> #+end_src
>
> ?

If this code works for you, the problem is the folloing incompatible
change in Org 9.3 (see etc/ORG-NEWS file in the repo):

* Version 9.3
** Incompatible changes
*** ~:file~ header argument no longer assume "file" ~:results~

The "file" ~:results~ value is now mandatory for a code block
returning a link to a file.  The ~:file~ or ~:file-ext~ header
arguments no longer imply a "file" result is expected.

Best,
Ihor


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

* Re: How is the return value of `org-babel-execute:FOO` interpreted?
  2021-10-03 12:39       ` Ihor Radchenko
@ 2021-10-03 12:49         ` Kodi Arfer
  2021-10-03 13:09           ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Kodi Arfer @ 2021-10-03 12:49 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On 2021 Oct 03 Sun 8:39:37 AM -0400, Ihor Radchenko <yantar92@gmail.com> wrote:
> Ihor Radchenko <yantar92@gmail.com> writes:
> 
>> Kodi Arfer <listu@arfer.net> writes:
>>
>>>> Are you sure that you have :file parameter in the source block you tried
>>>> to execute?
>>>
>>> Yes, this is my code block:
>>>
>>> #+begin_src hy :file g/foo.png
>>> (plt.scatter [1 2 3] [4 5 -9])
>>> #+end_src
>>
>> What about
>>
>> #+begin_src hy :results file :file g/foo.png
>> (plt.scatter [1 2 3] [4 5 -9])
>> #+end_src
>>
>> ?
> 
> If this code works for you, the problem is the folloing incompatible
> change in Org 9.3 (see etc/ORG-NEWS file in the repo):
> 
> * Version 9.3
> ** Incompatible changes
> *** ~:file~ header argument no longer assume "file" ~:results~
> 
> The "file" ~:results~ value is now mandatory for a code block
> returning a link to a file.  The ~:file~ or ~:file-ext~ header
> arguments no longer imply a "file" result is expected.

It works, thank you. I should've looked at the changelog more closely. I wonder why this change was made. It would be annoyingly redundant to put `:results file` next to every `:file`. I already have code to change the default value of `:results` when `:file` is set, for a different Babel language, so I should be able to adapt that to this language.


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

* Re: How is the return value of `org-babel-execute:FOO` interpreted?
  2021-10-03 12:49         ` Kodi Arfer
@ 2021-10-03 13:09           ` Ihor Radchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Ihor Radchenko @ 2021-10-03 13:09 UTC (permalink / raw)
  To: Kodi Arfer; +Cc: emacs-orgmode

Kodi Arfer <listu@arfer.net> writes:

> It works, thank you. I should've looked at the changelog more closely. I wonder why this change was made. It would be annoyingly redundant to put `:results file` next to every `:file`. I already have code to change the default value of `:results` when `:file` is set, for a different Babel language, so I should be able to adapt that to this language.

There are tools like subtree-local headers args or default headers args
at your disposal.

The argument why that change was made is the following (commit 26ed66b23):

>> Deducing the results from some other arguments is not obvious.
>> Moreover, it prevents users from setting, e.g., :file-ext, in a node
>> property, as every block would then create a file.
>> 
>> Reported-by: Alex Fenton <alex@pressure.to>
>> <http://lists.gnu.org/r/emacs-orgmode/2018-05/msg00469.html>

Best,
Ihor


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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-02 16:43 How is the return value of `org-babel-execute:FOO` interpreted? Kodi Arfer
2021-10-03  9:38 ` Ihor Radchenko
2021-10-03 12:03   ` Kodi Arfer
2021-10-03 12:20     ` Ihor Radchenko
2021-10-03 12:39       ` Ihor Radchenko
2021-10-03 12:49         ` Kodi Arfer
2021-10-03 13:09           ` Ihor Radchenko
  -- strict thread matches above, loose matches on Subject: below --
2021-10-02 13:27 Kodi Arfer

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.