* Possible to robustly embed elisp links in source block table results?
@ 2022-02-12 10:52 Tim Landscheidt
2022-02-13 15:17 ` John Kitchin
0 siblings, 1 reply; 2+ messages in thread
From: Tim Landscheidt @ 2022-02-12 10:52 UTC (permalink / raw)
To: emacs-orgmode
Hi,
I want org-mode to display a tab-separated values table ge-
nerated by jq that includes elisp links that do something
(differently) for each row, especially containing data that
is not displayed in other columns.
The source block:
| #+BEGIN_SRC sh :colnames '(Column\ A Column\ B Column\ C)
| jq --null-input -r 'range(1; 4) | tostring | [ "A" + ., "B" + ., "[[elisp:(ignore)][Do it]]"] | @tsv'
| #+END_SRC
evaluates to:
| #+RESULTS:
| | Column A | Column B | Column C |
| |----------+----------+----------|
| | A1 | B1 | [[elisp:(ignore)][Do it]] |
| | A2 | B2 | [[elisp:(ignore)][Do it]] |
| | A3 | B3 | [[elisp:(ignore)][Do it]] |
which org-mode displays as:
| #+RESULTS:
| | Column A | Column B | Column C |
| |----------+----------+----------|
| | A1 | B1 | Do it |
| | A2 | B2 | Do it |
| | A3 | B3 | Do it |
with each "Do it" being a button that, when pressed and con-
firmed, executes ignore. Great!
Executing Emacs Lisp:
| (org-insert-link nil "elisp:(ignore \"1\")" "Do it")
results in the org-mode source code:
| [[elisp:(ignore "1")][Do it]]
so let's try jq generating that with:
| #+BEGIN_SRC sh :colnames '(Column\ A Column\ B Column\ C)
| jq --null-input -r 'range(1; 4) | tostring | [ "A" + ., "B" + ., "[[elisp:(ignore \"" + . + "\")][Do it]]"] | @tsv'
| #+END_SRC
This jq call, executed in a shell, evaluates to the output
(tab-separated):
| A1 B1 [[elisp:(ignore "1")][Do it]]
| A2 B2 [[elisp:(ignore "2")][Do it]]
| A3 B3 [[elisp:(ignore "3")][Do it]]
When org-mode evaluates the source block, it strips it down
to:
| #+RESULTS:
| | Column A | Column B | Column C |
| |----------+----------+----------|
| | A1 | B1 | 1 |
| | A2 | B2 | 2 |
| | A3 | B3 | 3 |
where "1", "2" and "3" are not buttons or anything else but
plain text, and any other input has been permanently dis-
carded (i. e., is not just not displayed).
If however I set ":results raw" in the source block:
| #+BEGIN_SRC sh :colnames '(Column\ A Column\ B Column\ C) :results raw
| jq --null-input -r 'range(1; 4) | tostring | [ "A" + ., "B" + ., "[[elisp:(ignore \"" + . + "\")][Do it]]"] | @tsv'
| #+END_SRC
org-mode evaluates that to:
| #+RESULTS:
| A1 B1 Do it
| A2 B2 Do it
| A3 B3 Do it
with each "Do it" being a button that, when pressed and con-
firmed, will execute (ignore "1"), (ignore "2") and (ignore
"3"), respectively.
So in the first and third source block, org-mode teases me
that I can embed elisp links in that very nice table format
(first source block) with "complex" Lisp code (third source
block), but when I try to combine the two (second source
block), it slaps me in the face.
Surely I must be missing some obvious solution? Is there
another syntax I need to use? Do I need to have jq output
the raw columns A, B, D and E and then define a :post source
block that converts that to A, B and C = f(D, E)?
My alternative and thus benchmark for such "dashboards" that
show "stuff" and offer things to do with it are derivatives
of tabulated-list-mode, but their programming requires de-
finitions of functions & Co. that need to be updated syn-
chronously; an org-mode source block on the other hand just
does what it says on the tin.
TIA,
Tim
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Possible to robustly embed elisp links in source block table results?
2022-02-12 10:52 Possible to robustly embed elisp links in source block table results? Tim Landscheidt
@ 2022-02-13 15:17 ` John Kitchin
0 siblings, 0 replies; 2+ messages in thread
From: John Kitchin @ 2022-02-13 15:17 UTC (permalink / raw)
To: Tim Landscheidt; +Cc: emacs-orgmode
This is not a complete answer to why this happens, but a practical one
that I think is what you want. In the code below I just added | in your
jq call to construct the table. I also have to use :results raw to get
it to work. The :colnames did not work for me here, so I added the echo
line to get column names. It is not beautiful, but it works.
#+BEGIN_SRC sh :results raw
echo "| column a | column b | column c|\n|-"
jq --null-input -r 'range(1; 4) | tostring | [ "| A" + ., "| B" + ., " | [[elisp:(ignore \"" + . + "\")][Do it]] |"] | @tsv'
#+END_SRC
#+RESULTS:
| column a | column b | column c |
|----------+----------+----------|
| A1 | B1 | [[elisp:(ignore "1")][Do it]] |
| A2 | B2 | [[elisp:(ignore "2")][Do it]] |
| A3 | B3 | [[elisp:(ignore "3")][Do it]] |
Tim Landscheidt <tim@tim-landscheidt.de> writes:
> Hi,
>
> I want org-mode to display a tab-separated values table ge-
> nerated by jq that includes elisp links that do something
> (differently) for each row, especially containing data that
> is not displayed in other columns.
>
> The source block:
>
> | #+BEGIN_SRC sh :colnames '(Column\ A Column\ B Column\ C)
> | jq --null-input -r 'range(1; 4) | tostring | [ "A" + ., "B" + ., "[[elisp:(ignore)][Do it]]"] | @tsv'
> | #+END_SRC
>
> evaluates to:
>
> | #+RESULTS:
> | | Column A | Column B | Column C |
> | |----------+----------+----------|
> | | A1 | B1 | [[elisp:(ignore)][Do it]] |
> | | A2 | B2 | [[elisp:(ignore)][Do it]] |
> | | A3 | B3 | [[elisp:(ignore)][Do it]] |
>
> which org-mode displays as:
>
> | #+RESULTS:
> | | Column A | Column B | Column C |
> | |----------+----------+----------|
> | | A1 | B1 | Do it |
> | | A2 | B2 | Do it |
> | | A3 | B3 | Do it |
>
> with each "Do it" being a button that, when pressed and con-
> firmed, executes ignore. Great!
>
> Executing Emacs Lisp:
>
> | (org-insert-link nil "elisp:(ignore \"1\")" "Do it")
>
> results in the org-mode source code:
>
> | [[elisp:(ignore "1")][Do it]]
>
> so let's try jq generating that with:
>
> | #+BEGIN_SRC sh :colnames '(Column\ A Column\ B Column\ C)
> | jq --null-input -r 'range(1; 4) | tostring | [ "A" + ., "B" + ., "[[elisp:(ignore \"" + . + "\")][Do it]]"] | @tsv'
> | #+END_SRC
>
> This jq call, executed in a shell, evaluates to the output
> (tab-separated):
>
> | A1 B1 [[elisp:(ignore "1")][Do it]]
> | A2 B2 [[elisp:(ignore "2")][Do it]]
> | A3 B3 [[elisp:(ignore "3")][Do it]]
>
> When org-mode evaluates the source block, it strips it down
> to:
>
> | #+RESULTS:
> | | Column A | Column B | Column C |
> | |----------+----------+----------|
> | | A1 | B1 | 1 |
> | | A2 | B2 | 2 |
> | | A3 | B3 | 3 |
>
> where "1", "2" and "3" are not buttons or anything else but
> plain text, and any other input has been permanently dis-
> carded (i. e., is not just not displayed).
>
> If however I set ":results raw" in the source block:
>
> | #+BEGIN_SRC sh :colnames '(Column\ A Column\ B Column\ C) :results raw
> | jq --null-input -r 'range(1; 4) | tostring | [ "A" + ., "B" + ., "[[elisp:(ignore \"" + . + "\")][Do it]]"] | @tsv'
> | #+END_SRC
>
> org-mode evaluates that to:
>
> | #+RESULTS:
> | A1 B1 Do it
> | A2 B2 Do it
> | A3 B3 Do it
>
> with each "Do it" being a button that, when pressed and con-
> firmed, will execute (ignore "1"), (ignore "2") and (ignore
> "3"), respectively.
>
> So in the first and third source block, org-mode teases me
> that I can embed elisp links in that very nice table format
> (first source block) with "complex" Lisp code (third source
> block), but when I try to combine the two (second source
> block), it slaps me in the face.
>
> Surely I must be missing some obvious solution? Is there
> another syntax I need to use? Do I need to have jq output
> the raw columns A, B, D and E and then define a :post source
> block that converts that to A, B and C = f(D, E)?
>
> My alternative and thus benchmark for such "dashboards" that
> show "stuff" and offer things to do with it are derivatives
> of tabulated-list-mode, but their programming requires de-
> finitions of functions & Co. that need to be updated syn-
> chronously; an org-mode source block on the other hand just
> does what it says on the tin.
>
> TIA,
> Tim
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
Pronouns: he/him/his
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-13 15:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-12 10:52 Possible to robustly embed elisp links in source block table results? Tim Landscheidt
2022-02-13 15:17 ` John Kitchin
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).