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)
    )
)


_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Reply via email to