emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Appending results from babel block
@ 2024-01-27  3:19 Ken Mankoff
  2024-01-27 20:22 ` Matt
  0 siblings, 1 reply; 4+ messages in thread
From: Ken Mankoff @ 2024-01-27  3:19 UTC (permalink / raw)
  To: Org-mode list

Hello,

I'd like to append results from a babel block, but without the leading ":" that sometimes appears. Is this possible. I'm using v9.7-pre.

This works, but has leading colons:

#+BEGIN_SRC bash :results append
echo $(date)
#+END_SRC

#+RESULTS:
: Fri Jan 26 07:17:00 PM PST 2024
: Fri Jan 26 07:17:01 PM PST 2024
: Fri Jan 26 07:17:02 PM PST 2024
: Fri Jan 26 07:17:04 PM PST 2024

Setting :results append raw

prepends - understandably because 'raw' means there is no delimiter, and no way to know where the results end.

Weirdly,

:results append drawer

Appends result #2, but then inserts all results after the first.

Is this last behavior a bug? Any way to have true 'append' w/o ":"?

Thanks,

  -k.


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

* Re: Appending results from babel block
  2024-01-27  3:19 Appending results from babel block Ken Mankoff
@ 2024-01-27 20:22 ` Matt
  2024-01-28  0:53   ` Ken Mankoff
  0 siblings, 1 reply; 4+ messages in thread
From: Matt @ 2024-01-27 20:22 UTC (permalink / raw)
  To: Ken Mankoff; +Cc: Org-mode list


 ---- On Sat, 27 Jan 2024 03:20:37 +0100  Ken Mankoff  wrote --- 
 
 > I'd like to append results from a babel block, but without the leading ":" that sometimes appears. Is this possible. I'm using v9.7-pre.

AFAIK, the only ways are to use 'raw' or something that wraps the result, like :wrap or 'drawer'.  As you observed, using 'raw' will "prepend" the latest output because Org doesn't consider the previous output a result.

I'm curious, what broader goal are you trying to achieve?  How does the leading ":" stop you?

 > Weirdly,
 > 
 > :results append drawer
 > 
 > Appends result #2, but then inserts all results after the first.
 
I'm not sure what you mean.  However, trying it, I see bunches of "results-end" groups.  I assume this is what you see, too?

#+BEGIN_SRC bash :results append drawer
echo "$(date)"
#+END_SRC

#+RESULTS:
:results:
Sat Jan 27 09:11:21 PM CET 2024
:end:
:results:
Sat Jan 27 09:11:21 PM CET 2024
:end:
:results:
Sat Jan 27 09:11:21 PM CET 2024
:end:

 > Is this last behavior a bug?

That's a good question.  Skimming the manual, I didn't see mention of it, although I may have missed it.  The behavior I see doesn't match my expectation.  I would expect to see:

#+RESULTS:
:results:
Sat Jan 27 09:11:21 PM CET 2024
Sat Jan 27 09:11:21 PM CET 2024
Sat Jan 27 09:11:21 PM CET 2024
:end:

--
Matt Trzcinski
Emacs Org contributor (ob-shell)
Learn more about Org mode at https://orgmode.org
Support Org development at https://liberapay.com/org-mode



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

* Re: Appending results from babel block
  2024-01-27 20:22 ` Matt
@ 2024-01-28  0:53   ` Ken Mankoff
  2024-01-30 12:28     ` [FR] Append wrapped results from babel block (was: Appending results from babel block) Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Ken Mankoff @ 2024-01-28  0:53 UTC (permalink / raw)
  To: Matt; +Cc: Org-mode list

Hi Matt,

On 2024-01-27 at 12:22 -08, Matt <matt@excalamus.com> wrote...
>  ---- On Sat, 27 Jan 2024 03:20:37 +0100 Ken Mankoff wrote ---
>> Weirdly,
>> 
>> :results append drawer
>> 
>> Appends result #2, but then inserts all results after the first.
>  
> I'm not sure what you mean. However, trying it, I see bunches of
> "results-end" groups. I assume this is what you see, too?

Yes that's what I see in general format. You ran it 3x in on second so I can't very we're seeing the same thing. But the order becomes

1
5
4
3
2

That is, 2 is appended as expected, but then 3 is inserted after 1 but before 2, 4 is after 1 but before 3, etc.

> I would expect to see:

Again, all your strings appear the same so I can' verify order. I don't mind multiple :results: :end: drawers, I just want the order to be

1
2
3
4
5


> I'm curious, what broader goal are you trying to achieve? How does the
> leading ":" stop you?

I have a beancount (plain text accounting) file that is an Org file. Beancount parsing of that file ignores lines that start with "*" or "#", so I can organize finances by heading. The beancount parser fails on lines that begin with ":"

Under a given set of headings, e.g.,

* Finances
** Assets
*** Bank Foo
**** Checking

I parse the bank data (code defined elsewhere via library-of-babel) and convert to Beancount syntax with:

#+CALL: bank2bc()

I'd like to evaluate (C-c C-c) that CALL when I get a new statement each month, and have results appended, not prepended.

For accounts with a lot of transactions, I add a new  heading, and then this issue goes away.

***** 2024-01

But for accounts with few transactions, I'd like to break it by year not month, and have transactions appear in chronological order.


  -k.


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

* [FR] Append wrapped results from babel block (was: Appending results from babel block)
  2024-01-28  0:53   ` Ken Mankoff
@ 2024-01-30 12:28     ` Ihor Radchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2024-01-30 12:28 UTC (permalink / raw)
  To: Ken Mankoff; +Cc: Matt, Org-mode list

Ken Mankoff <mankoff@gmail.com> writes:

>>> Weirdly,
>>> 
>>> :results append drawer
>>> 
>>> Appends result #2, but then inserts all results after the first.
>>  
>> I'm not sure what you mean. However, trying it, I see bunches of
>> "results-end" groups. I assume this is what you see, too?
>
> Yes that's what I see in general format. You ran it 3x in on second so I can't very we're seeing the same thing. But the order becomes
>
> 1
> 5
> 4
> 3
> 2
>
> That is, 2 is appended as expected, but then 3 is inserted after 1 but before 2, 4 is after 1 but before 3, etc.

This is expected, because Org mode has no way to know which drawers are
related to results and which are not.

Let me illustrate with an example:

#+begin_src ... :results append drawer
...
#+end_src

:drawer:
I have nothing to do with the above src block
:end:

When you evaluate the code block, Org mode searches for #+RESULTS:
keyword to mark the results. If there is none, it adds it:

#+begin_src ... :results append drawer
...
#+end_src

#+RESULTS:
:drawer:
1
:end:
:drawer:
I have nothing to do with the above src block
:end:

Now, when you ask Org mode to append to result, it will find the drawer
with #+results: keyword and insert the new result _after_:

#+begin_src ... :results append drawer
...
#+end_src

#+RESULTS:
:drawer:
1
:end:
:drawer:
2
:end:
:drawer:
I have nothing to do with the above src block
:end:

If we now execute the source code block again, Org mode will have no
idea that the "2" drawer has anything to do with results of evaluation,
because it has no :RESULTS: keyword. Only the first drawer is
considered. Hence, Org mode appends the result after "1" again:

#+begin_src ... :results append drawer
...
#+end_src

#+RESULTS:
:drawer:
1
:end:
:drawer:
3
:end:
:drawer:
2
:end:
:drawer:
I have nothing to do with the above src block
:end:

That's how the sequence your observe is constructed.

When you do not use :results drawer, it happens so that subsequent

: 1
: 2

are not creating two separate syntax objects, but are merged into a
single fixed-width markup. So, appending works just fine.

----

Now, indeed, the above situation with drawers (and :wrap in general) is
confusing.

What we might do is modify `org-babel-insert-result' so that it unwraps
and re-wraps the existing result when it has exactly the same wrap
style. That might be a nice new feature to have.
Patches welcome!

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

end of thread, other threads:[~2024-01-30 12:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-27  3:19 Appending results from babel block Ken Mankoff
2024-01-27 20:22 ` Matt
2024-01-28  0:53   ` Ken Mankoff
2024-01-30 12:28     ` [FR] Append wrapped results from babel block (was: Appending results from babel block) Ihor Radchenko

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