[PATCH v3 5/9] emacs: Pass plist to `notmuch-search-show-result'
authorAustin Clements <amdragon@MIT.EDU>
Mon, 9 Jul 2012 21:42:38 +0000 (17:42 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:06 +0000 (09:48 -0800)
55/a03a3ec6345746da49e7de164fcdd4c641b995 [new file with mode: 0644]

diff --git a/55/a03a3ec6345746da49e7de164fcdd4c641b995 b/55/a03a3ec6345746da49e7de164fcdd4c641b995
new file mode 100644 (file)
index 0000000..7135326
--- /dev/null
@@ -0,0 +1,189 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 80C28431FAE\r
+       for <notmuch@notmuchmail.org>; Mon,  9 Jul 2012 14:42:55 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id QcVSfCSrLhB9 for <notmuch@notmuchmail.org>;\r
+       Mon,  9 Jul 2012 14:42:53 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
+       [18.7.68.37])\r
+       by olra.theworths.org (Postfix) with ESMTP id D5F5F429E30\r
+       for <notmuch@notmuchmail.org>; Mon,  9 Jul 2012 14:42:50 -0700 (PDT)\r
+X-AuditID: 12074425-b7f9b6d0000008c4-c7-4ffb505855a3\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id F2.E0.02244.8505BFF4; Mon,  9 Jul 2012 17:42:48 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q69LglAj003848; \r
+       Mon, 9 Jul 2012 17:42:47 -0400\r
+Received: from drake.dyndns.org (26-4-176.dynamic.csail.mit.edu [18.26.4.176])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q69LgiVe022686\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Mon, 9 Jul 2012 17:42:45 -0400 (EDT)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1SoLjA-0004g0-1C; Mon, 09 Jul 2012 17:42:44 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 5/9] emacs: Pass plist to `notmuch-search-show-result'\r
+Date: Mon,  9 Jul 2012 17:42:38 -0400\r
+Message-Id: <1341870162-17782-6-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1341870162-17782-1-git-send-email-amdragon@mit.edu>\r
+References: <1341354059-29396-1-git-send-email-amdragon@mit.edu>\r
+       <1341870162-17782-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFrrEIsWRmVeSWpSXmKPExsUixG6nohsR8NvfYGu7nsXquTwW12/OZLZ4\r
+       s3IeqwOzx85Zd9k9Dn9dyOLxbNUt5gDmKC6blNSczLLUIn27BK6MPTtWMBYc1qxomdHM1MC4\r
+       UbGLkZNDQsBE4tOfb4wQtpjEhXvr2boYuTiEBPYxSny4tYcFwlnPKNE+4SYrhHOSSeLjlyWM\r
+       EM5cRonl94+zgfSzCWhIbNu/HGyWiIC0xM67s1lBbGaBOIktU/4DxTk4hAU8JRbskgcJswio\r
+       Ssw42MoMYvMKOEisPzyBCeIMeYmn9/vARnIKOErMubkDbKSQQLnE5xv/mCcw8i9gZFjFKJuS\r
+       W6Wbm5iZU5yarFucnJiXl1qka6GXm1mil5pSuokRHFwuqjsYJxxSOsQowMGoxMO7keW3vxBr\r
+       YllxZe4hRkkOJiVR3jxPoBBfUn5KZUZicUZ8UWlOavEhRgkOZiUR3luuQDnelMTKqtSifJiU\r
+       NAeLkjjvjZSb/kIC6YklqdmpqQWpRTBZGQ4OJQneaf5AjYJFqempFWmZOSUIaSYOTpDhPEDD\r
+       J4DU8BYXJOYWZ6ZD5E8x6nKse3PkBqMQS15+XqqUOO9kkCIBkKKM0jy4ObCk8IpRHOgtYd4i\r
+       kCoeYEKBm/QKaAkT0JL2nl8gS0oSEVJSDYzFZmliZR7G71b4O7oeL85gsXv80er+inqbbsMV\r
+       ijpsktc2b5usV5EVtPCCRtwBV96+nh9Pb/yY7Hjny4tEgd+1HM2f58zvOZDjv6bkwXHGR9tv\r
+       8zuf1OV+bLVprfaxwm7B+m8Xk4LzIlIUM6pt+Hg0jd5yZvGemrlDLnGlxUqDwItNF7LyRJVY\r
+       ijMSDbWYi4oTAd18xl/lAgAA\r
+Cc: tomi.ollila@iki.fi\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 09 Jul 2012 21:42:56 -0000\r
+\r
+Rather than passing lots of arguments and then further passing those\r
+to `notmuch-search-insert-field', pass a plist containing all of the\r
+search result information.  This plist is compatible with the JSON\r
+format search results.\r
+---\r
+ emacs/notmuch.el |   65 +++++++++++++++++++++++++++++++-----------------------\r
+ 1 file changed, 38 insertions(+), 27 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 5bf01ca..dfeaf35 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -707,42 +707,47 @@ non-authors is found, assume that all of the authors match."\r
+         (overlay-put overlay 'isearch-open-invisible #'delete-overlay)))\r
+       (insert padding))))\r
+ \r
+-(defun notmuch-search-insert-field (field format-string date count authors subject tags)\r
++(defun notmuch-search-insert-field (field format-string result)\r
+   (cond\r
+    ((string-equal field "date")\r
+-    (insert (propertize (format format-string date)\r
++    (insert (propertize (format format-string (plist-get result :date_relative))\r
+                       'face 'notmuch-search-date)))\r
+    ((string-equal field "count")\r
+-    (insert (propertize (format format-string count)\r
++    (insert (propertize (format format-string\r
++                              (format "[%s/%s]" (plist-get result :matched)\r
++                                      (plist-get result :total)))\r
+                       'face 'notmuch-search-count)))\r
+    ((string-equal field "subject")\r
+-    (insert (propertize (format format-string subject)\r
++    (insert (propertize (format format-string (plist-get result :subject))\r
+                       'face 'notmuch-search-subject)))\r
+ \r
+    ((string-equal field "authors")\r
+-    (notmuch-search-insert-authors format-string authors))\r
++    (notmuch-search-insert-authors format-string (plist-get result :authors)))\r
+ \r
+    ((string-equal field "tags")\r
+     ;; Ignore format-string here because notmuch-search-set-tags\r
+     ;; depends on the format of this\r
+-    (insert (concat "(" (propertize tags 'font-lock-face 'notmuch-tag-face) ")")))))\r
++    (insert (concat "(" (propertize\r
++                       (mapconcat 'identity (plist-get result :tags) " ")\r
++                       'font-lock-face 'notmuch-tag-face) ")")))))\r
+ \r
+-(defun notmuch-search-show-result (thread-id date count authors subject tags)\r
++(defun notmuch-search-show-result (result)\r
+   ;; Ignore excluded matches\r
+-  (unless (eq (aref count 1) ?0)\r
+-    (let ((beg (point-max))\r
+-        (tags-str (mapconcat 'identity tags " ")))\r
++  (unless (= (plist-get result :matched) 0)\r
++    (let ((beg (point-max)))\r
+       (save-excursion\r
+       (goto-char beg)\r
+       (dolist (spec notmuch-search-result-format)\r
+-        (notmuch-search-insert-field (car spec) (cdr spec)\r
+-                                     date count authors subject tags-str))\r
++        (notmuch-search-insert-field (car spec) (cdr spec) result))\r
+       (insert "\n")\r
+-      (notmuch-search-color-line beg (point) tags)\r
+-      (put-text-property beg (point) 'notmuch-search-thread-id thread-id)\r
+-      (put-text-property beg (point) 'notmuch-search-authors authors)\r
+-      (put-text-property beg (point) 'notmuch-search-subject subject))\r
+-      (when (string= thread-id notmuch-search-target-thread)\r
++      (notmuch-search-color-line beg (point) (plist-get result :tags))\r
++      (put-text-property beg (point) 'notmuch-search-thread-id\r
++                         (concat "thread:" (plist-get result :thread)))\r
++      (put-text-property beg (point) 'notmuch-search-authors\r
++                         (plist-get result :authors))\r
++      (put-text-property beg (point) 'notmuch-search-subject\r
++                         (plist-get result :subject)))\r
++      (when (string= (plist-get result :thread) notmuch-search-target-thread)\r
+       (setq notmuch-search-target-thread "found")\r
+       (goto-char beg)))))\r
+ \r
+@@ -766,18 +771,24 @@ non-authors is found, assume that all of the authors match."\r
+             (while more\r
+               (while (and (< line (length string)) (= (elt string line) ?\n))\r
+                 (setq line (1+ line)))\r
+-              (if (string-match "^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" string line)\r
++              (if (string-match "^thread:\\([0-9A-Fa-f]*\\) \\([^][]*\\) \\[\\([0-9]*\\)/\\([0-9]*\\)\\] \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" string line)\r
+                   (let* ((thread-id (match-string 1 string))\r
+-                         (date (match-string 2 string))\r
+-                         (count (match-string 3 string))\r
+-                         (authors (match-string 4 string))\r
+-                         (subject (match-string 5 string))\r
+-                         (tags (match-string 6 string))\r
+-                         (tag-list (if tags (save-match-data (split-string tags)))))\r
+-                    (if (/= (match-beginning 1) line)\r
++                         (tags-str (match-string 7 string))\r
++                         (result (list :thread thread-id\r
++                                       :date_relative (match-string 2 string)\r
++                                       :matched (string-to-number\r
++                                                 (match-string 3 string))\r
++                                       :total (string-to-number\r
++                                               (match-string 4 string))\r
++                                       :authors (match-string 5 string)\r
++                                       :subject (match-string 6 string)\r
++                                       :tags (if tags-str\r
++                                                 (save-match-data\r
++                                                   (split-string tags-str))))))\r
++                    (if (/= (match-beginning 0) line)\r
+                         (notmuch-search-show-error\r
+-                         (substring string line (match-beginning 1))))\r
+-                    (notmuch-search-show-result thread-id date count authors subject tag-list)\r
++                         (substring string line (match-beginning 0))))\r
++                    (notmuch-search-show-result result)\r
+                     (set 'line (match-end 0)))\r
+                 (set 'more nil)\r
+                 (while (and (< line (length string)) (= (elt string line) ?\n))\r
+-- \r
+1.7.10\r
+\r