From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id +CO0OYtLhWL8CQAAbAwnHQ (envelope-from ) for ; Wed, 18 May 2022 21:39:56 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 8H3BOYtLhWIoowAA9RJhRA (envelope-from ) for ; Wed, 18 May 2022 21:39:55 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4D3AF12F4 for ; Wed, 18 May 2022 21:39:55 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 4A9005F771; Wed, 18 May 2022 19:30:12 +0000 (UTC) Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by mail.notmuchmail.org (Postfix) with ESMTPS id DE4D05F767 for ; Wed, 18 May 2022 19:30:09 +0000 (UTC) Received: from fencepost.gnu.org ([2001:470:142:3::e]:38034) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nrPN1-0008SR-Gl; Wed, 18 May 2022 15:30:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=0WYyVxRSlVRzT64jd5wI2adaXMAtVgllH0MqpqKQK4g=; b=BbrcOvmqCBT7Tc7E0DSM 8NhqwLzuzYX4LVFGVe5EOU25G96TYM9eL1O+82JENjKGN5/OePWQeV88I9QGHuL06SA+4RWA1zsnF 5JybLscmsJeR++cA7TuaSCivwLvDLqnjAkWcnPWe+yHVmbwpfT1QwVMIwfDBdNFnaQsyazSGcn2kK +XdUadjfaXfiPlz34uC1qmIE7NOp1PaYdAfPUU9tV77q/D2LtAxPeQz0KIWFXdDXMOd3Q8KXSWB3h lRNOgZtBFhy7sv3jD6n1JHIL2JHX9wW4RyhLZNVwenXhQF/R6dCzpbGWQFFk/vGYXKsRckA2YwE8f 4TpSrEJvi/hKaw==; Received: from cpc103048-sgyl39-2-0-cust502.18-2.cable.virginm.net ([92.233.85.247]:39518 helo=rivendell.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nrPN0-0000UJ-Vq; Wed, 18 May 2022 15:30:07 -0400 From: jao To: notmuch@notmuchmail.org Subject: [PATCH] emacs: notmuch-show-header-line: allow format strings and functions Date: Wed, 18 May 2022 20:29:56 +0100 Message-Id: <20220518192956.1440103-2-jao@gnu.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518192956.1440103-1-jao@gnu.org> References: <20220518192956.1440103-1-jao@gnu.org> MIME-Version: 1.0 Message-ID-Hash: RUZ32NTAFVYSVWXQKNHVM6YC4SIOMNXF X-Message-ID-Hash: RUZ32NTAFVYSVWXQKNHVM6YC4SIOMNXF X-MailFrom: jao@gnu.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: jao X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1652902795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=DDHfrAIuF1DIUR7mTjKpF7sBwCD3ghe2KTE1pzjnQvE=; b=utBK8fi2KArMbK4b8QNQ0y7u26wCRMTzqBU0xaWGv74OaRoTnmLsIGQeS9bq0C32zUD5Rl 4e2RqUtklYtfsHePJa1SOZ4x4aGPlxnolwHqCtw8uK+I2uSEYoc9ibwaz/MoEACyoJZ0lw pQHr0nxqJcUPTIMnzXzCol40OcvY+gQl37pKzlEEFKSJidkAbzfRXJh2SPJ1gFJk+ZyRma JPUmKAAgPBn1JHekp/cFImfghfGKNhLWMtqyOI3O14aSatg56gfNd7Uv7VO27vpOWIu1zD qWC1tixyyY0RHQNN4TEJSIJaR7fTY254phKSmD96p1ES/17Nb1fC0lqZKoaAOw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1652902795; a=rsa-sha256; cv=none; b=iNptX5PbPdaCUbITe84veOr9CiIWwXLR8POOF3uKrtigNd+9XEh25KPRxMjBFfr/IfVBEN 5XrDNDWuC92rBO8k6P1cbqSVxertl/lfpdP29oedeg46tJhV7uOCdgjttw2NceClCvKpKm A27iChLulhI/3M0W8CrNsoAkefOqSLNg8ChaDJ4yIM2iHNO9TOWMuI/tS1Mj7K1liazV2d OIDHD1+AhA1EdTNczijfGrgL2mbHgdV9yYMkdpI0gu31k4FRoiEpbyiBnla8NYhKhKklU4 BG0FARa12oRBpGEy276x9pn3JeYpDazm9Szb1+ahxpc1UZwWQfKAYRwtJJrGLQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=BbrcOvmq; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gnu.org (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 7.63 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=BbrcOvmq; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gnu.org (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 4D3AF12F4 X-Spam-Score: 7.63 X-Migadu-Scanner: scn1.migadu.com X-TUID: 3Z0UWNnt4FQQ 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 --- 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