diff --git a/doc/org-manual.org b/doc/org-manual.org index 5d93bac71..462e30f8a 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -1429,7 +1429,8 @@ you, configure the option ~org-table-auto-blank-field~. #+kindex: M-S-RIGHT #+findex: org-table-insert-column - Insert a new column to the right of point position. + Insert a new column at point position. Move the recent column and + all cells to the right of this column to the right. - {{{kbd(M-UP)}}} (~org-table-move-row-up~) :: diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index d46d1bd7c..b5a1349f9 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -470,6 +470,11 @@ I.e. treat the whole file as if it was a subtree. *** Respect narrowing when agenda command is restricted to buffer +*** ~org-table-insert-column~ inserts the column at point position + +Before, the new column was inserted to the right of the column at +point position. + * 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 58e7c3bdb..da9ba345f 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -1290,25 +1290,21 @@ However, when FORCE is non-nil, create new columns if necessary." (while (< (point) end) (unless (org-at-table-hline-p) (org-table-goto-column col t) - (unless (search-forward "|" (line-end-position) t 2) - ;; Add missing vertical bar at the end of the row. - (end-of-line) - (insert "|")) - (insert " |")) + (insert "|")) (forward-line))) - (org-table-goto-column (1+ col)) + (org-table-goto-column col) (org-table-align) ;; Shift appropriately stored shrunk column numbers, then hide the ;; columns again. - (org-table--shrink-columns (mapcar (lambda (c) (if (<= c col) c (1+ c))) + (org-table--shrink-columns (mapcar (lambda (c) (if (< c col) c (1+ c))) shrunk-columns) beg end) (set-marker end nil) ;; Fix TBLFM formulas, if desirable. (when (or (not org-table-fix-formulas-confirm) (funcall org-table-fix-formulas-confirm "Fix formulas? ")) - (org-table-fix-formulas "$" nil col 1) - (org-table-fix-formulas "$LR" nil col 1)))) + (org-table-fix-formulas "$" nil (1- col) 1) + (org-table-fix-formulas "$LR" nil (1- col) 1)))) (defun org-table-find-dataline () "Find a data line in the current table, which is needed for column commands. diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index 14094deb6..173c7b823 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -2351,45 +2351,45 @@ See also `test-org-table/copy-field'." (org-table-insert-column))) ;; Insert new column after current one. (should - (equal "| a | |\n" + (equal "| | a |\n" (org-test-with-temp-text "| a |" (org-table-insert-column) (buffer-string)))) (should - (equal "| a | | b |\n" + (equal "| | a | b |\n" (org-test-with-temp-text "| a | b |" (org-table-insert-column) (buffer-string)))) ;; Move point into the newly created column. (should - (equal " |" + (equal " | a |" (org-test-with-temp-text "| a |" (org-table-insert-column) (buffer-substring-no-properties (point) (line-end-position))))) (should - (equal " | b |" + (equal " | a | b |" (org-test-with-temp-text "| a | b |" (org-table-insert-column) (buffer-substring-no-properties (point) (line-end-position))))) ;; Handle missing vertical bar in the last column. (should - (equal "| a | |\n" + (equal "| | a |\n" (org-test-with-temp-text "| a" (org-table-insert-column) (buffer-string)))) (should - (equal " |" + (equal " | a |" (org-test-with-temp-text "| a" (org-table-insert-column) (buffer-substring-no-properties (point) (line-end-position))))) ;; Handle column insertion when point is before first column. (should - (equal " | a | |\n" + (equal " | | a |\n" (org-test-with-temp-text " | a |" (org-table-insert-column) (buffer-string)))) (should - (equal " | a | | b |\n" + (equal " | | a | b |\n" (org-test-with-temp-text " | a | b |" (org-table-insert-column) (buffer-string))))) @@ -2397,8 +2397,8 @@ See also `test-org-table/copy-field'." (ert-deftest test-org-table/insert-column-with-formula () "Test `org-table-insert-column' with a formula in place." (should - (equal "| 1 | | 1 | 2 | -#+TBLFM: $4=$1+$3" + (equal "| | 1 | 1 | 2 | +#+TBLFM: $4=$2+$3" (org-test-with-temp-text "| 1 | 1 | 2 | #+TBLFM: $3=$1+$2"