summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Wahl <marcowahlsoft@gmail.com>2020-04-18 16:16:02 +0200
committerMarco Wahl <marcowahlsoft@gmail.com>2020-04-18 16:16:02 +0200
commitbb9dfdafeb66df2e2b183d741caa1adfe1976e51 (patch)
tree09b6cc30829936a347d1dfcdf0b7e6420ad7a3e4
parent22d2b0ac8437e1207ac1b3f9fda8be3bfa7e9d97 (diff)
downloadorg-mode-bb9dfdafeb66df2e2b183d741caa1adfe1976e51.tar.gz
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
-rw-r--r--etc/ORG-NEWS5
-rw-r--r--lisp/org-table.el2
-rw-r--r--testing/lisp/test-org-table.el38
3 files changed, 44 insertions, 1 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index b5a1349..aeba960 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 da9ba34..f22e6ec 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 173c7b8..a89ee44 100644
--- a/testing/lisp/test-org-table.el
+++ b/testing/lisp/test-org-table.el
@@ -2341,6 +2341,44 @@ See also `test-org-table/copy-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
+ "| <point> | a |\n"
+ (org-table-delete-column)
+ (buffer-string))))
+ ;; Delete column and check location of point.
+ (should
+ (= 2
+ (org-test-with-temp-text
+ "| a | <point>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 |<point>\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<point> |"
+ (org-table-delete-column)
+ (org-table-delete-column)
+ (buffer-string)))))
+
+
;;; Inserting rows, inserting columns
(ert-deftest test-org-table/insert-column ()