From 9d51a8b5a033f5f066f7ed6e583e0e412f9376cf Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 17 May 2018 22:46:09 +0200 Subject: [PATCH] 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 --- lisp/org-capture.el | 3 ++- testing/lisp/test-org-capture.el | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index d87fb31b5..eeddd2ab4 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 460fb151b..4b9b4456d 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"