diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-07-01 10:34:01 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-07-01 10:34:01 +0200 |
commit | 64cbcb1bffb1a077beb66c2e27427e1993b88378 (patch) | |
tree | 4d19928fafb8e1b8650b14d99e01ebe22ff3b0e8 | |
parent | 282abe89697ea2002e312e9c4752ac2ae49b7388 (diff) | |
parent | 79f29b490ea9424cb5a9a1789b7fbdba0cd9b4d8 (diff) | |
download | org-mode-64cbcb1bffb1a077beb66c2e27427e1993b88378.tar.gz |
Merge branch 'maint'
-rw-r--r-- | lisp/org-table.el | 39 | ||||
-rw-r--r-- | testing/lisp/test-org-table.el | 86 |
2 files changed, 107 insertions, 18 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el index 595c4e9..b5cb535 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -1341,7 +1341,7 @@ value." Only data lines count for this." (save-excursion (let ((c 0) - (pos (point))) + (pos (line-beginning-position))) (goto-char (org-table-begin)) (while (<= (point) pos) (when (looking-at org-table-dataline-regexp) (cl-incf c)) @@ -1536,28 +1536,31 @@ non-nil, the one above is used." (dline1 (org-table-current-dline)) (dline2 (+ dline1 (if up -1 1))) (tonew (if up 0 2)) - txt hline2p) + hline2p) + (when (and up (= (point-min) (line-beginning-position))) + (user-error "Cannot move row further")) (beginning-of-line tonew) - (unless (org-at-table-p) + (when (or (and (not up) (eobp)) (not (org-at-table-p))) (goto-char pos) (user-error "Cannot move row further")) (setq hline2p (looking-at org-table-hline-regexp)) (goto-char pos) - (beginning-of-line 1) - (setq pos (point)) - (setq txt (buffer-substring (point) (1+ (point-at-eol)))) - (delete-region (point) (1+ (point-at-eol))) - (beginning-of-line tonew) - (insert txt) - (beginning-of-line 0) - (org-move-to-column col) - (unless (or hline1p hline2p - (not (or (not org-table-fix-formulas-confirm) - (funcall org-table-fix-formulas-confirm - "Fix formulas? ")))) - (org-table-fix-formulas - "@" (list (cons (number-to-string dline1) (number-to-string dline2)) - (cons (number-to-string dline2) (number-to-string dline1))))))) + (let ((row (delete-and-extract-region (line-beginning-position) + (line-beginning-position 2)))) + (beginning-of-line tonew) + (unless (bolp) (insert "\n")) ;at eob without a newline + (insert row) + (unless (bolp) (insert "\n")) ;missing final newline in ROW + (beginning-of-line 0) + (org-move-to-column col) + (unless (or hline1p hline2p + (not (or (not org-table-fix-formulas-confirm) + (funcall org-table-fix-formulas-confirm + "Fix formulas? ")))) + (org-table-fix-formulas + "@" (list + (cons (number-to-string dline1) (number-to-string dline2)) + (cons (number-to-string dline2) (number-to-string dline1)))))))) ;;;###autoload (defun org-table-insert-row (&optional arg) diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index cf0f056..99f593c 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -2100,6 +2100,92 @@ is t, then new columns should be added as needed" (let ((org-table-tab-jumps-over-hlines nil)) (org-table-next-field)) (buffer-string))))) + + +;;; Moving rows, moving columns + +(ert-deftest test-org-table/move-row-down () + "Test `org-table-move-row-down' specifications." + ;; Error out when row cannot be moved, e.g., it is the last row in + ;; the table. + (should-error + (org-test-with-temp-text "| a |" + (org-table-move-row-down))) + (should-error + (org-test-with-temp-text "| a |\n" + (org-table-move-row-down))) + (should-error + (org-test-with-temp-text "| a |\n| <point>b |" + (org-table-move-row-down))) + ;; Move data lines. + (should + (equal "| b |\n| a |\n" + (org-test-with-temp-text "| a |\n| b |\n" + (org-table-move-row-down) + (buffer-string)))) + (should + (equal "|---|\n| a |\n" + (org-test-with-temp-text "| a |\n|---|\n" + (org-table-move-row-down) + (buffer-string)))) + ;; Move hlines. + (should + (equal "| b |\n|---|\n" + (org-test-with-temp-text "|---|\n| b |\n" + (org-table-move-row-down) + (buffer-string)))) + (should + (equal "|---|\n|---|\n" + (org-test-with-temp-text "|---|\n|---|\n" + (org-table-move-row-down) + (buffer-string)))) + ;; Move rows even without a final newline. + (should + (equal "| b |\n| a |\n" + (org-test-with-temp-text "| a |\n| b |" + (org-table-move-row-down) + (buffer-string))))) + +(ert-deftest test-org-table/move-row-up () + "Test `org-table-move-row-up' specifications." + ;; Error out when row cannot be moved, e.g., it is the first row in + ;; the table. + (should-error + (org-test-with-temp-text "| a |" + (org-table-move-row-up))) + (should-error + (org-test-with-temp-text "| a |\n" + (org-table-move-row-up))) + ;; Move data lines. + (should + (equal "| b |\n| a |\n" + (org-test-with-temp-text "| a |\n| <point>b |\n" + (org-table-move-row-up) + (buffer-string)))) + (should + (equal "| b |\n|---|\n" + (org-test-with-temp-text "|---|\n| <point>b |\n" + (org-table-move-row-up) + (buffer-string)))) + ;; Move hlines. + (should + (equal "|---|\n| a |\n" + (org-test-with-temp-text "| a |\n|<point>---|\n" + (org-table-move-row-up) + (buffer-string)))) + (should + (equal "|---|\n|---|\n" + (org-test-with-temp-text "|---|\n|<point>---|\n" + (org-table-move-row-up) + (buffer-string)))) + ;; Move rows even without a final newline. + (should + (equal "| b |\n| a |\n" + (org-test-with-temp-text "| a |\n| <point>b |" + (org-table-move-row-up) + (buffer-string))))) + + ;;; Miscellaneous |