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 6Fs4EBhE91+3PAAA0tVLHw (envelope-from ) for ; Thu, 07 Jan 2021 17:25:44 +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 mO8CDBhE918YTQAAbx9fmQ (envelope-from ) for ; Thu, 07 Jan 2021 17:25:44 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (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 D7ECD9403A9 for ; Thu, 7 Jan 2021 17:25:43 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id E989A29D6E; Thu, 7 Jan 2021 12:25:34 -0500 (EST) Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by mail.notmuchmail.org (Postfix) with ESMTPS id 115FA29C8B for ; Thu, 7 Jan 2021 12:25:32 -0500 (EST) Received: by mail-wr1-x42a.google.com with SMTP id d13so6362429wrc.13 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:mime-version :content-transfer-encoding; bh=MkZD1T7V+xLaPblcuodlRaoDFZ/8mlTLwDKMGZ/yDIY=; b=eZECVQw9eYAbh+iLJyBuiu9Eob9kfZp9TFxE1MR8JUYjzHD8+w6OiaqKKVn+PUTc/u +c5GUSCb2XewQe90ReqpbntqDk7/ZzhdcFBg29j1OEH2Ae+Kq0Zq9/DP15lAJpQlzkZk LdA+QTdLOW5nyT4yQaOSb609WUPU+5Kj/FelMG2Exs7tvwWv8BgTyJVCaEpHi66RfbfB IRQVZs9iK4V/w5tKkn33ofgRFIeaCx5KyvM9F0qHrTzdx6LWFzMenXoiTqc5KuvXOO8l 0m+8F/HxGYHZg53x6vw5utefhDHwY++0FqQegJA6e3KjxlLTV/erCFrk5KXenoUS6EQR xR5A== 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:mime-version :content-transfer-encoding; bh=MkZD1T7V+xLaPblcuodlRaoDFZ/8mlTLwDKMGZ/yDIY=; b=m+S/PHQJGWuW5gzk/tYpX2CZk3VuaDTDP3aNhOIFILBy7E7eIJqw2vZkfohq0er48o HnTSiDaqV/ObwgJvRqCb8vcvnlQAFg0xYQuPGDQXzbNsv0OFrF6zQgVP38At2AI35+mi TgFSkCMdibFfAcrCWR2wAaqAaLMyMk5tBnAyGdZPd3u1NlrPGhMYg9f5yxlQG+vPMSuV gB1ILHid9EVgJSSxpYwh61zrwNbO3B57HC7TWKVGG+LU6JbKkZva6U2YrBTRCM0wb+Ut VXKcCjH2WTOTLSPK+5DBsMISXvtKTa6Q3r0D9wgS0TEFy7un7GtJ1dBck5+Bq8C/F+i6 qTGw== X-Gm-Message-State: AOAM531ZQQ1btUTBBIalBCWAk6+rLq/SaY4X/+fkgiW1YW3/NJDTv4Bi AnuvmB8Nsw/9CXKA5hKguFS8o9AjiVOW+6/T X-Google-Smtp-Source: ABdhPJxd+yyZbY3pZAEJ/gij6W7XvS0MvnVw/0ZWXkrQ8ubRDdj3eAAvSB7o77o4xeXRXn8m38cA/Q== X-Received: by 2002:a5d:4bc5:: with SMTP id l5mr9967978wrt.15.1610040326100; 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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 09:25:25 -0800 (PST) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 5d96a840; Thu, 7 Jan 2021 17:25:24 +0000 (UTC) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 1/2] emacs: Use pcase in notmuch-search-insert-field Date: Thu, 7 Jan 2021 17:25:22 +0000 Message-Id: <20210107172523.369192-1-dme@dme.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Message-ID-Hash: YTFESUBGND43WDDOSA55JBH2VCYJQESW X-Message-ID-Hash: YTFESUBGND43WDDOSA55JBH2VCYJQESW 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.07 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=dme-org.20150623.gappssmtp.com header.s=20150623 header.b=eZECVQw9; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D7ECD9403A9 X-Spam-Score: -0.07 X-Migadu-Scanner: scn0.migadu.com X-TUID: 1LyG3Pw1dTKs Rather than lots of string-equal calls, use the pcase macro. --- emacs/notmuch.el | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 83bcee57..efbf5bd0 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -65,7 +65,9 @@ ;;; Code: -(eval-when-compile (require 'cl-lib)) +(eval-when-compile + (require 'cl-lib) + (require 'pcase)) (require 'mm-view) (require 'message) @@ -822,26 +824,26 @@ non-authors is found, assume that all of the authors match." (insert padding)))) (defun notmuch-search-insert-field (field format-string result) - (cond - ((string-equal field "date") - (insert (propertize (format format-string (plist-get result :date_relative)) - 'face 'notmuch-search-date))) - ((string-equal field "count") - (insert (propertize (format format-string - (format "[%s/%s]" (plist-get result :matched) - (plist-get result :total))) - 'face 'notmuch-search-count))) - ((string-equal field "subject") - (insert (propertize (format format-string - (notmuch-sanitize (plist-get result :subject))) - 'face 'notmuch-search-subject))) - ((string-equal field "authors") - (notmuch-search-insert-authors - format-string (notmuch-sanitize (plist-get result :authors)))) - ((string-equal field "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))))))) + (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