emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Ken Mankoff <mankoff@gmail.com>
Cc: Matt <matt@excalamus.com>, Org-mode list <emacs-orgmode@gnu.org>
Subject: [FR] Append wrapped results from babel block (was: Appending results from babel block)
Date: Tue, 30 Jan 2024 12:28:38 +0000	[thread overview]
Message-ID: <87jznr80p5.fsf@localhost> (raw)
In-Reply-To: <87fryigtx7.fsf@gmail.com>

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	other threads:[~2024-01-30 12:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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     ` Ihor Radchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87jznr80p5.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=mankoff@gmail.com \
    --cc=matt@excalamus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).