From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: table as argument to code block : type of the elements Date: Fri, 13 Sep 2013 11:02:20 -0600 Message-ID: <87hadou02r.fsf@gmail.com> References: <874n9pjpu6.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKWkz-0003yN-Lc for emacs-orgmode@gnu.org; Fri, 13 Sep 2013 13:02:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VKWks-0008GV-BM for emacs-orgmode@gnu.org; Fri, 13 Sep 2013 13:02:09 -0400 Received: from mail-pb0-x230.google.com ([2607:f8b0:400e:c01::230]:34467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKWks-0008GB-3E for emacs-orgmode@gnu.org; Fri, 13 Sep 2013 13:02:02 -0400 Received: by mail-pb0-f48.google.com with SMTP id ma3so1474248pbc.21 for ; Fri, 13 Sep 2013 10:02:01 -0700 (PDT) In-Reply-To: <874n9pjpu6.fsf@gmail.com> (Nick Dokos's message of "Fri, 13 Sep 2013 00:41:21 -0400") 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: Nick Dokos Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Nick Dokos writes: > francois@avalenn.eu writes: > >> This code does not work because of automatic conversion from string to >> number in org-babel-read-table. >> >> #+TBLNAME: table_test >> | name | id | >> |-------+-----| >> | name1 | 034 | >> | name2 | 135 | >> | name3 | 1B5 | >> >> #+NAME: code_test >> #+BEGIN_SRC emacs-lisp :var table=table_test >> (setq myv "") >> (dolist (line table myv) >> (unless (eq line 'hline) >> (setq myv (concat myv ";" (mapconcat 'identity line ","))))) >> myv >> >> #+END_SRC >> >> I would like to have this result : >> >> #+RESULTS: code_test >> : ;name,id;name1,034;name2,135;name3,1B5 >> >> Is there any possibility to deactivate this conversion as with >> inhibit-lisp-eval for lisp forms ? Or better is there any way to chose >> conversion parameters on a column to column basis ? >> > > Not that I know of. But you can redefine org-babel-read-table to omit > the conversion: > > --8<---------------cut here---------------start------------->8--- > (defun org-babel-read-table () > (org-table-to-lisp)) > --8<---------------cut here---------------end--------------->8--- > > and redefine it back afterwards: > > --8<---------------cut here---------------start------------->8--- > (defun org-babel-read-table () > "Read the table at `point' into emacs-lisp." > (mapcar (lambda (row) > (if (and (symbolp row) (equal row 'hline)) row > (mapcar (lambda (el) (org-babel-read el 'inhibit-lisp-eval)) row))) > (org-table-to-lisp))) > --8<---------------cut here---------------end--------------->8--- > > Disgusting, no? Disgusting and fantastic. How about taking it one step further... --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=it.org This code block defines the == form used to read table references without conversion. Eval this first. #+begin_src emacs-lisp :results silent (defmacro with-simple-tables (ref) `(flet ((org-babel-read-table () (org-table-to-lisp))) (org-babel-ref-resolve ,(symbol-name ref)))) #+end_src * Original Example #+TBLNAME: table_test | name | id | |-------+-----| | name1 | 034 | | name2 | 135 | | name3 | 1B5 | #+NAME: code_test_orig #+BEGIN_SRC emacs-lisp :var table=table_test (format "%S" table) #+END_SRC #+RESULTS: code_test_orig : (("name" "id") hline ("name1" 34) ("name2" 135) ("name3" "1B5")) and now without conversion #+NAME: code_test_simplified #+BEGIN_SRC emacs-lisp :var table=(with-simple-tables table_test) (format "%S" table) #+END_SRC #+RESULTS: code_test_simplified : (("name" "id") hline ("name1" "034") ("name2" "135") ("name3" "1B5")) --=-=-= Content-Type: text/plain -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D --=-=-=--