From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oDMKJx1E91/7JwAA0tVLHw (envelope-from ) for ; Thu, 07 Jan 2021 17:25:49 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id mG3hIh1E919GagAAB5/wlQ (envelope-from ) for ; Thu, 07 Jan 2021 17:25:49 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 380B29403A9 for ; Thu, 7 Jan 2021 17:25:49 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 15D8A29DA7; Thu, 7 Jan 2021 12:25:36 -0500 (EST) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by mail.notmuchmail.org (Postfix) with ESMTPS id 13F7429D63 for ; Thu, 7 Jan 2021 12:25:32 -0500 (EST) Received: by mail-wr1-x42c.google.com with SMTP id t30so6443937wrb.0 for ; Thu, 07 Jan 2021 09:25:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dme-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o7J0Pq31pjPCUwBoBI2phICdsLi8dH6sUsvqGnny8rA=; b=TsyS6/5J8mM2Px0tsP3SW8OFkt/Oog9VGlUEL86DnTCXSzzLhRHFNFAxhxU9nrtXRi kU2qe/Ug1J7SXnaOqZvuDwQWcvdWorSCcDoMtcsRHurogXYHXKMC4ES4jNKRA2O6cVoS 6f+OkuAD2XXgMotskfe1PghuHv4SgDamQkk5OTO7lbGyST3IsSfCNDf75up85vGP45uI clJJrV0GVhOdDY+MMBXhFrnD/JxigJeizZTHFgX6lZ3ItEiai7d/7CaK8mNTHDkCdJq8 +ubNw8e0NOnbxQzzJq35cl1X8qg6YBfVjGrdBPwQ4LvYrCCLNZ59Lzl5boGFpa8qwcxH 1hvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o7J0Pq31pjPCUwBoBI2phICdsLi8dH6sUsvqGnny8rA=; b=CnPACsVb2YCRQFa2WQDnJSrMpojVqusq9AYCkL3jCvZyoWQk5cHAyduP6pZZ4vk3me VZlK+oCnvsO7sNCTyeIgCJxUAtSEhcw5erSiIRDFKJhuLYjJ51JqxuIqbbfKDffOgnrG 8XSDYNM2IwNWFpcK4PjfRzbq0lCfa1m0ddDG0MlDi+kVdML/mIdtVagE8WsfmWvoCfCp B6hK75COIr1zzgKzhN0ZcYHOMJ8vk9F86rgr6CKTs/5p7lCXwBHJbMCdyUhAjndqaxIz qFFxQ6FT6FdwBb/0PmlrmMe7G9nv0IE2ne33zDNZg98rqL32UQVW7gGgV2jInkRswAUN 4ItQ== X-Gm-Message-State: AOAM5337rUoWFRlT4tX2yqH2l3W67GPXpKtdJtm6nbqJfcowupAaaNSP T1agu4k0g1jMzHKRxbcajv7CZ0SyyPv3WSxh X-Google-Smtp-Source: ABdhPJx0KVEirPOwXaNXSdDQpVQrXTJc7PPf1cQKoUwAGv8g4X7ukEGW8f7WJ2tfYLPPpXMubcCJrQ== X-Received: by 2002:adf:fdce:: with SMTP id i14mr10051335wrs.58.1610040326825; Thu, 07 Jan 2021 09:25:26 -0800 (PST) Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net. [2001:8b0:bb71:7140:64::1]) by smtp.gmail.com with ESMTPSA id g78sm8257228wme.33.2021.01.07.09.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 09:25:26 -0800 (PST) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 850729b4; Thu, 7 Jan 2021 17:25:24 +0000 (UTC) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 2/2] emacs: Allow functions in notmuch-search-result-format Date: Thu, 7 Jan 2021 17:25:23 +0000 Message-Id: <20210107172523.369192-2-dme@dme.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210107172523.369192-1-dme@dme.org> References: <20210107172523.369192-1-dme@dme.org> MIME-Version: 1.0 Message-ID-Hash: NUB5QW4VPHKR5SEQAA2RUUJ3DTV6TVNM X-Message-ID-Hash: NUB5QW4VPHKR5SEQAA2RUUJ3DTV6TVNM X-MailFrom: dme@dme.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0 CC: David Edmondson X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 0.10 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=dme-org.20150623.gappssmtp.com header.s=20150623 header.b=TsyS6/5J; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 380B29403A9 X-Spam-Score: 0.10 X-Migadu-Scanner: scn0.migadu.com X-TUID: dXldjtTgl+r1 If the car of an element in notmuch-search-result-format is a function, insert the result of calling the function into the buffer. This allows a user to generate custom fields in the output of a search result. For example, with: (defun -notmuch-result-flags (format-string result) (let ((tags-to-letters '(("flagged" . "!") ("unread" . "u") ("mine" . "m") ("sent" . "s") ("replied" . "r"))) (tags (plist-get result :tags))) (format format-string (mapconcat (lambda (t2l) (if (member (car t2l) tags) (cdr t2l) " ")) tags-to-letters "")))) (setq notmuch-search-result-format '((-notmuch-result-flags . "%s ") ("date" . "%12s ") ("count" . "%9s ") ("authors" . "%-30s ") ("subject" . "%s ") ("tags" . "(%s)"))) The first few characters on each line of the search result are used to show information about some significant tags associated with the thread. --- emacs/notmuch.el | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index efbf5bd0..92cb5202 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -824,26 +824,31 @@ non-authors is found, assume that all of the authors match." (insert padding)))) (defun notmuch-search-insert-field (field format-string result) - (pcase field - ("date" - (insert (propertize (format format-string (plist-get result :date_relative)) - 'face 'notmuch-search-date))) - ("count" - (insert (propertize (format format-string - (format "[%s/%s]" (plist-get result :matched) - (plist-get result :total))) - 'face 'notmuch-search-count))) - ("subject" - (insert (propertize (format format-string - (notmuch-sanitize (plist-get result :subject))) - 'face 'notmuch-search-subject))) - ("authors" - (notmuch-search-insert-authors format-string - (notmuch-sanitize (plist-get result :authors)))) - ("tags" - (let ((tags (plist-get result :tags)) - (orig-tags (plist-get result :orig-tags))) - (insert (format format-string (notmuch-tag-format-tags tags orig-tags))))))) + (cond + ((functionp field) + (insert (funcall field format-string result))) + + ((stringp field) + (pcase field + ("date" + (insert (propertize (format format-string (plist-get result :date_relative)) + 'face 'notmuch-search-date))) + ("count" + (insert (propertize (format format-string + (format "[%s/%s]" (plist-get result :matched) + (plist-get result :total))) + 'face 'notmuch-search-count))) + ("subject" + (insert (propertize (format format-string + (notmuch-sanitize (plist-get result :subject))) + 'face 'notmuch-search-subject))) + ("authors" + (notmuch-search-insert-authors format-string + (notmuch-sanitize (plist-get result :authors)))) + ("tags" + (let ((tags (plist-get result :tags)) + (orig-tags (plist-get result :orig-tags))) + (insert (format format-string (notmuch-tag-format-tags tags orig-tags))))))))) (defun notmuch-search-show-result (result pos) "Insert RESULT at POS." -- 2.29.2