emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Juan Pechiar <juan@pechiar.com>
To: Vikas Rawal <vikaslists@agrarianresearch.org>
Cc: org-mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: Converting table to properties
Date: Wed, 6 Jun 2012 10:06:38 -0300	[thread overview]
Message-ID: <20120606130638.GC6258@soloJazz.com> (raw)
In-Reply-To: <-8912430512402798276@unknownmsgid>

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.

  reply	other threads:[~2012-06-06 13:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06 12:25 Converting table to properties Vikas Rawal
2012-06-06 13:06 ` Juan Pechiar [this message]
2012-06-07 23:44   ` Vikas Rawal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120606130638.GC6258@soloJazz.com \
    --to=juan@pechiar.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=vikaslists@agrarianresearch.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).