emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* List-table feature (or a potential quick and easy mullti-lines table in org?)
@ 2011-03-17 11:04 Ben
  2011-03-17 11:16 ` Jambunathan K
  2011-03-17 15:41 ` Nicolas
  0 siblings, 2 replies; 8+ messages in thread
From: Ben @ 2011-03-17 11:04 UTC (permalink / raw)
  To: emacs org-mode mailing list

[-- 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 --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: List-table feature (or a potential quick and easy mullti-lines table in org?)
  2011-03-17 11:04 List-table feature (or a potential quick and easy mullti-lines table in org?) Ben
@ 2011-03-17 11:16 ` Jambunathan K
  2011-03-17 15:41 ` Nicolas
  1 sibling, 0 replies; 8+ messages in thread
From: Jambunathan K @ 2011-03-17 11:16 UTC (permalink / raw)
  To: emacs-orgmode


>  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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: List-table feature (or a potential quick and easy mullti-lines table in org?)
  2011-03-17 11:04 List-table feature (or a potential quick and easy mullti-lines table in org?) Ben
  2011-03-17 11:16 ` Jambunathan K
@ 2011-03-17 15:41 ` Nicolas
  2011-03-17 22:18   ` Ben
  1 sibling, 1 reply; 8+ messages in thread
From: Nicolas @ 2011-03-17 15:41 UTC (permalink / raw)
  To: Ben; +Cc: emacs org-mode mailing list

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: List-table feature (or a potential quick and easy mullti-lines table in org?)
  2011-03-17 15:41 ` Nicolas
@ 2011-03-17 22:18   ` Ben
  2011-03-18  0:31     ` Nick Dokos
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Ben @ 2011-03-17 22:18 UTC (permalink / raw)
  To: emacs org-mode mailing list

[-- 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 --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Re: List-table feature (or a potential quick and easy mullti-lines table in org?)
  2011-03-17 22:18   ` Ben
@ 2011-03-18  0:31     ` Nick Dokos
  2011-03-18  0:33     ` feng shu
  2011-03-18  7:02     ` Nicolas
  2 siblings, 0 replies; 8+ messages in thread
From: Nick Dokos @ 2011-03-18  0:31 UTC (permalink / raw)
  To: Ben; +Cc: nicholas.dokos, emacs org-mode mailing list

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Re: List-table feature (or a potential quick and easy mullti-lines table in org?)
  2011-03-17 22:18   ` Ben
  2011-03-18  0:31     ` Nick Dokos
@ 2011-03-18  0:33     ` feng shu
  2011-03-18  7:02     ` Nicolas
  2 siblings, 0 replies; 8+ messages in thread
From: feng shu @ 2011-03-18  0:33 UTC (permalink / raw)
  To: emacs-orgmode

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
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: List-table feature (or a potential quick and easy mullti-lines table in org?)
  2011-03-17 22:18   ` Ben
  2011-03-18  0:31     ` Nick Dokos
  2011-03-18  0:33     ` feng shu
@ 2011-03-18  7:02     ` Nicolas
  2011-03-18  9:55       ` Ben
  2 siblings, 1 reply; 8+ messages in thread
From: Nicolas @ 2011-03-18  7:02 UTC (permalink / raw)
  To: Ben; +Cc: emacs org-mode mailing list

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: List-table feature (or a potential quick and easy mullti-lines table in org?)
  2011-03-18  7:02     ` Nicolas
@ 2011-03-18  9:55       ` Ben
  0 siblings, 0 replies; 8+ messages in thread
From: Ben @ 2011-03-18  9:55 UTC (permalink / raw)
  To: emacs org-mode mailing list

[-- 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 --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-03-18  9:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-17 11:04 List-table feature (or a potential quick and easy mullti-lines table in org?) Ben
2011-03-17 11:16 ` Jambunathan K
2011-03-17 15:41 ` Nicolas
2011-03-17 22:18   ` Ben
2011-03-18  0:31     ` Nick Dokos
2011-03-18  0:33     ` feng shu
2011-03-18  7:02     ` Nicolas
2011-03-18  9:55       ` Ben

Code repositories for project(s) associated with this 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).