all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Converting table to properties
@ 2012-06-06 12:25 Vikas Rawal
  2012-06-06 13:06 ` Juan Pechiar
  0 siblings, 1 reply; 3+ messages in thread
From: Vikas Rawal @ 2012-06-06 12:25 UTC (permalink / raw)
  To: org-mode mailing list

I have a table under each of several headlines in an org file. Each
table has a row of column labels and a row of data. I would like to
convert the table into properties, with labels coming from first row
and values of properties coming from the second row.

How should I do this?

Vikas

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

* Re: Converting table to properties
  2012-06-06 12:25 Converting table to properties Vikas Rawal
@ 2012-06-06 13:06 ` Juan Pechiar
  2012-06-07 23:44   ` Vikas Rawal
  0 siblings, 1 reply; 3+ messages in thread
From: Juan Pechiar @ 2012-06-06 13:06 UTC (permalink / raw)
  To: Vikas Rawal; +Cc: org-mode mailing list

On Wed, Jun 06, 2012 at 05:55:52PM +0530, Vikas Rawal wrote:
> I have a table under each of several headlines in an org file. Each
> table has a row of column labels and a row of data. I would like to
> convert the table into properties, with labels coming from first row
> and values of properties coming from the second row.
>
> How should I do this?

Hi Vikas,

This is a quick hack on org-table-transpose-table-at-point to print
out a property list instead of a table.

#+begin_src elisp

(defun vikas-convert ()
  "table to props"
  (interactive)
  (let ((contents
         (apply #'mapcar* #'list
                ;; remove 'hline from list
                   (delq nil (mapcar (lambda (x) (when (listp x) x))
                                       (org-table-to-lisp))))))
    (delete-region (org-table-begin) (org-table-end))
    (insert "  :PROPERTIES:\n")
    (insert (mapconcat (lambda(x) (concat "  :" (first x) ": " (second
    x) "\n" ))
                       contents ""))
    (insert "  :END:\n\n")))

#+end_src

This transforms:

| PROP1 | PROP2 | PROP3 |
| 1     | 2     | 3     |

into

  :PROPERTIES:
  :PROP1: 1
  :PROP2: 2
  :PROP3: 3
  :END:

Hope it helps.
.j.

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

* Re: Converting table to properties
  2012-06-06 13:06 ` Juan Pechiar
@ 2012-06-07 23:44   ` Vikas Rawal
  0 siblings, 0 replies; 3+ messages in thread
From: Vikas Rawal @ 2012-06-07 23:44 UTC (permalink / raw)
  To: Juan Pechiar; +Cc: org-mode mailing list

[-- Attachment #1: Type: text/plain, Size: 831 bytes --]

This is a quick hack on org-table-transpose-table-at-point to print
out a property list instead of a table.

#+begin_src elisp

(defun vikas-convert ()
 "table to props"
 (interactive)
 (let ((contents
        (apply #'mapcar* #'list
               ;; remove 'hline from list
                  (delq nil (mapcar (lambda (x) (when (listp x) x))
                                      (org-table-to-lisp))))))
   (delete-region (org-table-begin) (org-table-end))
   (insert "  :PROPERTIES:\n")
   (insert (mapconcat (lambda(x) (concat "  :" (first x) ": " (second
   x) "\n" ))
                      contents ""))
   (insert "  :END:\n\n")))

#+end_src

This transforms:

| PROP1 | PROP2 | PROP3 |
| 1     | 2     | 3     |

into

 :PROPERTIES:
 :PROP1: 1
 :PROP2: 2
 :PROP3: 3
 :END:


Your code worked flawlessly. Thank you.

Vikas

[-- Attachment #2: Type: text/html, Size: 1752 bytes --]

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

end of thread, other threads:[~2012-06-07 23:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-06 12:25 Converting table to properties Vikas Rawal
2012-06-06 13:06 ` Juan Pechiar
2012-06-07 23:44   ` Vikas Rawal

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.