From b67b6b7844f619f40a79dff69e700f24ac8d6ac9 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Sun, 11 Dec 2011 17:34:37 +0100 Subject: [PATCH] New command: `org-table-transpose-table-at-point'. * org-table.el (org-table-transpose-table-at-point): New command. Thanks to Juan Pechiar for this function. --- lisp/org-table.el | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lisp/org-table.el b/lisp/org-table.el index 6ea072751..09f896897 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -1726,6 +1726,35 @@ blindly applies a recipe that works for simple tables." (replace-match "-+")) (goto-char beg))))) +(defun org-table-transpose-table-at-point () + "Transpose orgmode table at point and eliminate hlines. +So a table like + +| 1 | 2 | 4 | 5 | +|---+---+---+---| +| a | b | c | d | +| e | f | g | h | + +will be transposed as + +| 1 | a | e | +| 2 | b | f | +| 4 | c | g | +| 5 | d | h | + +Note that horizontal lines disappeared." + (interactive) + (let ((contents + (apply #'mapcar* #'list + ;; remove 'hline from list + (remove-if-not 'listp + ;; signals error if not table + (org-table-to-lisp))))) + (delete-region (org-table-begin) (org-table-end)) + (insert (mapconcat (lambda(x) (concat "| " (mapconcat 'identity x " | " ) " |\n" )) + contents "")) + (org-table-align))) + (defun org-table-wrap-region (arg) "Wrap several fields in a column like a paragraph. This is useful if you'd like to spread the contents of a field over several -- 2.11.4.GIT