summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brand <michael.ch.brand@gmail.com>2013-09-30 20:32:29 +0200
committerCarsten Dominik <carsten.dominik@gmail.com>2013-10-15 16:49:07 +0200
commitfb5003ea6314666a2701e7c5ef689f9370d95209 (patch)
tree995d2a0b254ee6c9bae563d6ccca1c16e1244527
parent2eef1b45495432f14520d42902bd0d246305efe3 (diff)
downloadorg-mode-fb5003ea6314666a2701e7c5ef689f9370d95209.tar.gz
org-table-transpose-table-at-point: Preserve indentation and point
* lisp/org-table.el (org-table-transpose-table-at-point): Preserve indentatinon of first row. Restore point to transposed field in transposed table.
-rw-r--r--lisp/org-table.el21
1 files changed, 15 insertions, 6 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 5bc754c..7be77cc 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -1834,7 +1834,7 @@ blindly applies a recipe that works for simple tables."
(goto-char beg)))))
(defun org-table-transpose-table-at-point ()
- "Transpose orgmode table at point and eliminate hlines.
+ "Transpose Org table at point and eliminate hlines.
So a table like
| 1 | 2 | 4 | 5 |
@@ -1849,9 +1849,11 @@ will be transposed as
| 4 | c | g |
| 5 | d | h |
-Note that horizontal lines disappeared."
+Note that horizontal lines disappear."
(interactive)
(let* ((table (delete 'hline (org-table-to-lisp)))
+ (dline_old (org-table-current-line))
+ (col_old (org-table-current-column))
(contents (mapcar (lambda (p)
(let ((tp table))
(mapcar
@@ -1861,10 +1863,17 @@ Note that horizontal lines disappeared."
(setq tp (cdr tp))))
table)))
(car table))))
- (delete-region (org-table-begin) (org-table-end))
- (insert (mapconcat (lambda(x) (concat "| " (mapconcat 'identity x " | " ) " |\n" ))
- contents ""))
- (org-table-align)))
+ (goto-char (org-table-begin))
+ (re-search-forward "|")
+ (backward-char)
+ (delete-region (point) (org-table-end))
+ (insert (mapconcat
+ (lambda(x)
+ (concat "| " (mapconcat 'identity x " | " ) " |\n" ))
+ contents ""))
+ (org-table-goto-line col_old)
+ (org-table-goto-column dline_old))
+ (org-table-align))
;;;###autoload
(defun org-table-wrap-region (arg)