emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
   commit b67b6b7844f619f40a79dff69e700f24ac8d6ac9 (patch)
   parent bf25b6891 Rewrite of contrib/lisp/org-velocity.el.
     tree 8d0745b99595daa407eae115018ef8d93473d18d
   author Bastien Guerry <bzg@altern.org>  2011-12-11 17:34:37 +0100
committer Bastien Guerry <bzg@altern.org>  2011-12-11 17:34:37 +0100

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


glossary
--------
Commit objects reference one tree, and zero or more parents.

Single parent commits can typically generate a patch in
unified diff format via `git format-patch'.

Multiple parents means the commit is a merge.

Root commits have no ancestor.  Note that it is
possible to have multiple root commits when merging independent histories.

Every commit references one top-level tree object.

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