Browse Source

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>
Nicolas Goaziou 1 year ago
parent
commit
9d51a8b5a0
2 changed files with 18 additions and 1 deletions
  1. 2 1
      lisp/org-capture.el
  2. 16 0
      testing/lisp/test-org-capture.el

+ 2 - 1
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.

+ 16 - 0
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"