OK I think I understand why it doesn't work. I'm attaching a simple
patch that hopefully solves the issue. I've put comments in the commit
message. Please let me know if anything is not clear or if you see
issues.

Eric

On Thu, Jun 7, 2018 at 11:18 PM Eric Danan <eric.da...@u-cergy.fr> wrote:
>
> Thanks.
>
>> As far as I know it is not currently possible to get property
>> auto-completion from the property list of the file itself.
>
>
> I don't understand: when I call "org-set-property" directly from the file 
> (C-c C-x p), it does get all the property values in the file and proposes 
> them for completion. I am probably missing your pint, could I ask you to 
> explain?
>
> Only when I use the "%^{prop}p" capture template element are the values not 
> offered. I don't understand why because looking at the code of 
> "org-capture-fill-template", it seems to simply call "org-set-property" for 
> this element.
>
>> but you could still make use of the stock property in the template and 
>> auto-complete
>> from there
>>
>> For instance:
>>
>> ("T" "TEST" entry (file+headline"/tmp/test.org" "drill")
>>         "** TEST  \n :PROPERTIES:\n :Effort: 
>> %^{prompt|0:10|0:20|0:30|1:00|2:00|3:00}\n :END: \n %^{PROMPT} " )
>>
>> see the rest of the thread for more details 
>> http://lists.gnu.org/archive/html/emacs-orgmode/2011-10/msg01339.html
>
>
> Yes I've read the rest of the thread, but that's not always feasible. In my 
> use case, the property values are titles of academic journals, I can't list 
> them all inside a "%^{prompt}" template element, I need them to be fetched 
> from the file.
>
> Thanks again.
>
> Eric
From 5dd9c5b54d32af1023eb2ea84d8ad702cae3307e Mon Sep 17 00:00:00 2001
From: Eric Danan <eric.danan@u-cergy.fr>
Date: Fri, 8 Jun 2018 16:26:21 +0200
Subject: [PATCH] org-capture.el: Offer property value completions in capture
 template

* lisp/org-capture.el (org-capture-fill-template): When reading a
  property's value for a `%^{prop}p' template element, offer
  completions on the property's allowed or existing values.

This is done by temporarily prepending to the variable
`org-file-property' and entry `(prop_all . vals)' where vals is either
the local or inherited value of `prop_all' at the target location or,
if that is nil, the set of local values of `prop' in the target
buffer.  A dummy value `:ETC' is added in the latter case so that
matching is not required.

The resulting behavior is (hopefully) the same as when using
`org-set-property' directly.  If there is an entry for `prop' in
`org-property-allowed-value-functions', that will be used in
priority.  If not and there is a local or inherited value for
`prop_all' at point or target location, then this will be used.  In
these two cases, matching is required unless `:ETC' belongs to the
allowed values.  Finally, in the absence of allowed values, the set of
local values for `prop' in the current or target buffer is used, with
matching not required.
---
 lisp/org-capture.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index eeddd2ab..b10ba576 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1695,7 +1695,15 @@ (defun org-capture-fill-template (&optional template initial annotation)
 						first-value)))
 			 (_ (error "Invalid `org-capture--clipboards' value: %S"
 				   org-capture--clipboards)))))
-		    ("p" (org-set-property prompt nil))
+		    ("p"
+		     (let* ((prop-all (concat prompt "_ALL"))
+			    (vals (with-current-buffer buffer
+				    (or (org-entry-get nil prop-all 'inherit)
+					(concat (mapconcat 'identity (org-property-values prompt) " ")
+						" :ETC"))))
+			    (org-file-properties (cons (cons prop-all vals)
+						       org-file-properties)))
+		       (org-set-property prompt nil)))
 		    ((or "t" "T" "u" "U")
 		     ;; These are the date/time related ones.
 		     (let* ((upcase? (equal (upcase key) key))
-- 
2.17.0

Reply via email to