From: "James Boyle" <jboyle@fastmail.com>
To: emacs-orgmode@gnu.org
Subject: Is reading nested simple lists into org-babel code blocks currently supported?
Date: Wed, 28 Oct 2020 19:43:13 -0400 [thread overview]
Message-ID: <50a71862-dbde-41c1-aab8-b7570d9c5d3c@www.fastmail.com> (raw)
Hi all,
Since this is a bit of a long post, I've put my questions and summary
comment at the top, with the detailed context below.
1. What is the level of support for reading nested simple lists into
org-babel code blocks?
2. When the manual (see link below) says that they are not supported,
is it known if it meant "not at all supported," or, that support is
currently language-dependent?
3. Directionally, does the org-mode project care to support nested
simple lists?
I'm happy to submit patches for both code and manual in any event, but
wanted to align on if there are goals for supporting reading nested
lists, and if so, at what level.
At a minimum, I think updating the manual to be more precise would be
great.
Thanks for your any assistance you can provide.
Details:
I was going through the manual on this page:
https://orgmode.org/manual/Environment-of-a-Code-Block.html#Environment-of-a-Code-Block
and testing out the example, "A simple named list."
Contrary to this line in the manual:
> Note that only the top level list items are passed along. Nested list items are ignored.
It looks like the example org-babel block *does* work for nested
lists, depending upon the language. I am using org-mode 9.4.
Here is the org block verbatim from the manual, with the
results that are supposed to occur:
#+NAME: example-list
- simple
- not
- nested
- list
#+BEGIN_SRC emacs-lisp :var x=example-list
(print x)
#+END_SRC
#+RESULTS:
| simple | list |
And here is the same block, when I evaluate it locally, with the
actual results, showing that unordered, nested lists are not ignored.
#+NAME: example-list
- simple
- not
- nested
- list
#+BEGIN_SRC emacs-lisp :var x=example-list
(print x)
#+END_SRC
#+RESULTS:
| simple | (unordered (not) (nested)) |
| list | |
I thought this was a nice surprise, until I noticed that whether or
not it works is language-dependent.
In ruby, I get an error:
#+begin_src ruby :var x=example-list
# This is the error I get:
# `main': undefined local variable or method `unordered' for
# main:Object (NameError)
puts x
#+end_src
#+RESULTS:
And here is the equivalent error in js. Presumably other languages
have variable support for this feature.
#+begin_src js :var x=example-list
// Below is a partial error trace:
// /private/var/folders/mc/jylgk04j5r1f96hcsd3ywm8h0000gn/T/babel-shSmEq/js-script-xzngmd:2
// var x=[["simple", [unordered, ["not"], ["nested"]]], ["list"]]; ^
// ReferenceError: unordered is not defined
return x
#+end_src
#+RESULTS:
The error can be trivially "fixed" by some code like this, or making
the equivalent change in the actual source line to output a string
rather than a symbol. Changing L#2365 linked below to use "unordered"
(string) rather than 'unordered (symbol) seemed to fix it, and
produced no new test failures for me.
#+begin_src emacs-lisp
; See this line for where 'unordered is being spat out:
; https://code.orgmode.org/bzg/org-mode/src/master/lisp/ob-core.el#L2365
(defun patch-get-vars-output (vars)
"Substitute special Lisp symbols with a Lisp keyword.
This allows Ruby to not barf on an undefined variable error
for certain input structures like nested lists.
Argument VARS is a tree structure. See above example format."
(subst "unordered" 'unordered vars))
(advice-add 'org-babel--get-vars :filter-return #'patch-get-vars-output)
#+end_src
Thanks again for any help or direction you can provide.
James Boyle
next reply other threads:[~2020-10-29 11:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-28 23:43 James Boyle [this message]
2020-10-29 16:52 ` Is reading nested simple lists into org-babel code blocks currently supported? Tom Gillespie
2020-10-31 14:56 ` Is reading nested simple lists into org-babel code blocks currently supported? [PATCH] - manual.org James Boyle
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=50a71862-dbde-41c1-aab8-b7570d9c5d3c@www.fastmail.com \
--to=jboyle@fastmail.com \
--cc=emacs-orgmode@gnu.org \
/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).