* table as argument to code block : type of the elements
@ 2013-09-12 7:43 francois
2013-09-12 8:42 ` francois
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: francois @ 2013-09-12 7:43 UTC (permalink / raw)
To: emacs-orgmode
Hello list,
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 ?
François.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: table as argument to code block : type of the elements
2013-09-12 7:43 table as argument to code block : type of the elements francois
@ 2013-09-12 8:42 ` francois
2013-09-13 4:05 ` Nick Dokos
2013-09-13 4:41 ` Nick Dokos
2 siblings, 0 replies; 6+ messages in thread
From: francois @ 2013-09-12 8:42 UTC (permalink / raw)
To: emacs-orgmode
> This code does not work because of automatic conversion from string
> to
> number in org-babel-read-table.
I found a workaround changing the table to :
#+TBLNAME: table_test
| name | id |
|-------+-------|
| name1 | "034" |
| name2 | "135" |
| name3 | 1B5 |
but I think inhibiting number conversion could nevertheless be useful
in a number of situations.
François.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: table as argument to code block : type of the elements
2013-09-12 7:43 table as argument to code block : type of the elements francois
2013-09-12 8:42 ` francois
@ 2013-09-13 4:05 ` Nick Dokos
2013-09-13 4:24 ` Nick Dokos
2013-09-13 4:41 ` Nick Dokos
2 siblings, 1 reply; 6+ messages in thread
From: Nick Dokos @ 2013-09-13 4:05 UTC (permalink / raw)
To: emacs-orgmode
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 ?
>
--
Nick
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: table as argument to code block : type of the elements
2013-09-13 4:05 ` Nick Dokos
@ 2013-09-13 4:24 ` Nick Dokos
0 siblings, 0 replies; 6+ messages in thread
From: Nick Dokos @ 2013-09-13 4:24 UTC (permalink / raw)
To: emacs-orgmode
Bah, humbug: C-c C-c in the wrong buffer.
Apologies for the contentless "reply"...
--
Nick
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: table as argument to code block : type of the elements
2013-09-12 7:43 table as argument to code block : type of the elements francois
2013-09-12 8:42 ` francois
2013-09-13 4:05 ` Nick Dokos
@ 2013-09-13 4:41 ` Nick Dokos
2013-09-13 17:02 ` Eric Schulte
2 siblings, 1 reply; 6+ messages in thread
From: Nick Dokos @ 2013-09-13 4:41 UTC (permalink / raw)
To: emacs-orgmode
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?
--
Nick
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: table as argument to code block : type of the elements
2013-09-13 4:41 ` Nick Dokos
@ 2013-09-13 17:02 ` Eric Schulte
0 siblings, 0 replies; 6+ messages in thread
From: Eric Schulte @ 2013-09-13 17:02 UTC (permalink / raw)
To: Nick Dokos; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1709 bytes --]
Nick Dokos <ndokos@gmail.com> 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...
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: it.org --]
[-- Type: text/x-org, Size: 879 bytes --]
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"))
[-- Attachment #3: Type: text/plain, Size: 63 bytes --]
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-09-13 17:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-12 7:43 table as argument to code block : type of the elements francois
2013-09-12 8:42 ` francois
2013-09-13 4:05 ` Nick Dokos
2013-09-13 4:24 ` Nick Dokos
2013-09-13 4:41 ` Nick Dokos
2013-09-13 17:02 ` Eric Schulte
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.