diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-12-02 17:23:03 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-12-02 17:23:03 +0100 |
commit | ca43c1f262b6e88881b24023b517e5bb4a5b6804 (patch) | |
tree | 386645778a0ce82d91fb6463f73879950d31536e | |
parent | f53d1e2005a26a52427b7514f2d3e7cfa3ff2562 (diff) | |
download | org-mode-ca43c1f262b6e88881b24023b517e5bb4a5b6804.tar.gz |
Fix RET past the last column of a table
* lisp/org.el (org-return): Split the table before first column or
after last one.
* lisp/org-table.el (org-table-next-row): Remove code handling split.
* testing/lisp/test-org.el (test-org/return): Add test.
-rw-r--r-- | lisp/org-table.el | 26 | ||||
-rw-r--r-- | lisp/org.el | 10 | ||||
-rw-r--r-- | testing/lisp/test-org.el | 12 |
3 files changed, 30 insertions, 18 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el index d51750f..6ebd6da 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -1087,22 +1087,18 @@ Before doing so, re-align the table if necessary." (interactive) (org-table-maybe-eval-formula) (org-table-maybe-recalculate-line) - (if (or (looking-at "[ \t]*$") - (save-excursion (skip-chars-backward " \t") (bolp))) - (newline) - (if (and org-table-automatic-realign - org-table-may-need-update) - (org-table-align)) - (let ((col (org-table-current-column))) - (beginning-of-line 2) - (if (or (not (org-at-table-p)) + (if (and org-table-automatic-realign + org-table-may-need-update) + (org-table-align)) + (let ((col (org-table-current-column))) + (beginning-of-line 2) + (when (or (not (org-at-table-p)) (org-at-table-hline-p)) - (progn - (beginning-of-line 0) - (org-table-insert-row 'below))) - (org-table-goto-column col) - (skip-chars-backward "^|\n\r") - (if (looking-at " ") (forward-char 1))))) + (beginning-of-line 0) + (org-table-insert-row 'below)) + (org-table-goto-column col) + (skip-chars-backward "^|\n\r") + (when (looking-at " ") (forward-char)))) ;;;###autoload (defun org-table-copy-down (n) diff --git a/lisp/org.el b/lisp/org.el index 7ec61bb..f25088f 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -21042,13 +21042,17 @@ object (e.g., within a comment). In these case, you need to use (let ((context (if org-return-follows-link (org-element-context) (org-element-at-point)))) (cond - ;; In a table, call `org-table-next-row'. + ;; In a table, call `org-table-next-row'. However, before first + ;; column or after last one, split the table. ((or (and (eq (org-element-type context) 'table) (>= (point) (org-element-property :contents-begin context)) (< (point) (org-element-property :contents-end context))) (org-element-lineage context '(table-row table-cell) t)) - (org-table-justify-field-maybe) - (call-interactively #'org-table-next-row)) + (if (or (looking-at-p "[ \t]*$") + (save-excursion (skip-chars-backward " \t") (bolp))) + (insert "\n") + (org-table-justify-field-maybe) + (call-interactively #'org-table-next-row))) ;; On a link or a timestamp, call `org-open-at-point' if ;; `org-return-follows-link' allows it. Tolerate fuzzy ;; locations, e.g., in a comment, as `org-open-at-point'. diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 9c06612..e1ef482 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1179,6 +1179,18 @@ (equal "* h\n" (org-test-with-temp-text "*<point> h" (org-return) + (buffer-string)))) + ;; Before first column or after last one in a table, split the + ;; table. + (should + (equal "| a |\n\n| b |" + (org-test-with-temp-text "| a |\n<point>| b |" + (org-return) + (buffer-string)))) + (should + (equal "| a |\n\n| b |" + (org-test-with-temp-text "| a |<point>\n| b |" + (org-return) (buffer-string))))) (ert-deftest test-org/meta-return () |