From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id gPZ0LW3g/V+1OwAA0tVLHw (envelope-from ) for ; Tue, 12 Jan 2021 17:46:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id kFtZKW3g/V9TcgAAbx9fmQ (envelope-from ) for ; Tue, 12 Jan 2021 17:46:21 +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 494889401C0 for ; Tue, 12 Jan 2021 17:46:21 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id A991E29EF2; Tue, 12 Jan 2021 12:46:05 -0500 (EST) Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by mail.notmuchmail.org (Postfix) with ESMTPS id B59E729DCB for ; Tue, 12 Jan 2021 12:46:01 -0500 (EST) Received: by mail-wr1-x436.google.com with SMTP id c5so3409173wrp.6 for ; Tue, 12 Jan 2021 09:46:01 -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=ymlfDSmpdKeuT4Y+AEbTMrxtXTmmHjZ0W2P05tw9DTEcrqSxrqdbriUUQOctafbXUy s+B1ezbmIU4ldrN1fq/qF/CpNijGgHQpVd7/VZvG3eIXnfoH0eGk1Yz3jnFZhRNNBvqy JIHxsRiF24awSdEkfYr+NVfj5QLQh7o+dByU8Dj40ESIuct6hS0SAu19nWDcm7F2yXb8 a3ipXoDMGZLLnQ5+Wqe3HjPDnKw84IzSXPSFNOP52TuQzoYgs3ep87+aNhpRXLffQpqy TeM+LyL+zP9iQlVJlp/t0BMWRrvoB9iKBA3tN+rD83ag/YYRgwv0VX/Tqq0pySqdp0iW K/oQ== 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=nRSpSL9xdCFeXe27+DU0nR2E39ubY8WYe2lIMAMu81drQm/de8JqZ+1uzO5PxvJHWP mQFbfrCaj4vvDniajn9VDwMLrPIVhznjgF/5kX/l0rN9ZP3EUXMW9D7rAfVqfZMBTtTX fKgLJnwY6wgIfmJNcT2cRilFdhVxjoMTbgqS8eNYxA79o5kTp5hx0T4mN2Fs5+k6cRWt O0vxeU4BUIsZYYzk8P+YTLsPwL0BuacDxEqle2wd/3hTHHPEUSKVMZb/SZ6xgEW+IebF VpSxGzYyA5n6ZU93g25TZbpsyb+eEc04ro11XbeKkgB7niRrMBhspqSzKondvI6tQGoT fVDg== X-Gm-Message-State: AOAM531UanXF5YrWsXRumw8RlUx89zSA02nOqTp4Z5iH/0ljvXGvcd2H u2G+zM6cQ5bKF0O+8gw+P9UNvg== X-Google-Smtp-Source: ABdhPJze+ShOfXvVExT7dF09jp0TeOF4dgvaA4RmT5aMZH8lWcTcJOQZ5rPQnRy4kJtaoX2UqgWuMQ== X-Received: by 2002:adf:9b91:: with SMTP id d17mr29556wrc.32.1610473560607; Tue, 12 Jan 2021 09:46:00 -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 h5sm6336930wrp.56.2021.01.12.09.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 09:46:00 -0800 (PST) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 6c0a8e15; Tue, 12 Jan 2021 17:45:58 +0000 (UTC) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v2 2/3] emacs: Allow functions in notmuch-search-result-format Date: Tue, 12 Jan 2021 17:45:56 +0000 Message-Id: <20210112174557.2229802-3-dme@dme.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210112174557.2229802-1-dme@dme.org> References: <20210112174557.2229802-1-dme@dme.org> MIME-Version: 1.0 Message-ID-Hash: XYG4HP3SXGNV7OSLNDF2KVMOP4UVAM7Q X-Message-ID-Hash: XYG4HP3SXGNV7OSLNDF2KVMOP4UVAM7Q 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.05 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=dme-org.20150623.gappssmtp.com header.s=20150623 header.b=ymlfDSmp; 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: 494889401C0 X-Spam-Score: 0.05 X-Migadu-Scanner: scn1.migadu.com X-TUID: a3hz1Uk+nRfC 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