--- /dev/null
+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 C540D431FC9\r
+ for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:21 -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 wq2tmDAbOKiL for <notmuch@notmuchmail.org>;\r
+ Sat, 21 Jul 2012 10:37:20 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
+ [18.7.68.36])\r
+ by olra.theworths.org (Postfix) with ESMTP id B9960431FBF\r
+ for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:19 -0700 (PDT)\r
+X-AuditID: 12074424-b7f2a6d0000008bf-76-500ae8ce4abd\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 36.3D.02239.EC8EA005; Sat, 21 Jul 2012 13:37:18 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q6LHbHdr018461; \r
+ Sat, 21 Jul 2012 13:37:17 -0400\r
+Received: from drake.dyndns.org\r
+ (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [209.6.116.242]) (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 q6LHbFs3008010\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Sat, 21 Jul 2012 13:37:16 -0400 (EDT)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1SsdcB-0001Zc-55; Sat, 21 Jul 2012 13:37:15 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 0/8] emacs: JSON-based search cleanups\r
+Date: Sat, 21 Jul 2012 13:37:04 -0400\r
+Message-Id: <1342892232-5659-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1341354059-29396-1-git-send-email-amdragon@mit.edu>\r
+References: <1341354059-29396-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFrrIIsWRmVeSWpSXmKPExsUixCmqrXvuBVeAwfaJIhZ79nlZrJ7LY3H9\r
+ 5kxmB2aPu6e5PHbOusvu8WzVLeYA5igum5TUnMyy1CJ9uwSujJfrWtgKWjQrzvZ+Zm5g/KLQ\r
+ xcjJISFgIrHi8VF2CFtM4sK99WxdjFwcQgL7GCXu3n7CBOFsYJS4enIllPOISaK1fREjhDOX\r
+ UWLG9YesIP1sAhoS2/YvZwSxRQSkJXbenQ0WZxawlPjeeg8sLgxk7944B8xmEVCVmL1/KpjN\r
+ K2AvserdfDaIO+Qlnt7vA7M5BRwlVtw8ywJiCwk4SGz70ME6gZF/ASPDKkbZlNwq3dzEzJzi\r
+ 1GTd4uTEvLzUIl1zvdzMEr3UlNJNjKDQYndR2cHYfEjpEKMAB6MSD6+lEleAEGtiWXFl7iFG\r
+ SQ4mJVHevvtAIb6k/JTKjMTijPii0pzU4kOMEhzMSiK8m04D5XhTEiurUovyYVLSHCxK4rzX\r
+ U276CwmkJ5akZqemFqQWwWRlODiUJHjdgTEkJFiUmp5akZaZU4KQZuLgBBnOAzQ8GKSGt7gg\r
+ Mbc4Mx0if4pRl+Paw1u3GIVY8vLzUqXEee1AigRAijJK8+DmwFLCK0ZxoLeEeQ1AqniA6QRu\r
+ 0iugJUxAS6SzwJaUJCKkpBoYhd/+l16aK1126qZE/kG5yxz1QZr5d+UkTu8UVH/H1jz1549l\r
+ L3zaHbKEWFW3qH/7GaJ/XH41x6WpP7j+nNTu+1C48/3vrZIhCTNV/DU3seU+OTyxeZuizy/f\r
+ CEm9ZQeWLZCKbyqwjv4pfT1QId7pwrFHcQvsmzyPHni35pH96YvXt21S8/wVrcRSnJFoqMVc\r
+ VJwIADDODqTkAgAA\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: Sat, 21 Jul 2012 17:37:22 -0000\r
+\r
+This version fixes several bugs found in the previous version. I\r
+replaced the insert-before-markers trick in\r
+notmuch-search-update-result with direct point manipulation. This\r
+fixes the problem with authors getting unhidden when a result is\r
+updated with point after the authors on the line (since it no longer\r
+deletes the region with the invisibility overlay). I also removed the\r
+scrolling hack (which was partially necessitated by\r
+insert-before-markers), so that archiving the last visible result will\r
+properly scroll the buffer instead of jumping point to the middle of\r
+the visible window. As a result, the window may scroll when updating\r
+a multiline result, however, it will scroll to show the entire result\r
+(unlike an earlier version where it scrolled to cut off the result\r
+because of an interaction with insert-before-markers). Finally, I\r
+fixed notmuch-search-last-thread so that it behaves like it did before\r
+when there are no results, rather than failing with an obscure error.\r
+\r
+I also updated the customize documentation and NEWS to indicate that\r
+multiline search results are considered experimental.\r
+\r
+Diff from v3:\r
+\r
+diff --git a/NEWS b/NEWS\r
+index 7b33f0d..7b1f36c 100644\r
+--- a/NEWS\r
++++ b/NEWS\r
+@@ -25,7 +25,7 @@ The formatting of tags in search results can now be customized\r
+ `notmuch-search-result-format` would usually break tagging from\r
+ search-mode. We no longer make assumptions about the format.\r
+ \r
+-Multi-line search result formats are now supported\r
++Experimental support for multi-line search result formats\r
+ \r
+ It is now possible to embed newlines in\r
+ `notmuch-search-result-format` to make individual search results\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index ec760dc..fd1836f 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -70,12 +70,12 @@\r
+ For example:\r
+ (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)\r
+ \(\"subject\" . \"%s\"\)\)\)\r
+-Line breaks are permitted in format strings. Note that a line\r
+-break at the end of an \"authors\" field will get elided if the\r
+-authors list is long; place it instead at the beginning of the\r
+-following field. To enter a line break when setting this\r
+-variable with setq, use \\n. To enter a line break in customize,\r
+-press \\[quoted-insert] C-j."\r
++Line breaks are permitted in format strings (though this is\r
++currently experimental). Note that a line break at the end of an\r
++\"authors\" field will get elided if the authors list is long;\r
++place it instead at the beginning of the following field. To\r
++enter a line break when setting this variable with setq, use \\n.\r
++To enter a line break in customize, press \\[quoted-insert] C-j."\r
+ :type '(alist :key-type (string) :value-type (string))\r
+ :group 'notmuch-search)\r
+ \r
+@@ -310,7 +310,8 @@ For a mouse binding, return nil."\r
+ (interactive)\r
+ (goto-char (point-max))\r
+ (forward-line -2)\r
+- (goto-char (notmuch-search-result-beginning)))\r
++ (let ((beg (notmuch-search-result-beginning)))\r
++ (when beg (goto-char beg))))\r
+ \r
+ (defun notmuch-search-first-thread ()\r
+ "Select the first thread in the search results."\r
+@@ -599,30 +600,31 @@ This function advances the next thread when finished."\r
+ \r
+ (defun notmuch-search-update-result (result &optional pos)\r
+ "Replace the result object of the thread at POS (or point) by\r
+-RESULT and redraw it."\r
++RESULT and redraw it.\r
++\r
++This will keep point in a reasonable location. However, if there\r
++are enclosing save-excursions and the saved point is in the\r
++result being updated, the point will be restored to the beginning\r
++of the result."\r
+ (let ((start (notmuch-search-result-beginning pos))\r
+ (end (notmuch-search-result-end pos))\r
+ (init-point (point))\r
+- (init-start (window-start))\r
+ (inhibit-read-only t))\r
+ ;; Delete the current thread\r
+ (delete-region start end)\r
+ ;; Insert the updated thread\r
+ (notmuch-search-show-result result start)\r
+- ;; There may have been markers pointing into the text we just\r
+- ;; replaced. For the most part, there's nothing we can do about\r
+- ;; this, but we can fix markers that were at point (which includes\r
+- ;; point itself and any save-excursions for which point hasn't\r
+- ;; moved) by re-inserting the text that should come before point\r
+- ;; before markers.\r
++ ;; If point was inside the old result, make an educated guess\r
++ ;; about where to place it now. Unfortunately, this won't work\r
++ ;; with save-excursion (or any other markers that would be nice to\r
++ ;; preserve, such as the window start), but there's nothing we can\r
++ ;; do about that without a way to retrieve markers in a region.\r
+ (when (and (>= init-point start) (<= init-point end))\r
+ (let* ((new-end (notmuch-search-result-end start))\r
+ (new-point (if (= init-point end)\r
+ new-end\r
+ (min init-point (- new-end 1)))))\r
+- (insert-before-markers (delete-and-extract-region start new-point))))\r
+- ;; We also may have shifted the window scroll. Fix it.\r
+- (set-window-start (selected-window) init-start)))\r
++ (goto-char new-point)))))\r
+ \r
+ (defun notmuch-search-process-sentinel (proc msg)\r
+ "Add a message to let user know when \"notmuch search\" exits"\r
+\r
+\r
+\r