Visuwesh <[email protected]> writes:
> Looking at the definition of `org-agenda-timerange-leaders' suggests
> that the second item of the list can be a function.
>
> (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
> "Text preceding timerange entries in the agenda view.
> This is a list with two strings. The first applies when the range
> is entirely on one day. The second applies if the range spans several
> days.
> The strings may have two \"%d\" format specifiers which will be filled
> with the sequence number of the days, and the total number of days in the
> range, respectively."
> :group 'org-agenda-line-format
> :type '(list
> (string :tag "Deadline today ")
> (choice :tag "Deadline relative"
> (string :tag "Format string")
> (function))))
> ^^^
>
> However, setting it to a function simply yields a type error since
> `format' expects a string. This has been a problem ever since the
> option was introduced in the commit ea258dbdb.
>
> It would be nice if org could accept a function, as one would expect
> from the definition of the concerned option. The function would accept two
> arguments and return a format-string or a _formatted_ string?
>
> Regards.
> P.S. Please add me to CCs since I don't follow the mailing list.
Hi. This patch fixes this issue. What this patch changes:
1. The first element of `org-agenda-timerange-leaders` now also accepts a
function as a value. I don't know why only the second one "was accepting"
a function, that's a mystery for me
2. Docstring of the variable now tells you that you can use a function,
not only a string. The option you described wasn't documented at all...
3. And of course now org does not throw this error you mentioned
>
>From 4d423386336d566f1346b657a926b51d23a61d02 Mon Sep 17 00:00:00 2001
From: Ilya Chernyshov <[email protected]>
Date: Sun, 7 Jun 2026 15:45:38 +0500
Subject: [PATCH] org-agenda-timerange-leaders: Allow functions as element
values
* lisp/org-agenda.el (org-agenda-timerange-leaders): Allow functions
as element values
* etc/ORG-NEWS: (~org-agenda-timerange-leaders~ now allows to use functions as element values):
Announce the change.
Reported-by: Visuwesh via "General discussions about Org-mode." <[email protected]>
Link: https://list.orgmode.org/orgmode/[email protected]/
---
etc/ORG-NEWS | 5 +++++
lisp/org-agenda.el | 29 +++++++++++++++++++----------
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 5a72b69ea..4d17521d8 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -143,6 +143,11 @@ properties.
# Changes dealing with changing default values of customizations,
# adding new customizations, or changing the interpretation of the
# existing customizations.
+*** ~org-agenda-timerange-leaders~ now allows to use functions as element values
+
+Other than strings, ~org-agenda-timerange-leaders~ now accepts
+functions which must return a string of the same format as usual string
+values.
*** ~org-support-shift-select~ can now make shift-cursor selection work on timestamps
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 62f9c0c3b..2e8bf7276 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1846,14 +1846,17 @@ (defcustom org-agenda-diary-sexp-prefix nil
(defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
"Text preceding timerange entries in the agenda view.
-This is a list with two strings. The first applies when the range
-is entirely on one day. The second applies if the range spans several days.
-The strings may have two \"%d\" format specifiers which will be filled
-with the sequence number of the days, and the total number of days in the
-range, respectively."
+This is a list with two strings or functions that return strings. The
+first applies when the range is entirely on one day. The second applies
+if the range spans several days. The strings may have two \"%d\" format
+specifiers which will be filled with the sequence number of the days,
+and the total number of days in the range, respectively."
:group 'org-agenda-line-format
+ :package-version '(Org . "10.0")
:type '(list
- (string :tag "Deadline today ")
+ (choice :tag "Deadline today "
+ (string :tag "Format string")
+ (function))
(choice :tag "Deadline relative"
(string :tag "Format string")
(function))))
@@ -6871,10 +6874,16 @@ (defun org-agenda-get-blocks ()
(setq txt (org-agenda-format-item
(concat
(when inactive? org-agenda-inactive-leader)
- (format
- (nth (if (= start-day end-day) 0 1)
- org-agenda-timerange-leaders)
- (1+ (- agenda-today start-day)) (1+ (- end-day start-day))))
+ (format
+ (let ((format
+ (if (= start-day end-day)
+ (car org-agenda-timerange-leaders)
+ (cadr org-agenda-timerange-leaders))))
+ (if (functionp format)
+ (funcall format)
+ format))
+ (1+ (- agenda-today start-day))
+ (1+ (- end-day start-day))))
(org-add-props head nil
'effort effort
'effort-minutes effort-minutes)
--
2.52.0