From bb9dfdafeb66df2e2b183d741caa1adfe1976e51 Mon Sep 17 00:00:00 2001 From: Marco Wahl Date: Sat, 18 Apr 2020 16:16:02 +0200 Subject: [PATCH] org-table: Make column delete consistent with row delete * lisp/org-table.el (org-table-delete-column): Stay in the column at delete. Exceptionally allow column delete when point is at eol immediately to the right of a cell seperator. A hint by Eric S Fraga led to this commit. https://lists.gnu.org/archive/html/emacs-orgmode/2020-04/msg00283.html --- etc/ORG-NEWS | 5 +++++ lisp/org-table.el | 2 +- testing/lisp/test-org-table.el | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index b5a1349f9..aeba9602d 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -475,6 +475,11 @@ I.e. treat the whole file as if it was a subtree. Before, the new column was inserted to the right of the column at point position. +*** Table column deletion now consistent with row deletion + +Point stays in the column at deletion, except when deleting the +rightmost column. + * Version 9.2 ** Incompatible changes *** Removal of OrgStruct mode mode and radio lists diff --git a/lisp/org-table.el b/lisp/org-table.el index da9ba345f..f22e6ec96 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -1427,6 +1427,7 @@ Swap with anything in target cell." (interactive) (unless (org-at-table-p) (user-error "Not at a table")) (org-table-find-dataline) + (and (eolp) (looking-back "|" 1) (backward-char)) ; Snap into last column. (org-table-check-inside-data-field nil t) (let* ((col (org-table-current-column)) (beg (org-table-begin)) @@ -1442,7 +1443,6 @@ Swap with anything in target cell." (and (looking-at "|[^|\n]+|") (replace-match "|"))) (forward-line))) - (org-table-goto-column (max 1 (1- col))) (org-table-align) ;; Shift appropriately stored shrunk column numbers, then hide the ;; columns again. diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index 173c7b823..a89ee4450 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -2340,6 +2340,44 @@ See also `test-org-table/copy-field'." (ignore-errors (org-table-previous-field)) (char-after))))) + +;;; Deleting columns +(ert-deftest test-org-table/delete-column () + "Test `org-table-delete-column'." + ;; Error when outside a table. + (should-error + (org-test-with-temp-text "Paragraph" + (org-table-delete-column))) + ;; Delete first column. + (should + (equal "| a |\n" + (org-test-with-temp-text + "| | a |\n" + (org-table-delete-column) + (buffer-string)))) + ;; Delete column and check location of point. + (should + (= 2 + (org-test-with-temp-text + "| a | b | c |" + (org-table-delete-column) + (org-table-current-column)))) + ;; Delete column when at end of line and immediately after a "|". + (should + (equal "| a |\n" + (org-test-with-temp-text + "| a | b |\n" + (org-table-delete-column) + (buffer-string)))) + ;; Delete two columns starting with the last column. + (should + (equal "| a |\n" + (org-test-with-temp-text + "| a | b | c |" + (org-table-delete-column) + (org-table-delete-column) + (buffer-string))))) + ;;; Inserting rows, inserting columns