[PATCH v3 1/3] emacs: Use pcase in notmuch-search-insert-field

Subject: [PATCH v3 1/3] emacs: Use pcase in notmuch-search-insert-field

Date: Sun, 21 Feb 2021 15:19:00 +0000

To: notmuch@notmuchmail.org

Cc: David Edmondson

From: David Edmondson


Rather than lots of string-equal calls, use the pcase macro.
---
 emacs/notmuch.el | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 6d37c623..b9cee19c 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -830,26 +830,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.30.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: