diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-06-16 23:15:34 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-06-16 23:15:34 +0200 |
commit | 54abd0f0ead0c98206eb551f639bc3cc727b71b2 (patch) | |
tree | 26218641d4bfd76362152bae12a789cd3a1c3d58 | |
parent | 7fcceecf5d30f815d86e519569d6eabe25e54115 (diff) | |
download | org-mode-54abd0f0ead0c98206eb551f639bc3cc727b71b2.tar.gz |
org-capture: Fix last commit
* lisp/org-capture.el (org-capture-fill-template): Properly handle
allowed values when target sets them.
-rw-r--r-- | lisp/org-capture.el | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el index ef694dd..df91cb4 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1696,18 +1696,35 @@ The template may still contain \"%?\" for cursor positioning." (_ (error "Invalid `org-capture--clipboards' value: %S" org-capture--clipboards))))) ("p" - (let ((value (org-read-property-value - prompt - (set-marker (make-marker) - (org-capture-get :pos) - (org-capture-get :buffer))))) - (org-entry-put - nil prompt - (pcase (assoc-string prompt - org-properties-postprocess-alist - t) - (`(,_ . ,f) (funcall f value)) - (_ value))))) + ;; We remove file properties inherited from + ;; target buffer so `org-read-property-value' has + ;; a chance to find allowed values in sub-trees + ;; from the target buffer. + (setq-local org-file-properties nil) + (let* ((origin (set-marker (make-marker) + (org-capture-get :pos) + (org-capture-get :buffer))) + ;; Find location from where to get allowed + ;; values. If `:target-entry-p' is + ;; non-nil, the current headline in the + ;; target buffer is going to be a parent + ;; headline, so location is fine. + ;; Otherwise, find the parent headline in + ;; the target buffer. + (pom (if (org-capture-get :target-entry-p) origin + (let ((level (progn + (while (org-up-heading-safe)) + (org-current-level)))) + (org-with-point-at origin + (let ((l (if (org-at-heading-p) + (org-current-level) + most-positive-fixnum))) + (while (and l (>= l level)) + (setq l (org-up-heading-safe))) + (if l (point-marker) + (point-min-marker))))))) + (value (org-read-property-value prompt pom))) + (org-set-property prompt value))) ((or "t" "T" "u" "U") ;; These are the date/time related ones. (let* ((upcase? (equal (upcase key) key)) |