emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Vikas Rawal <vikaslists@agrarianresearch.org>
To: Juan Pechiar <juan@pechiar.com>
Cc: org-mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: Converting table to properties
Date: Fri, 8 Jun 2012 05:14:00 +0530	[thread overview]
Message-ID: <6939046439501716163@unknownmsgid> (raw)
In-Reply-To: <20120606130638.GC6258@soloJazz.com>

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

      reply	other threads:[~2012-06-07 23:44 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
2012-06-07 23:44   ` Vikas Rawal [this message]

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=6939046439501716163@unknownmsgid \
    --to=vikaslists@agrarianresearch.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=juan@pechiar.com \
    /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).