emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christopher League <league@contrapunctus.net>
To: emacs-orgmode@gnu.org
Cc: Christopher League <league@contrapunctus.net>
Subject: [PATCH] org-agenda: Allow org-agenda-overriding-header to be a function
Date: Thu, 12 Aug 2021 18:09:35 -0400	[thread overview]
Message-ID: <20210812220934.178834-2-league@contrapunctus.net> (raw)
In-Reply-To: <20210812220934.178834-1-league@contrapunctus.net>

* org-agenda.el (org-agenda--insert-overriding-header): Allow
`org-agenda-overriding-header' to be a function in addition to a
string or nil. When the custom agenda is created or updated, call that
function and insert the string it returns as the agenda header.

This allows custom commands to produce dynamic headers that include
up-to-date information. For example, this produces a header with a
current timestamp:

(push '("DHD" "Dynamic header demo"
            (lambda ()
               (format-time-string "-- Get crackin’, it’s %H:%M:%S!!\n")
               'face 'org-agenda-structure)))))))

User is free to add any face properties, use Org links, and include a
blank line or not. I am using this to count how many items are in
various inboxes and display them in an agenda.
 lisp/org-agenda.el | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index b4e5547d7..f5e332a29 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -2131,7 +2131,8 @@ works you probably want to add it to `org-agenda-custom-commands' for good."
 The inserted header depends on `org-agenda-overriding-header'.
 If the empty string, don't insert a header.  If any other string,
 insert it as a header.  If nil, insert DEFAULT, which should
-evaluate to a string."
+evaluate to a string.  If a function, call it and insert the
+string that it returns."
   (declare (debug (form)) (indent defun))
     ((not org-agenda-overriding-header) (insert ,default))
@@ -2140,6 +2141,8 @@ evaluate to a string."
      (insert (propertize org-agenda-overriding-header
 			 'face 'org-agenda-structure)
+    ((functionp org-agenda-overriding-header)
+     (insert (funcall org-agenda-overriding-header)))
     (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
@@ -5046,10 +5049,11 @@ used by user-defined selections using `org-agenda-skip-function'.")
 (defvar org-agenda-overriding-header nil
   "When set during agenda, todo and tags searches it replaces the header.
 If an empty string, no header will be inserted.  If any other
-string, it will be inserted as a header.  If nil, a header will
-be generated automatically according to the command.  This
-variable should not be set directly, but custom commands can bind
-it in the options section.")
+string, it will be inserted as a header.  If a function, insert
+the string returned by the function as a header.  If nil, a
+header will be generated automatically according to the command.
+This variable should not be set directly, but custom commands can
+bind it in the options section.")
 (defun org-agenda-skip-entry-if (&rest conditions)
   "Skip entry if any of CONDITIONS is true.

  reply	other threads:[~2021-08-12 22:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12 22:09 [PATCH] org-agenda: Allow org-agenda-overriding-header to be a function Christopher League
2021-08-12 22:09 ` Christopher League [this message]
2021-09-27  8:44   ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210812220934.178834-2-league@contrapunctus.net \
    --to=league@contrapunctus.net \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).