From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.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 +DUpJhS3gWJURQEAbAwnHQ (envelope-from ) for ; Mon, 16 May 2022 04:29:40 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id WCEVJhS3gWLpHgAAauVa8A (envelope-from ) for ; Mon, 16 May 2022 04:29:40 +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 ECB4C8E71 for ; Mon, 16 May 2022 04:29:39 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 67DE85F6DC; Mon, 16 May 2022 02:21:06 +0000 (UTC) Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by mail.notmuchmail.org (Postfix) with ESMTPS id 91F325F6B8 for ; Mon, 16 May 2022 02:21:03 +0000 (UTC) Received: from fencepost.gnu.org ([2001:470:142:3::e]:60304) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqQM2-0007YU-8V; Sun, 15 May 2022 22:21:02 -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=8rE3cTlTZF1FcpwyRa7xHqc60rR0/rpq5nPOvqTr6jQ=; b=OUFAnB6AyhEcz1ExHCxz u9YwRI/SsEhhUYQFrKncIEetrPGpRFTSlKj33TtM0pVGd+NJp8ImmPogseGRN2y1FykXXZQAzvZSy dkoG87OHZYaBNIBrD+OpG2oG4Moeb4d2/TeIYTOS2eqrUVcOPGLA8cJy3VCvn/oY1Vk/cnDfB9gWO nAUWGSW9jVUY4w2U9NWIdWfivSrNDGiq17r3hn0AEwzY01FNk/piQ6bvj//OnT0SNhSuN2rukK/tA NrOx6WkPaIRnkxPFqAIT3KUIPtSUlx49TCyKQ9zB1P/43wfMHTNvGePjzOZks5mdgcW89x3Jd9KX9 5+2XooZlZ3TYAQ==; Received: from cpc103048-sgyl39-2-0-cust502.18-2.cable.virginm.net ([92.233.85.247]:39226 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 1nqQM1-0007Pr-RO; Sun, 15 May 2022 22:21:02 -0400 From: jao To: notmuch@notmuchmail.org Subject: [PATCH v2 1/1] emacs: notmuch-show-header-line: allow format strings and functions Date: Mon, 16 May 2022 03:20:39 +0100 Message-Id: <20220516022039.551596-2-jao@gnu.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516022039.551596-1-jao@gnu.org> References: <20220516022039.551596-1-jao@gnu.org> MIME-Version: 1.0 Message-ID-Hash: YUY32MM3CYSWVENRJSCKJVW5RWJTDYDY X-Message-ID-Hash: YUY32MM3CYSWVENRJSCKJVW5RWJTDYDY 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=1652668180; 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=J8RZV1aKjqj66h8rW6qAquOSKzO0jHvGoq3ApOOTeMQ=; b=bMbRl3rImj95j+O8ilr4lbQgT3p37CBgALHzxPpCYBuj3wMfAUqFSUd0CMjb/VZ2DaeR0s kjQM3DjgS/6XeSj3xn7RE//cQPX9ExrU2jlbmOcog2KcKpCcs7cauw4TyN8+hych+gclG4 lT+it/CVVh2x0epv+5O2/TPRlEwgRU8e3wxWn8Tgiwh0l9yjNvq++3lFWhoqIrRvkTopJX PNM+2vHiq0ZwC6GyjtH/6FO6BM3jkw/ZYTYJVhRcTVyFj/Wnfk+V56GLL1M8zFC933lxwj b0KUGwhL6lkKxls/Y06rsecxGXiIHi/j7pDHPuA4gsRIYIeWNuJ8FzRSxe8oHQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1652668180; a=rsa-sha256; cv=none; b=cxAU0uiz5wjLPfWolAGm7a8XQsF1EmzH/0Xnx2EUNjxmeto4uMHJT8rmIeWPViZmg3RfII OAena5Qv2zS78SPM4o0oDN/R6Sb8cVnKo5hPn6XhLVbh1gRHgp7EEBAg3I9bmFbjeHMBOO yg7tMRuQt8w8QvDtcn60foC0JtJtX/TLJIaMFO4ObhX/MfpWVwGXjiTgUnmE2jy2l4L8S6 JLOTYDvcQt5LPFr7CB7qQUTZv4w8fIqfa3HUNIDx0282VtZwXMFYEQuTGuALI54xY6APoB 01huDibrbNexZKjbheJRQ2vLJo8+pIKTZF/HD8vIVP8UdR4T3P+2HV6B1Ws1XA== 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=OUFAnB6A; 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.34 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=OUFAnB6A; 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: ECB4C8E71 X-Spam-Score: 7.34 X-Migadu-Scanner: scn0.migadu.com X-TUID: yeB/72igBSM6 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 | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 7c1f02c9..79599480 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 @@ -1351,11 +1369,16 @@ If no messages match the query return NIL." (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)))))) + (let* ((s (replace-regexp-in-string "%" "%%" + (notmuch-sanitize + (notmuch-show-strip-re + (notmuch-show-get-subject))))) + (h (cond ((stringp notmuch-show-header-line) + (format-spec notmuch-show-header-line `((?s . ,s)))) + ((functionp notmuch-show-header-line) + (funcall notmuch-show-header-line s)) + (notmuch-show-header-line s)))) + (setq header-line-format h))) (run-hooks 'notmuch-show-hook) (if state (notmuch-show-apply-state state) -- 2.36.1