--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 9510A6DE1B8C\r
+ for <notmuch@notmuchmail.org>; Sun, 5 Apr 2015 16:02:13 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.545\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.545 tagged_above=-999 required=5 tests=[AWL=0.535, \r
+ T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id r4w-LzeliZbN for <notmuch@notmuchmail.org>;\r
+ Sun, 5 Apr 2015 16:02:11 -0700 (PDT)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+ [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 610DA6DE1B9D\r
+ for <notmuch@notmuchmail.org>; Sun, 5 Apr 2015 16:02:09 -0700 (PDT)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+ 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1YetXj-0002p8-NY; Sun, 05 Apr 2015 23:01:27 +0000\r
+Received: (nullmailer pid 2255 invoked by uid 1000); Sun, 05 Apr 2015\r
+ 22:59:25 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP2 10/12] emacs: convert notmuch-search to format-version 3\r
+Date: Mon, 6 Apr 2015 07:59:12 +0900\r
+Message-Id: <1428274754-1698-11-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1428274754-1698-1-git-send-email-david@tethera.net>\r
+References: <1428274754-1698-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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: Sun, 05 Apr 2015 23:02:13 -0000\r
+\r
+XXX this checks every result to see if it is metadata. This might or\r
+ might not be innefficient\r
+\r
+XXX This ignores the actual metadata from the query. Should it do\r
+ something useful?\r
+---\r
+ emacs/notmuch-query.el | 5 +++++\r
+ emacs/notmuch.el | 15 ++++++++-------\r
+ test/T310-emacs.sh | 2 +-\r
+ 3 files changed, 14 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el\r
+index d1daffc..bfef22c 100644\r
+--- a/emacs/notmuch-query.el\r
++++ b/emacs/notmuch-query.el\r
+@@ -34,6 +34,11 @@ is a possibly empty forest of replies.\r
+ (setq args (append args search-terms))\r
+ (apply #'notmuch-call-notmuch-sexp args)))\r
+ \r
++\r
++(defun notmuch-query-metadata-p (result)\r
++ "Determine if the result is a \"metadata\" object (format-version 3)"\r
++ (plist-get result :query_type))\r
++\r
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
+ ;; Mapping functions across collections of messages.\r
+ \r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index ab00454..87caee4 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -793,12 +793,13 @@ non-authors is found, assume that all of the authors match."\r
+ \r
+ This is only called when a result is first inserted so it also\r
+ sets the :orig-tag property."\r
+- (let ((new-result (plist-put result :orig-tags (plist-get result :tags)))\r
+- (pos (point-max)))\r
+- (notmuch-search-show-result new-result pos)\r
+- (when (string= (plist-get result :thread) notmuch-search-target-thread)\r
+- (setq notmuch-search-target-thread "found")\r
+- (goto-char pos))))\r
++ (unless (notmuch-query-metadata-p result)\r
++ (let ((new-result (plist-put result :orig-tags (plist-get result :tags)))\r
++ (pos (point-max)))\r
++ (notmuch-search-show-result new-result pos)\r
++ (when (string= (plist-get result :thread) notmuch-search-target-thread)\r
++ (setq notmuch-search-target-thread "found")\r
++ (goto-char pos)))))\r
+ \r
+ (defun notmuch-search-process-filter (proc string)\r
+ "Process and filter the output of \"notmuch search\""\r
+@@ -935,7 +936,7 @@ the configured default sort order."\r
+ (save-excursion\r
+ (let ((proc (notmuch-start-notmuch\r
+ "notmuch-search" buffer #'notmuch-search-process-sentinel\r
+- "search" "--format=sexp" "--format-version=2"\r
++ "search" "--format=sexp" "--format-version=3"\r
+ (if oldest-first\r
+ "--sort=oldest-first"\r
+ "--sort=newest-first")\r
+diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh\r
+index d72799b..f460923 100755\r
+--- a/test/T310-emacs.sh\r
++++ b/test/T310-emacs.sh\r
+@@ -897,7 +897,7 @@ YYY/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)\r
+ === ERROR ===\r
+ [XXX]\r
+ YYY/notmuch_fail exited with status 1\r
+-command: YYY/notmuch_fail search --format\=sexp --format-version\=2 --sort\=newest-first tag\:inbox\r
++command: YYY/notmuch_fail search --format\=sexp --format-version\=3 --sort\=newest-first tag\:inbox\r
+ exit status: 1"\r
+ \r
+ test_begin_subtest "Search handles subprocess warnings"\r
+-- \r
+2.1.4\r
+\r