From: jao <jao@gnu.org>
To: notmuch@notmuchmail.org
Cc: jao <jao@gnu.org>
Subject: [PATCH] emacs: notmuch-show-header-line: allow format strings and functions
Date: Wed, 18 May 2022 20:29:56 +0100 [thread overview]
Message-ID: <20220518192956.1440103-2-jao@gnu.org> (raw)
In-Reply-To: <20220518192956.1440103-1-jao@gnu.org>
If a string value is assigned to notmuch-show-header-line, it's used
as a format string to be passed passed to format-spec with `%s`
substituted by the message's subject. If a function is given, it's
called with the subject as argument, and its return value used as
header line.
As before, t means displaying the subject and nil not using any header
line.
Signed-off-by: jao <jao@gnu.org>
---
emacs/notmuch-show.el | 42 +++++++++++++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 9 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 69f6c845..266afbaa 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -85,8 +85,26 @@ visible for any given message."
:group 'notmuch-show)
(defcustom notmuch-show-header-line t
- "Show a header line with the current message's subject."
- :type 'boolean
+ "Show a header line in notmuch show buffers.
+
+If t (the default), the header line will contain the current
+message's subject.
+
+If a string, this value is interpreted as a format string to be
+passed to `format-spec` with `%s` as the substitution variable
+for the message's subject. E.g., to display the subject trimmed
+to a maximum of 80 columns, you could use \"%>-80s\" as format.
+
+If you assign to this variable a function, the function will be
+called with the subject as argument and its return value used as
+the header line.
+
+Finally, if this variabale is set to nil, no header is
+displayed."
+ :type '(choice (const :tag "No header" ni)
+ (const :tag "Subject" t)
+ (string :tag "Format")
+ (function :tag "Function"))
:group 'notmuch-show)
(defcustom notmuch-show-relative-dates t
@@ -1313,6 +1331,18 @@ fallback if the prior matches no messages."
(push (list thread "and (" context ")") queries))
queries))
+(defun notmuch-show--header-line-format ()
+ "Compute the header line format of a notmuch-show buffer."
+ (when notmuch-show-header-line
+ (let* ((s (notmuch-sanitize
+ (notmuch-show-strip-re (notmuch-show-get-subject))))
+ (subject (replace-regexp-in-string "%" "%%" s)))
+ (cond ((stringp notmuch-show-header-line)
+ (format-spec notmuch-show-header-line `((?s . ,subject))))
+ ((functionp notmuch-show-header-line)
+ (funcall notmuch-show-header-line subject))
+ (notmuch-show-header-line subject)))))
+
(defun notmuch-show--build-buffer (&optional state)
"Display messages matching the current buffer context.
@@ -1343,13 +1373,7 @@ If no messages match the query return NIL."
;; display changes.
(notmuch-show-mapc
(lambda () (notmuch-show-set-prop :orig-tags (notmuch-show-get-tags))))
- ;; Set the header line to the subject of the first message.
- (when notmuch-show-header-line
- (setq header-line-format
- (replace-regexp-in-string "%" "%%"
- (notmuch-sanitize
- (notmuch-show-strip-re
- (notmuch-show-get-subject))))))
+ (setq header-line-format (notmuch-show--header-line-format))
(run-hooks 'notmuch-show-hook)
(if state
(notmuch-show-apply-state state)
--
2.36.1
next prev parent reply other threads:[~2022-05-18 19:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-18 19:29 notmuch-show-header-line: allow format strings and functions jao
2022-05-18 19:29 ` jao [this message]
2022-05-26 23:51 ` [PATCH] emacs: " David Bremner
2022-05-27 0:26 ` Jose A Ortega Ruiz
2022-06-01 9:26 ` David Bremner
2022-06-01 9:56 ` Jose A Ortega Ruiz
2022-06-01 10:25 ` David Bremner
2022-06-01 10:34 ` Jose A Ortega Ruiz
2022-06-01 11:39 ` David Bremner
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220518192956.1440103-2-jao@gnu.org \
--to=jao@gnu.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* 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
https://yhetil.org/notmuch.git/
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).