From: Immanuel Litzroth <immanuel.litzroth@gmail.com>
To: Martin Jerabek <om@mailservice.ms>
Cc: emacs-orgmode@gnu.org
Subject: Re: Babel C-mode corrupts double-quoted strings in output
Date: Wed, 31 Aug 2022 20:03:43 +0200 [thread overview]
Message-ID: <CAM1nAcwS35TXGRc+FnFdBUgmqkucfdeissRs3Rzq1Uf5U1Egog@mail.gmail.com> (raw)
In-Reply-To: <bc004962-679e-498f-b245-ae253aae6271@www.fastmail.com>
I would advise you not to use org babel for compiled languages. There
is just too
much stuff that doesn't work well and multifile dependencies & build
systems are
just plain hard to get right. Debugging is annoying and getting org
babel to tell
you compiler where the source actually came from is impossible, if the language
even supports #line and #file directives (Rust still doesn't).
Immanuel Litzroth
On Wed, Aug 31, 2022 at 6:38 PM Martin Jerabek <om@mailservice.ms> wrote:
>
> Hi!
>
> I recently started to use Org Babel for C++ programs. One of the programs outputs several lines with double-quoted strings, similar to this:
>
> #+NAME: doublequotes_cpp
> #+begin_src cpp :includes <iostream> :results output verbatim raw
> std::cout << "\"line 1\"\n";
> std::cout << "\"line 2\"\n";
> std::cout << "\"line 3\"\n";
> #+end_src
>
> #+RESULTS: doublequotes_cpp
> line 1
>
> As you can see, only the first line is copied to the RESULTS block, and it is stripped of the double quotes.
>
> I tracked down the problem to org-babel-read (in ob-core.el). org-babel-C-execute (in ob-C.el) calls this function with the output of the C++ program. The problem is the following line:
>
> ((eq (string-to-char cell) ?\") (read cell))
>
> i.e. if the output of the program starts with a double quote, it is passed to read which reads only the first string and also removes the double quotes, resulting in the observed output.
>
> The original version of this piece of code was added with the following commit:
>
> commit 60a8ba556d682849eafb0f84e689967cd2965549
> Author: Eric Schulte <schulte.eric@gmail.com>
> Date: Wed Mar 2 07:55:39 2011 -0700
>
> ob: read string variable values wrapped in double quotes, removing the quotes
>
> * lisp/ob.el (org-babel-read): Read string variable values wrapped in
> double quotes, removing the quotes.
>
> AFAICT this modification was done in response to the email thread "[Orgmode] org-babel-read should have option NOT to interpret as elisp" started on 2011-02-27, more specifically the email on "Wed, 02 Mar 2011 07:56:45 -0700" from Eric Schulte. This was obviously done for parsing variables in the header line, not for the program output, but the Babel C mode uses org-babel-read also for the output.
>
> I assumed that ":results output verbatim raw" would prevent any postprocessing of the output but this is not the case for C mode.
>
> I am not sure how to fix this without breaking backward compatibility. I assume it should be fixed directly in org-babel-C-execute, not in a central function like org-babel-read to minimize the impact. Surprisingly (for me) the equivalent shell script works as expected:
>
> #+NAME: doublequotes
> #+begin_src shell :results output verbatim raw
> echo '"line 1"'
> echo '"line 2"'
> echo '"line 3"'
> #+end_src
>
> #+RESULTS: doublequotes
> "line 1"
> "line 2"
> "line 3"
>
> because org-babel-execute:shell does not process the output with org-babel-read. I do not know if languages other than the C family (C, C++, D) are affected.
>
> At the very least, the documentation of org-babel-read should be expanded to document the fact that if the CELL parameter starts with a double quote, it is processed by the read function.
>
> Best regards
> Martin Jerabek
>
--
-- A man must either resolve to point out nothing new or to become a
slave to defend it. -- Sir Isaac Newton
next prev parent reply other threads:[~2022-08-31 18:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 16:35 Babel C-mode corrupts double-quoted strings in output Martin Jerabek
2022-08-31 18:03 ` Immanuel Litzroth [this message]
2022-09-02 11:02 ` tbanelwebmin
2022-09-02 17:34 ` tbanelwebmin
2022-09-25 8:23 ` Ihor Radchenko
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=CAM1nAcwS35TXGRc+FnFdBUgmqkucfdeissRs3Rzq1Uf5U1Egog@mail.gmail.com \
--to=immanuel.litzroth@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=om@mailservice.ms \
/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).