diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-10-23 00:04:37 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-10-23 00:43:59 +0200 |
commit | ad0fce50ebe8864c365bfba4d4a8e0e6a767d266 (patch) | |
tree | 90ee1a613c23716b69250dbe52eb897c17fd3bc0 | |
parent | aaa3372b8bf159c37d935decea3bca7afb0f5337 (diff) | |
download | org-mode-ad0fce50ebe8864c365bfba4d4a8e0e6a767d266.tar.gz |
org-capture: Small fix to table line capture
* lisp/org-capture.el (org-capture-place-table-line): Handle abort
table line insertion more gracefully.
* testing/lisp/test-org-capture.el (test-org-capture/abort): Add tests
-rw-r--r-- | lisp/org-capture.el | 25 | ||||
-rw-r--r-- | testing/lisp/test-org-capture.el | 9 |
2 files changed, 22 insertions, 12 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 54fbe39..462dbb1 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1271,18 +1271,19 @@ may have been stored before." (t (goto-char (org-table-end)))) ;; Insert text and position point according to template. - (unless (bolp) (insert "\n")) - (let ((beg (point)) - (end (save-excursion - (insert text) - (point)))) - (org-capture-position-for-last-stored 'table-line) - (org-capture-mark-kill-region beg end) - (org-capture-narrow beg end) - (when (or (re-search-backward "%\\?" beg t) - (re-search-forward "%\\?" end t)) - (replace-match ""))) - (org-table-align))) + (let ((origin (point))) + (unless (bolp) (insert "\n")) + (let ((beg (point)) + (end (save-excursion + (insert text) + (point)))) + (org-capture-position-for-last-stored 'table-line) + (org-capture-mark-kill-region origin end) + (org-capture-narrow beg end) + (when (or (search-backward "%?" beg t) + (search-forward "%?" end t)) + (replace-match ""))) + (org-table-align)))) (defun org-capture-place-plain-text () "Place the template plainly. diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el index 10cb457..56f7783 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -161,6 +161,15 @@ (insert "Capture text") (org-capture-kill)) (buffer-string)))) + (should + (equal "| a |\n| b |" + (org-test-with-temp-text-in-file "| a |\n| b |" + (let* ((file (buffer-file-name)) + (org-capture-templates + `(("t" "Table" table-line (file ,file) "| x |")))) + (org-capture nil "t") + (org-capture-kill)) + (buffer-string)))) ;; Test aborting a capture that split the line. (should (equal |