[-- Attachment #1: Type: text/plain, Size: 1196 bytes --] Dear Orgers, I would have a question for you. I'm writing more and more documentation in OrgMode (with HTML and DocBook exports) and I'm very happy with it. There's a little hitch though on tables. Org tables are great with one known and documented constraints: it does not accept multi lines [1]. In some types of documents it can be a challenge, however, editing large columns could be a mess too. I'm thinking about a potential alternative and I would like to know if anyone here would know if this can be done with org. ReStructured Text [2] has a nice feature called list-tables. As you can guess from the name, you write a list and an instruction to process it and it creates a table out of the list in the export target. See the ReST documentation for a quick explanation [3]. What is does it to transform a nested list in a simple table. And potentially it would make long list items / table content easy to edit. Does anyone has heard of such a possibility in Org? Many thanks to all! -- Ben [1] http://orgmode.org/worg/org-faq.html#table-multiline-fields [2] http://docutils.sourceforge.net/rst.html [3] http://docutils.sourceforge.net/docs/ref/rst/directives.html#list-table [-- Attachment #2: Type: text/html, Size: 1719 bytes --]
> What is does it to transform a nested list in a simple table. Just a thought. If someone takes a stab at it, I suggest that they use my experimental staging branch (org-html/org-odt) that implements callbacks for various org entities like paragraphs, outline, lists and tables. Without looking in to the specifics of the proposal and the links provided, my initial reaction is that a quick prototype could be developed with my generic backend. Let me add that my experimental has gone through 3 cycles of re-implementation and is very usable. http://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg00839.html http://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg00840.html Jambunathan K.
Hello,
Ben <bip@maleloria.org> writes:
> I'm thinking about a potential alternative and I would like to know if
> anyone here would know if this can be done with org.
> ReStructured Text [2] has a nice feature called list-tables. As you can
> guess from the name, you write a list and an instruction to process it and
> it creates a table out of the list in the export target. See the ReST
> documentation for a quick explanation [3]. What is does it to transform a
> nested list in a simple table. And potentially it would make long list items
> / table content easy to edit.
>
> Does anyone has heard of such a possibility in Org?
Out of boredom, I've written a draft for it.
First we need the following function that might be of some use (i.e. to
Babel, as you can write an Org list as a lisp list and write it to the
buffer). Well anyway, here it is:
#+begin_src emacs-lisp
(defun org-list-to-org (list)
"Convert LIST into an Org list.
LIST is as returned by `org-list-parse-list'."
(let ((sep (if (eq org-plain-list-ordered-item-terminator ?\)) ")" "."))
(ltype (make-vector 20 "-")))
(org-list-to-generic
list
'(:isep "\n"
:ostart (and (aset ltype depth (concat "1" sep)) "")
:dstart (and (aset ltype depth "-") "")
:ustart (and (aset ltype depth "-") "")
:icount (concat (make-string depth ?\ )
(org-list-bullet-string (aref ltype depth))
(format "[@%d] " counter))
:istart (concat (make-string depth ?\ )
(org-list-bullet-string (aref ltype depth)))
:cbon "[X]" :cboff "[ ]"
:dtstart (if (and org-list-two-spaces-after-bullet-regexp
(string-match org-list-two-spaces-after-bullet-regexp
"-")) " " " ")
:csep "\n"
:ddstart " :: "))))
#+end_src
Next, we need bi-directional internal representation converters from
a table to a list:
#+begin_src emacs-lisp
(defun org-lisp-list-to-table (list)
"Change LIST lisp representation into a table lisp representation."
(mapcar (lambda (sub)
(cons (nth 1 sub)
(mapcar (lambda (item) (nth 1 item)) (cdr (nth 2 sub)))))
(cdr list)))
(defun org-lisp-table-to-list (table)
"Change TABLE lisp representation into a list lisp representation."
(cons 'unordered
(mapcar (lambda (row)
(list nil (car row)
(cons 'unordered
(mapcar (lambda (cell)
(list nil cell))
(cdr row)))))
table)))
#+end_src
Finally, we need the interactive functions for the user. Those will
also clean up output.
#+begin_src emacs-lisp
(defun org-convert-list-to-table ()
"Transform list at point into a table."
(interactive)
(if (org-at-item-p)
(let ((parsed (org-list-parse-list t)))
(insert (orgtbl-to-orgtbl (org-lisp-list-to-table parsed) nil) "\n")
(goto-char (org-table-begin))
(org-table-align))
(error "Not at a list")))
(defun org-convert-table-to-list ()
"Transform table at point into a list."
(interactive)
(if (org-at-table-p)
(let ((pos (point))
(table (org-table-to-lisp)))
(delete-region (org-table-begin) (org-table-end))
(insert (org-list-to-org (org-lisp-table-to-list table)))
(goto-char pos)
(org-list-repair))
(error "Not at a table")))
#+end_src
That's it.
All of this will convert
- Row 1
- 1.1
- 1.2
- 1.3
- Row 2
- 2.1
- 2.2
- 2.3
to
| Row 1 | 1.1 | 1.2 | 1.3 |
| Row 2 | 2.1 | 2.2 | 2.3 |
and the other way.
Notes :
- I'm far from being an Org table expert. There probably are corner
cases. This also doesn't support hlines.
- This requires latest git head (b6fc03b)
Regards,
--
Nicolas
[-- Attachment #1: Type: text/plain, Size: 720 bytes --] > > > Out of boredom, I've written a draft for it. > > Woohoo! congrats for the way you're getting bored! Hey thank you Nicolas! > #+begin_src emacs-lisp > So here I'm guessing the whole code fits into Babel, right? All of this will convert > (...) > | Row 1 | 1.1 | 1.2 | 1.3 | > | Row 2 | 2.1 | 2.2 | 2.3 | > > Oh actually you went the 'line' way -- and not the column. Considering, I actually think you're right. I got used to the ReST way (1 item + sub-items = 1 column) but I think your way seems more natural. Cool, thank you again! > and the other way. > > I'm afraid I don't get the 'and the other way', does it means your code can go the column way as well?! Splendid thanks again Nicolas! -- Ben [-- Attachment #2: Type: text/html, Size: 1720 bytes --]
Ben <bip@maleloria.org> wrote: > > #+begin_src emacs-lisp > > > > So here I'm guessing the whole code fits into Babel, right? > It depends on what you mean: you *can* use babel to evaluate the code (C-c C-c on every code block, or similar), thereby loading it into your current emacs, but if you want to use this code regularly, you probably want to save it in a file (or tangle it if you prefer - although there is no advantage to tangling in this case), and load it up from your .emacs. > > > and the other way. > > > > > I'm afraid I don't get the 'and the other way', does it means your code can > go the column way as well?! > No, he means you can go back from the table to the list, by calling org-convert-table-to-list. > Splendid thanks again Nicolas! > > -- Ben > Nick
I wish org-mode can do like this...
- Row 1 :exports tabel
- 1.1
- 1.2
- 1.3
- Row 2
- 2.1
- 2.2
- 2.3
On Fri, Mar 18, 2011 at 6:18 AM, Ben <bip@maleloria.org> wrote:
>>
>> Out of boredom, I've written a draft for it.
>>
>
>
> Woohoo! congrats for the way you're getting bored!
> Hey thank you Nicolas!
>
>>
>> #+begin_src emacs-lisp
>
> So here I'm guessing the whole code fits into Babel, right?
>>
>> All of this will convert
>
> (...)
>>
>> | Row 1 | 1.1 | 1.2 | 1.3 |
>> | Row 2 | 2.1 | 2.2 | 2.3 |
>>
>
> Oh actually you went the 'line' way -- and not the column.
> Considering, I actually think you're right.
> I got used to the ReST way (1 item + sub-items = 1 column) but I think your
> way seems more natural.
> Cool, thank you again!
>
>>
>> and the other way.
>>
>
> I'm afraid I don't get the 'and the other way', does it means your code can
> go the column way as well?!
> Splendid thanks again Nicolas!
> -- Ben
>
Hello,
Ben <bip@maleloria.org> writes:
> Oh actually you went the 'line' way -- and not the column.
> Considering, I actually think you're right.
> I got used to the ReST way (1 item + sub-items = 1 column) but I think your
> way seems more natural.
I went that way because it was easier to implement. Though, there is
code somewhere to transpose tables (in Library of Babel, I think). So
you can type list items as columns instead, change the list into
a table, and transpose it. Voilà.
Regards,
--
Nicolas
[-- Attachment #1: Type: text/plain, Size: 310 bytes --] > > > I went that way because it was easier to implement. Though, there is > code somewhere to transpose tables (in Library of Babel, I think). So > you can type list items as columns instead, change the list into > a table, and transpose it. Voilà. > > Brilliant! Thank you again Nicolas! -- Ben [-- Attachment #2: Type: text/html, Size: 545 bytes --]