diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-05-17 22:46:09 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-05-17 22:57:49 +0200 |
commit | 9d51a8b5a033f5f066f7ed6e583e0e412f9376cf (patch) | |
tree | 55b1d7863e827dffdd5ce3ee63c214b04aff64e3 | |
parent | 1cfd5d04e32078f695f2a6a58cd05c77961d6054 (diff) | |
download | org-mode-9d51a8b5a033f5f066f7ed6e583e0e412f9376cf.tar.gz |
org-capture: Fix table line capture with custom location
* lisp/org-capture.el (org-capture-place-table-line): Fix error when
a precise location is given, e.g. with `file+function' target.
* testing/lisp/test-org-capture.el (test-org-capture/table-line): Add
test.
Reported-by: Thomas Holst <thomas_holst@gmx.de>
<http://lists.gnu.org/r/emacs-orgmode/2018-05/msg00359.html>
-rw-r--r-- | lisp/org-capture.el | 3 | ||||
-rw-r--r-- | testing/lisp/test-org-capture.el | 16 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el index d87fb31..eeddd2a 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1204,7 +1204,8 @@ may have been stored before." beg end) (cond ((org-capture-get :exact-position) - (goto-char (org-capture-get :exact-position))) + (setq beg (org-capture-get :exact-position)) + (setq end (save-excursion (outline-next-heading) (point)))) ((not (org-capture-get :target-entry-p)) ;; Table is not necessarily under a heading. Find first table ;; in the buffer. diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el index 460fb15..4b9b445 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -207,6 +207,22 @@ "| x |" :immediate-finish t)))) (org-capture nil "t")) (buffer-string)))) + ;; When a precise location is specified, find the first table after + ;; point, down to the end of the section. + (should + (equal "| a | + + +| b | +| x | +" + (org-test-with-temp-text-in-file "| a |\n\n\n| b |\n" + (let* ((file (buffer-file-name)) + (org-capture-templates + `(("t" "Table" table-line (file+function ,file forward-line) + "| x |" :immediate-finish t)))) + (org-capture nil "t")) + (buffer-string)))) ;; Create a new table with an empty header when none can be found. (should (equal "| | |\n|---+---|\n| a | b |\n" |