all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juan <pechiar@computer.org>
To: Emacs-orgmode <emacs-orgmode@gnu.org>
Subject: [CODE SNIPPET] transpose table at point
Date: Thu, 8 Jul 2010 15:10:13 -0300	[thread overview]
Message-ID: <20100708181013.GA28721@soloJazz.com> (raw)

The below code snippet is an interactive function to transpose an
org-mode table.

Just works for normal tables (no formulas, etc.).

Evaluate the code below (by throwing into .emacs, or by calling C-x
C-e after the defun()), and call M-x org-transpose-table-at-point with
the cursor on a table.

The magic part was stolen from the Library of Babel (1).

Hope it helps.

.j.

(1)  http://orgmode.org/worg/org-contrib/babel/library-of-babel.php#sec-3_2

8<------------------------------------------------------------

(require 'cl)

(defun org-transpose-table-at-point ()
  "Transpose orgmode table at point, eliminate hlines."
  (interactive)
  (let ((contents (apply #'mapcar* #'list    ;; <== LOB magic imported here
                         (remove-if-not 'listp  ;; remove 'hline from list
                                        (org-table-to-lisp))))  ;; signals error if not table
        )
    (delete-region (org-table-begin) (org-table-end))
    (insert (mapconcat (lambda(x) (concat "| " (mapconcat 'identity x " | " ) "  |\n" ))
                       contents
                       ""))
    (org-table-align)
    )
)

                 reply	other threads:[~2010-07-08 18:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=20100708181013.GA28721@soloJazz.com \
    --to=pechiar@computer.org \
    --cc=emacs-orgmode@gnu.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 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.