emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] [CODE SNIPPET] transpose table at point


From: Juan
Subject: [Orgmode] [CODE SNIPPET] transpose table at point
Date: Thu, 8 Jul 2010 15:10:13 -0300
User-agent: Mutt/1.5.20 (2009-06-14)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]