Skip to content

Commit 83c93e6

Browse files
PhilHudsonbzg
authored andcommitted
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.
1 parent e2bb605 commit 83c93e6

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

doc/org-manual.org

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7858,7 +7858,8 @@ here:
78587858

78597859
- =%^{PROP}p= ::
78607860

7861-
Prompt the user for a value for property {{{var(PROP)}}}.
7861+
Prompt the user for a value for property {{{var(PROP)}}}. You may
7862+
specify a default value with =%^{PROP|default}=.
78627863

78637864
- =%^{PROMPT}= ::
78647865

lisp/org-capture.el

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ be replaced with content and expanded:
332332
%^C Interactive selection of which kill or clip to use.
333333
%^L Like %^C, but insert as link.
334334
%^{prop}p Prompt the user for a value for property `prop'.
335+
A default value can be specified like this:
336+
%^{prop|default}p.
335337
%^{prompt} Prompt the user for a string and replace this sequence with it.
336338
A default value and a completion table can be specified like this:
337339
%^{prompt|default|completion2|completion3|...}.
@@ -1787,7 +1789,8 @@ The template may still contain \"%?\" for cursor positioning."
17871789
(setq l (org-up-heading-safe)))
17881790
(if l (point-marker)
17891791
(point-min-marker)))))))
1790-
(value (org-read-property-value prompt pom)))
1792+
(value
1793+
(org-read-property-value prompt pom default)))
17911794
(org-set-property prompt value)))
17921795
((or "t" "T" "u" "U")
17931796
;; These are the date/time related ones.

lisp/org.el

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13300,11 +13300,12 @@ This is computed according to `org-property-set-functions-alist'."
1330013300
(or (cdr (assoc property org-property-set-functions-alist))
1330113301
'org-completing-read))
1330213302

13303-
(defun org-read-property-value (property &optional pom)
13303+
(defun org-read-property-value (property &optional pom default)
1330413304
"Read value for PROPERTY, as a string.
1330513305
When optional argument POM is non-nil, completion uses additional
1330613306
information, i.e., allowed or existing values at point or marker
13307-
POM."
13307+
POM.
13308+
Optional argument DEFAULT provides a default value for PROPERTY."
1330813309
(let* ((completion-ignore-case t)
1330913310
(allowed
1331013311
(or (org-property-get-allowed-values nil property 'table)
@@ -13320,7 +13321,8 @@ POM."
1332013321
(if allowed
1332113322
(funcall set-function
1332213323
prompt allowed nil
13323-
(not (get-text-property 0 'org-unrestricted (caar allowed))))
13324+
(not (get-text-property 0 'org-unrestricted (caar allowed)))
13325+
default nil default)
1332413326
(let ((all (mapcar #'list
1332513327
(append (org-property-values property)
1332613328
(and pom

0 commit comments

Comments
 (0)