diff options
author | Phil Hudson <phil.hudson@iname.com> | 2020-09-23 14:09:49 +0200 |
---|---|---|
committer | Bastien <bzg@gnu.org> | 2020-09-23 14:12:08 +0200 |
commit | 83c93e6fede493611c44d51abdd972b879f328a8 (patch) | |
tree | af4b3288fcec44c8f6970dc4028a417494d62498 | |
parent | e2bb60581b489f92c9f2479994d484d2104968db (diff) | |
download | org-mode-83c93e6fede493611c44d51abdd972b879f328a8.tar.gz |
org-capture.el: Give a default value when prompting for a property
* lisp/org-capture.el (org-capture-templates)
(org-capture-fill-template): Enable declaring a default value
when prompting for a property during capture.
* lisp/org.el (org-read-property-value): Add parameter DEFAULT
for an initial/default/suggested property value.
* doc/org-manual.org: Document declaring a default value for a
prompted property during capture.
-rw-r--r-- | doc/org-manual.org | 3 | ||||
-rw-r--r-- | lisp/org-capture.el | 5 | ||||
-rw-r--r-- | lisp/org.el | 8 |
3 files changed, 11 insertions, 5 deletions
diff --git a/doc/org-manual.org b/doc/org-manual.org index 043f2dd..e7d25b9 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -7858,7 +7858,8 @@ here: - =%^{PROP}p= :: - Prompt the user for a value for property {{{var(PROP)}}}. + Prompt the user for a value for property {{{var(PROP)}}}. You may + specify a default value with =%^{PROP|default}=. - =%^{PROMPT}= :: diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 2ef55cd..bdaee41 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -332,6 +332,8 @@ be replaced with content and expanded: %^C Interactive selection of which kill or clip to use. %^L Like %^C, but insert as link. %^{prop}p Prompt the user for a value for property `prop'. + A default value can be specified like this: + %^{prop|default}p. %^{prompt} Prompt the user for a string and replace this sequence with it. A default value and a completion table can be specified like this: %^{prompt|default|completion2|completion3|...}. @@ -1787,7 +1789,8 @@ The template may still contain \"%?\" for cursor positioning." (setq l (org-up-heading-safe))) (if l (point-marker) (point-min-marker))))))) - (value (org-read-property-value prompt pom))) + (value + (org-read-property-value prompt pom default))) (org-set-property prompt value))) ((or "t" "T" "u" "U") ;; These are the date/time related ones. diff --git a/lisp/org.el b/lisp/org.el index d45a789..ec336c7 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -13300,11 +13300,12 @@ 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 &optional pom) +(defun org-read-property-value (property &optional pom default) "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." +POM. +Optional argument DEFAULT provides a default value for PROPERTY." (let* ((completion-ignore-case t) (allowed (or (org-property-get-allowed-values nil property 'table) @@ -13320,7 +13321,8 @@ POM." (if allowed (funcall set-function prompt allowed nil - (not (get-text-property 0 'org-unrestricted (caar allowed)))) + (not (get-text-property 0 'org-unrestricted (caar allowed))) + default nil default) (let ((all (mapcar #'list (append (org-property-values property) (and pom |