* Wishlist: allow range of table elements to be filled by sbe
@ 2011-08-19 7:22 András Major
2011-08-19 13:17 ` Eric Schulte
2011-08-19 20:46 ` Michael Brand
0 siblings, 2 replies; 5+ messages in thread
From: András Major @ 2011-08-19 7:22 UTC (permalink / raw)
To: emacs-orgmode
Hi,
I'd like to use a babel code block to fill a table with values. The
sbe elisp function looks like the right thing for this task, but it
appears that the result of the code block always goes into a single
cell of a table. I can specify ranges of values, but then the entire
output is placed into each of the specified cells.
Here is how I imagine things should work:
#+srcname: shcode
#+begin_src sh :exports output table silent
echo "1 2 3"
#+end_src
| 1 | 2 | 3 |
#+TBLFM: $1..$3='(sbe shcode)
Note that this is *NOT* real output from the code block in the current
version of org-mode, it's what I want it to be. There are two things
that cause this to break at the moment:
- The range $1..$3 doesn't work, I have to prepend a row specifier as
in @<$1..@>$3 or suchlike, which is rather counterintuitive but
seems to work.
- The output "1 2 3" are not separated into the various cells but all
placed into each cell.
Or am I doing something wrong here?
András
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Wishlist: allow range of table elements to be filled by sbe
2011-08-19 7:22 Wishlist: allow range of table elements to be filled by sbe András Major
@ 2011-08-19 13:17 ` Eric Schulte
2011-08-19 18:59 ` András Major
2011-08-19 20:46 ` Michael Brand
1 sibling, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2011-08-19 13:17 UTC (permalink / raw)
To: András Major; +Cc: emacs-orgmode
András Major <andras.g.major@gmail.com> writes:
> Hi,
>
> I'd like to use a babel code block to fill a table with values. The
> sbe elisp function looks like the right thing for this task, but it
> appears that the result of the code block always goes into a single
> cell of a table. I can specify ranges of values, but then the entire
> output is placed into each of the specified cells.
>
> Here is how I imagine things should work:
>
> #+srcname: shcode
> #+begin_src sh :exports output table silent
> echo "1 2 3"
> #+end_src
>
> | 1 | 2 | 3 |
> #+TBLFM: $1..$3='(sbe shcode)
>
> Note that this is *NOT* real output from the code block in the current
> version of org-mode, it's what I want it to be. There are two things
> that cause this to break at the moment:
>
> - The range $1..$3 doesn't work, I have to prepend a row specifier as
> in @<$1..@>$3 or suchlike, which is rather counterintuitive but
> seems to work.
>
> - The output "1 2 3" are not separated into the various cells but all
> placed into each cell.
>
> Or am I doing something wrong here?
>
sbe is just an elisp function which is called by the Org-mode
spreadsheet's function evaluation mechanisms. The spreadsheet does not
allow for insertion of results into multiple cells and thus neither does
the use of sbe. I would recommend a solution like the following, which
reads the /entire/ table into a code block, and writes the results out
in place.
#+results: this-is-the-table
| 1 | 4 | 7 |
| 2 | 5 | 8 |
| 3 | 6 | 9 |
#+source: this-is-the-table
#+begin_src emacs-lisp :var table=this-is-the-table
(mapcar (lambda (row) (mapcar (lambda (cell) (* cell 2)) row)) table)
#+end_src
Every time the code block is evaluated multiple cells in the table are
changed. To only set specific table values use of the `setf' macro
would probably be more appropriate.
Hope this helps -- Eric
--
Eric Schulte
http://cs.unm.edu/~eschulte/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Wishlist: allow range of table elements to be filled by sbe
2011-08-19 13:17 ` Eric Schulte
@ 2011-08-19 18:59 ` András Major
2011-08-19 22:22 ` Eric Schulte
0 siblings, 1 reply; 5+ messages in thread
From: András Major @ 2011-08-19 18:59 UTC (permalink / raw)
To: emacs-orgmode
Hi Eric,
> sbe is just an elisp function which is called by the Org-mode
> spreadsheet's function evaluation mechanisms. The spreadsheet does not
> allow for insertion of results into multiple cells and thus neither does
> the use of sbe.
Hmmm. It appears that one can make sbe set multiple cells in the
table -- simply make your code block output multiple results separated
by "|" and set ":results table". This, however, also shifts any
existing cells in the table, thus increasing the number of columns,
instead of just overwriting the given number of cells.
> I would recommend a solution like the following, which
> reads the /entire/ table into a code block, and writes the results out
> in place.
This isn't always practical. In the case of the Org document I'm
writing at the moment, the computation is rather expensive, and my
goal is that you can edit a row in the table and run the calculation
just for that row to see the result. Updating the entire table at
once would be much too slow.
> Every time the code block is evaluated multiple cells in the table are
> changed. To only set specific table values use of the `setf' macro
> would probably be more appropriate.
How is setf used? I haven't found it in the documentation.
András
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Wishlist: allow range of table elements to be filled by sbe
2011-08-19 7:22 Wishlist: allow range of table elements to be filled by sbe András Major
2011-08-19 13:17 ` Eric Schulte
@ 2011-08-19 20:46 ` Michael Brand
1 sibling, 0 replies; 5+ messages in thread
From: Michael Brand @ 2011-08-19 20:46 UTC (permalink / raw)
To: András Major; +Cc: emacs-orgmode
Hi András
I am not sure if you really need the data between the sh output and
the sbe input as a table. If not, this can be used:
#+source: shcode(x = 0)
#+begin_src sh
echo "$x"
#+end_src
| 1 | 2 | 3 |
#+TBLFM: @1$1..@1$3 = '(sbe "shcode" (x "$#"))
Michael
2011/8/19 András Major <andras.g.major@gmail.com>:
> Hi,
>
> I'd like to use a babel code block to fill a table with values. The
> sbe elisp function looks like the right thing for this task, but it
> appears that the result of the code block always goes into a single
> cell of a table. I can specify ranges of values, but then the entire
> output is placed into each of the specified cells.
>
> Here is how I imagine things should work:
>
> #+srcname: shcode
> #+begin_src sh :exports output table silent
> echo "1 2 3"
> #+end_src
>
> | 1 | 2 | 3 |
> #+TBLFM: $1..$3='(sbe shcode)
>
> Note that this is *NOT* real output from the code block in the current
> version of org-mode, it's what I want it to be. There are two things
> that cause this to break at the moment:
>
> - The range $1..$3 doesn't work, I have to prepend a row specifier as
> in @<$1..@>$3 or suchlike, which is rather counterintuitive but
> seems to work.
>
> - The output "1 2 3" are not separated into the various cells but all
> placed into each cell.
>
> Or am I doing something wrong here?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Wishlist: allow range of table elements to be filled by sbe
2011-08-19 18:59 ` András Major
@ 2011-08-19 22:22 ` Eric Schulte
0 siblings, 0 replies; 5+ messages in thread
From: Eric Schulte @ 2011-08-19 22:22 UTC (permalink / raw)
To: András Major; +Cc: emacs-orgmode
Hi András,
András Major <andras.g.major@gmail.com> writes:
> Hi Eric,
>
>> sbe is just an elisp function which is called by the Org-mode
>> spreadsheet's function evaluation mechanisms. The spreadsheet does not
>> allow for insertion of results into multiple cells and thus neither does
>> the use of sbe.
>
> Hmmm. It appears that one can make sbe set multiple cells in the
> table -- simply make your code block output multiple results separated
> by "|" and set ":results table". This, however, also shifts any
> existing cells in the table, thus increasing the number of columns,
> instead of just overwriting the given number of cells.
>
>> I would recommend a solution like the following, which
>> reads the /entire/ table into a code block, and writes the results out
>> in place.
>
> This isn't always practical. In the case of the Org document I'm
> writing at the moment, the computation is rather expensive, and my
> goal is that you can edit a row in the table and run the calculation
> just for that row to see the result. Updating the entire table at
> once would be much too slow.
>
Unfortunately I don't believe there is a good solution to this problem.
>
>> Every time the code block is evaluated multiple cells in the table are
>> changed. To only set specific table values use of the `setf' macro
>> would probably be more appropriate.
>
> How is setf used? I haven't found it in the documentation.
>
Setf can be used to update internal parts of a data structure, for
example.
#+results: this-is-another-table
| 0 | 0 | 0 |
| 0 | 0 | 0 |
| 0 | 0 | 0 |
#+source: this-is-another-table
#+begin_src emacs-lisp :var table=this-is-another-table
(setf (nth 1 table) '(2 2 2))
table
#+end_src
executing the code block will set the second row of the table to all
twos.
Hope this helps -- Eric
>
> András
>
>
>
--
Eric Schulte
http://cs.unm.edu/~eschulte/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-08-21 18:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-19 7:22 Wishlist: allow range of table elements to be filled by sbe András Major
2011-08-19 13:17 ` Eric Schulte
2011-08-19 18:59 ` András Major
2011-08-19 22:22 ` Eric Schulte
2011-08-19 20:46 ` Michael Brand
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).