Browse Source

Fix problem with :exact-positions in capture

* lisp/org-capture.el (org-capture-place-entry): Set :exact-position
before doing other stuff, to allow function with other target settings

TINYCHANGE

Assuming file "test.org" has a single headline "* Level 1" (ended with
newline character), when trying to use function type capture target in
an org-capture template, as shown in the example:

(setq org-capture-templates
      `(("t"
         "Test function type target"
         entry
         (function
          (lambda ()
            (set-buffer (org-capture-target-buffer "test.org"))
            (goto-char (point-max))))
         "* Level 2")))

When this template gets filled, file "test.org" becomes:

* Level 1
* Level 2

Instead of:

* Level 1
** Level 2

This is because when using function type target, `:exact-position' is
used to store buffer position returned by user's function (the lambda
function here), and function `org-capture-place-entry' will never
insert template as a child of current entry when `:exact-position' is
used.

The problem is addressed by not special casing for `:exact-position'
in function `org-capture-place-entry'.

York
York Zhao 11 years ago
parent
commit
f1583aab46
1 changed files with 2 additions and 2 deletions
  1. 2 2
      lisp/org-capture.el

+ 2 - 2
lisp/org-capture.el

@@ -1021,9 +1021,9 @@ may have been stored before."
 	 (target-entry-p (org-capture-get :target-entry-p))
 	 level beg end file)
 
+    (and (org-capture-get :exact-position)
+	 (goto-char (org-capture-get :exact-position)))
     (cond
-     ((org-capture-get :exact-position)
-      (goto-char (org-capture-get :exact-position)))
      ((not target-entry-p)
       ;; Insert as top-level entry, either at beginning or at end of file
       (setq level 1)