org-capture: Fix completion for properties in capture buffer

* lisp/org.el (org-read-property-value):
* lisp/org-capture.el (org-capture-fill-template): Sidestep
  `org-set-property'.  Use previous function and `org-entry-put'
  instead.

Reported-by: Eric Danan <eric.danan@u-cergy.fr>
<http://lists.gnu.org/r/emacs-orgmode/2018-06/msg00061.html>
This commit is contained in:
Nicolas Goaziou 2018-06-16 16:39:25 +02:00
parent dcf1796636
commit 42a2c248eb
2 changed files with 39 additions and 17 deletions

View File

@ -1695,7 +1695,19 @@ The template may still contain \"%?\" for cursor positioning."
first-value)))
(_ (error "Invalid `org-capture--clipboards' value: %S"
org-capture--clipboards)))))
("p" (org-set-property prompt nil))
("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)))))
((or "t" "T" "u" "U")
;; These are the date/time related ones.
(let* ((upcase? (equal (upcase key) key))

View File

@ -15636,23 +15636,33 @@ This is computed according to `org-property-set-functions-alist'."
(or (cdr (assoc property org-property-set-functions-alist))
'org-completing-read))
(defun org-read-property-value (property)
"Read PROPERTY value from user."
(defun org-read-property-value (property &optional pom)
"Read value for PROPERTY, as a string.
When optional argument POM is non-nil, completion uses additional
information, i.e., allowed or existing values at point or marker
POM."
(let* ((completion-ignore-case t)
(allowed (org-property-get-allowed-values nil property 'table))
(cur (org-entry-get nil property))
(prompt (concat property " value"
(if (and cur (string-match "\\S-" cur))
(concat " [" cur "]") "") ": "))
(set-function (org-set-property-function property))
(val (if allowed
(funcall set-function prompt allowed nil
(not (get-text-property 0 'org-unrestricted
(caar allowed))))
(funcall set-function prompt
(mapcar 'list (org-property-values property))
nil nil "" nil cur))))
(org-trim val)))
(allowed
(or (org-property-get-allowed-values nil property 'table)
(and pom (org-property-get-allowed-values pom property 'table))))
(current (org-entry-get nil property))
(prompt (format "%s value%s: "
property
(if (org-string-nw-p current)
(format " [%s]" current)
"")))
(set-function (org-set-property-function property)))
(org-trim
(if allowed
(funcall set-function
prompt allowed nil
(not (get-text-property 0 'org-unrestricted (caar allowed))))
(let ((all (mapcar #'list
(append (org-property-values property)
(and pom
(org-with-point-at pom
(org-property-values property)))))))
(funcall set-function prompt all nil nil "" nil current))))))
(defvar org-last-set-property nil)
(defvar org-last-set-property-value nil)