emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[FR] Append wrapped results from babel block (was: Appending results fro


From: Ihor Radchenko
Subject: [FR] Append wrapped results from babel block (was: Appending results from babel block)
Date: Tue, 30 Jan 2024 12:28:38 +0000

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>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]