* Org functions in source blocks
@ 2022-12-09 20:41 William Denton
2022-12-10 2:28 ` Max Nikulin
0 siblings, 1 reply; 4+ messages in thread
From: William Denton @ 2022-12-09 20:41 UTC (permalink / raw)
To: emacs-orgmode
I ran org-lookup-all in a source block, but it didn't give any output. I think
I don't know something basic about Org or Lisp (likely both) and I hope someone
can point out what's going on.
For example, I have this table, and I can count how many times x appears:
#+name: test_table
| | A |
|---+---|
| ! | A |
| | x |
| | |
| | x |
| | x |
|---+---|
| # | 3 |
#+TBLFM: $2='(length(org-lookup-all "x" '(@I..@II) nil))
I can do the count from another table, referring to a remote table:
#+name: summary
| A |
|---|
| 3 |
#+TBLFM: @2$1='(length(org-lookup-all "x" '(remote(test_table, @I$A..@II$A)) nil))
But running org-lookup-all on its own like this gives result nil, not something
with some xs in it. Why not?
#+begin_src emacs-lisp :results raw
(org-lookup-all "x" '(remote(test_table, @I$A..@II$A)) nil)
#+end_src
Thanks,
Bill
--
William Denton
https://www.miskatonic.org/
Librarian, artist and licensed private investigator.
Toronto, Canada
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Org functions in source blocks
2022-12-09 20:41 Org functions in source blocks William Denton
@ 2022-12-10 2:28 ` Max Nikulin
2022-12-12 3:23 ` William Denton
0 siblings, 1 reply; 4+ messages in thread
From: Max Nikulin @ 2022-12-10 2:28 UTC (permalink / raw)
To: William Denton, emacs-orgmode
On 10/12/2022 03:41, William Denton wrote:
>
> #+begin_src emacs-lisp :results raw
> (org-lookup-all "x" '(remote(test_table, @I$A..@II$A)) nil)
> #+end_src
There is nothing wrong with `org-lookup-all'. It just does not receive
arguments you expect. Try
#+begin_src emacs-lisp :results raw
(list "x" '(remote(test_table, @I$A..@II$A)) nil)
#+end_src
#+RESULTS:
(x (remote (test_table (, @I$A..@II$A))) nil)
@I$A and the "remote" function are available in table formulas only.
Moreover you quoted remote, so this s-expression is not evaluated. In
addition, unlike in table formulas, in elisp function arguments are
separated by space, not by comma.
Use :var to pass test_table to a source block
#+begin_src emacs-lisp :results raw :var data=test_table
data
#+end_src
#+RESULTS:
(( A) (! A) ( x) ( ) ( x) ( x) (# 3))
Unfortunately there are no convenient shortcuts for range selectors like
"@I$A..@II$A" (at least ready to use). You should use some functions
instead.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Org functions in source blocks
2022-12-10 2:28 ` Max Nikulin
@ 2022-12-12 3:23 ` William Denton
2022-12-13 15:05 ` Max Nikulin
0 siblings, 1 reply; 4+ messages in thread
From: William Denton @ 2022-12-12 3:23 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode
On 10 December 2022, Max Nikulin wrote:
> @I$A and the "remote" function are available in table formulas only. Moreover
> you quoted remote, so this s-expression is not evaluated. In addition, unlike
> in table formulas, in elisp function arguments are separated by space, not by
> comma.
Thanks for your explanation about this and the rest. I have a better sense now
of what works where and how Elisp code blocks can interact with the Org document
they're in. I'll be back with more questions eventually, I'm sure, but for now
just learning about all the table features I've overlooked so far will keep me
busy.
Bill
--
William Denton
https://www.miskatonic.org/
Librarian, artist and licensed private investigator.
Toronto, Canada
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Org functions in source blocks
2022-12-12 3:23 ` William Denton
@ 2022-12-13 15:05 ` Max Nikulin
0 siblings, 0 replies; 4+ messages in thread
From: Max Nikulin @ 2022-12-13 15:05 UTC (permalink / raw)
To: William Denton; +Cc: emacs-orgmode
On 12/12/2022 10:23, William Denton wrote:
> On 10 December 2022, Max Nikulin wrote:
>
>> @I$A and the "remote" function are available in table formulas only.
...
> I'll be back with more questions eventually,
Using source blocks you may define new functions that you may call from
table formulas.
You may create an intermediate table to evaluate expressions heavily
relied on cell ranges and feed this table to another source block as a
variable.
By the way, a range may be specified when passing a table as a source
block variable, but it uses another syntax, see
(info "(org)Environment of a Code Block")
https://orgmode.org/manual/Environment-of-a-Code-Block.html
So it is possible to mix table formulas and source code blocks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-12-13 15:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-09 20:41 Org functions in source blocks William Denton
2022-12-10 2:28 ` Max Nikulin
2022-12-12 3:23 ` William Denton
2022-12-13 15:05 ` Max Nikulin
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).