From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: Wishlist: allow range of table elements to be filled by sbe Date: Fri, 19 Aug 2011 07:17:47 -0600 Message-ID: <878vqpo39j.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:60925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QuQYQ-0000Hj-Q2 for emacs-orgmode@gnu.org; Fri, 19 Aug 2011 11:00:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QuQYP-0006Ks-CG for emacs-orgmode@gnu.org; Fri, 19 Aug 2011 11:00:14 -0400 Received: from mail-gx0-f169.google.com ([209.85.161.169]:58333) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QuQYP-0005wa-65 for emacs-orgmode@gnu.org; Fri, 19 Aug 2011 11:00:13 -0400 Received: by mail-gx0-f169.google.com with SMTP id 23so2457264gxk.0 for ; Fri, 19 Aug 2011 08:00:12 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: =?utf-8?Q?Andr=C3=A1s?= Major Cc: emacs-orgmode Andr=C3=A1s Major 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=3D'(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=3Dthis-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 --=20 Eric Schulte http://cs.unm.edu/~eschulte/