From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id ACZ7IvU4l2LFcAEAbAwnHQ (envelope-from ) for ; Wed, 01 Jun 2022 12:01:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id ANN5IfU4l2KHggAAG6o9tA (envelope-from ) for ; Wed, 01 Jun 2022 12:01:25 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (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 4E4AD248BC for ; Wed, 1 Jun 2022 12:01:25 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 64D095F7B4; Wed, 1 Jun 2022 09:53:50 +0000 (UTC) Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by mail.notmuchmail.org (Postfix) with ESMTPS id 56F645F7AC for ; Wed, 1 Jun 2022 09:53:48 +0000 (UTC) Received: from fencepost.gnu.org ([2001:470:142:3::e]:58856) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwL2w-0003PI-Jb; Wed, 01 Jun 2022 05:53:46 -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=G6k1ZNyz0qcDpO7G7MDhtvUlrGa/+zdhmEx1ohIKoes=; b=kWZpAhOSb6BP0FYnIwEY 2bpcbqbh+iLND2thVjL8OCwwcdo7TUJblBbp7BI/DNGcAvYeA7knVd1yGQySc2NWLqklSmL1GobGK aDYAjiEv6YtribIc7R8uXqyIZibN3qkb89h5PWDgs1qtAIE2rqa2EhcrtRu0DAzVtchI+AA+uRkcQ bQiru4x88GbOX2U74iBjYJ5Dh76RbzzvxcL6Nk1PnIZCbYCXrXs0O7nHkcDX50OUsFgBPI141iMdW jOgkXmF89M8dIbx5SmwhONodlIweGsLjDulHEJYhTiYYIIvyICEtNTtgBEuMuRFa9YpwdjQd/zgUT SoRdyRMwgPd+Cg==; Received: from cpc103048-sgyl39-2-0-cust502.18-2.cable.virginm.net ([92.233.85.247]:59616 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 1nwL2w-0007xE-6r; Wed, 01 Jun 2022 05:53:46 -0400 From: jao To: notmuch@notmuchmail.org Subject: [PATCH v4 1/1] emacs: notmuch-show-header-line: allow format strings and functions Date: Wed, 1 Jun 2022 10:53:36 +0100 Message-Id: <20220601095336.1164738-2-jao@gnu.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220601095336.1164738-1-jao@gnu.org> References: <20220601095336.1164738-1-jao@gnu.org> MIME-Version: 1.0 Message-ID-Hash: SYOCZFZTEHKZCZ4UZAUM5JIVO6P7VDSS X-Message-ID-Hash: SYOCZFZTEHKZCZ4UZAUM5JIVO6P7VDSS 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=1654077685; 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=M8zWnPWZn/cs6GM24b64CURAXPWeCEgnxYAmB9paq9c=; b=grMaxb/rbom83G3vELWS+iP7mynvtFgie58lUMfjmQV9OZ+N69UF1+3UsqYXqz8ziEcYE1 5ep9DCOLPKrnpGbCwPSwjHbRpavk0w+hEugRoa0DIss0mtWpZnn8V0pWpjXqZ9htEhHuLN 4a2euN3/tgtACmdGiM1uodM1XJVyGX6WxLISL7AfKx5JRt9WN/Ai6MbMnNpAC1b/rBikuB dNlnRSOS7tRU3Bi5oBXPptaSZNaXhsjm3szh0VyScke71SojXJH71iZaMCe9EhrCawW8cu yYxEnRyQ4mevcAx4qVt8k+bZSjqHXhxbgKJRkQhED9RSoWecAJYXoOF6SS7lFA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1654077685; a=rsa-sha256; cv=none; b=cFTO+JE8hffzBmVy6Ime1tsdNNw7GdnFBYELq0gXQkpdsscSOb6xcJurg1mCLs7emt72lw YWWV8zoedZoMWMA5dRpChLrS6cOT8iGddzwDaEzqQY2FZjEkXpnO5x8+SSJn5JDUzyPTho 1SQab+BU5NLc3sQpCByAgNa43wt1p/uOC8PCeuzBuURd+RiO6lCsk/DByI3pe119+Zli9I j7DQHSxFB51T9iO/MXq5/9oLJvfIAbkfLZUFfGKic/1JiNn8qPstuKSr8EpuJQiAwnMsUd 0AgnIO8S61watjyMIeiNEzHX76Ncx3TdTveeXgiphdm9wE24IlfCzDR48bSRYA== 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=kWZpAhOS; 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 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 7.26 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=kWZpAhOS; 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 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 4E4AD248BC X-Spam-Score: 7.26 X-Migadu-Scanner: scn0.migadu.com X-TUID: uIfYuCMYelfH 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 | 46 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 69f6c845..51b916ea 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -85,8 +85,30 @@ 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, it will be called with +the subject as argument, and the return value will be used as the +header line format. Since the function is called with the +message buffer as the current buffer, it is also possible to +access any other properties of the message, using for instance +notmuch-show functions such as +`notmuch-show-get-message-properties'. + +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 +1335,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 +1377,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