--- /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 55961431FD6\r
+ for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:23 -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 SJekj+QhNwDA for <notmuch@notmuchmail.org>;\r
+ Sat, 21 Jul 2012 10:37:21 -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 2D468431FC3\r
+ for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:20 -0700 (PDT)\r
+X-AuditID: 12074424-b7f2a6d0000008bf-77-500ae8ce4d48\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 46.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-1.mit.edu (8.13.8/8.9.2) with ESMTP id q6LHbHDJ029419; \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 q6LHbFrj008015\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-0001Zi-9y; Sat, 21 Jul 2012 13:37:15 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 3/8] emacs: Update tags by rewriting the search result line\r
+ in place\r
+Date: Sat, 21 Jul 2012 13:37:07 -0400\r
+Message-Id: <1342892232-5659-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1342892232-5659-1-git-send-email-amdragon@mit.edu>\r
+References: <1341354059-29396-1-git-send-email-amdragon@mit.edu>\r
+ <1342892232-5659-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsUixCmqrHvuBVeAwYevkhZ79nlZrJ7LY3H9\r
+ 5kxmB2aPu6e5PHbOusvu8WzVLeYA5igum5TUnMyy1CJ9uwSujLsd/9gLnspVrP/0j7WB8bJE\r
+ FyMnh4SAicS0l4uZIWwxiQv31rN1MXJxCAnsY5SYvWEGM4SzgVHi+KvzUJlHTBLTWjeyQjhz\r
+ GSWab7exg/SzCWhIbNu/nBHEFhGQlth5dzYriM0skCbxvf0tWFxYIFyi5+cqsHoWAVWJ+08n\r
+ soHYvAL2EltP9rND3CEv8fR+H1icU8BB4tHZAywgtpBAmcTijsOMExj5FzAyrGKUTcmt0s1N\r
+ zMwpTk3WLU5OzMtLLdI118vNLNFLTSndxAgKLXYXlR2MzYeUDjEKcDAq8fBaKnEFCLEmlhVX\r
+ 5h5ilORgUhLl7bsPFOJLyk+pzEgszogvKs1JLT7EKMHBrCTCu+k0UI43JbGyKrUoHyYlzcGi\r
+ JM57PeWmv5BAemJJanZqakFqEUxWhoNDSYLXHRhDQoJFqempFWmZOSUIaSYOTpDhPEDDg0Fq\r
+ eIsLEnOLM9Mh8qcYFaXEee1AEgIgiYzSPLheWOy/YhQHekWY1wCkigeYNuC6XwENZgIaLJ0F\r
+ NrgkESEl1cCY+NTjXeZl7zf5Hds8DuSJnE9uMVYOmRAflMxqb8/l9m9+23yRddvXXfefsPLd\r
+ XM0LstePVpbcThG5bWtx7IFE5h6jSxy/WLc1vFG/d1RGo+fPMu+JvDyyop/b/rht+MPMc3bH\r
+ naSIT7mbpXq+hRlPnvXFul3D9e4DHq1ln2YG/DLewltpadmoxFKckWioxVxUnAgAGKRjldgC AAA=\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:23 -0000\r
+\r
+Now that we keep the full thread result object, we can refresh a\r
+result after any changes by simply deleting and reconstructing the\r
+result line from scratch.\r
+\r
+A convenient side-effect of this wholesale replacement is that search\r
+now re-applies notmuch-search-line-faces when tags change.\r
+---\r
+ emacs/notmuch.el | 61 +++++++++++++++++++++++++++++++++---------------------\r
+ 1 file changed, 37 insertions(+), 24 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 82c148d..6995482 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -509,28 +509,12 @@ and will also appear in a buffer named \"*Notmuch errors*\"."\r
+ (error (buffer-substring beg end))\r
+ ))))))\r
+ \r
+-(defun notmuch-search-set-tags (tags)\r
+- (save-excursion\r
+- (end-of-line)\r
+- (re-search-backward "(")\r
+- (forward-char)\r
+- (let ((beg (point))\r
+- (inhibit-read-only t))\r
+- (re-search-forward ")")\r
+- (backward-char)\r
+- (let ((end (point)))\r
+- (delete-region beg end)\r
+- (insert (propertize (mapconcat 'identity tags " ")\r
+- 'face 'notmuch-tag-face))))))\r
+-\r
+-(defun notmuch-search-get-tags ()\r
+- (save-excursion\r
+- (end-of-line)\r
+- (re-search-backward "(")\r
+- (let ((beg (+ (point) 1)))\r
+- (re-search-forward ")")\r
+- (let ((end (- (point) 1)))\r
+- (split-string (buffer-substring-no-properties beg end))))))\r
++(defun notmuch-search-set-tags (tags &optional pos)\r
++ (let ((new-result (plist-put (notmuch-search-get-result pos) :tags tags)))\r
++ (notmuch-search-update-result new-result pos)))\r
++\r
++(defun notmuch-search-get-tags (&optional pos)\r
++ (plist-get (notmuch-search-get-result pos) :tags))\r
+ \r
+ (defun notmuch-search-get-tags-region (beg end)\r
+ (save-excursion\r
+@@ -583,6 +567,34 @@ This function advances the next thread when finished."\r
+ (notmuch-search-tag '("-inbox"))\r
+ (notmuch-search-next-thread))\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
++\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
++ (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
++ ;; 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
++ (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
+ (let ((buffer (process-buffer proc))\r
+@@ -745,10 +757,11 @@ non-authors is found, assume that all of the authors match."\r
+ (mapconcat 'identity (plist-get result :tags) " ")\r
+ 'font-lock-face 'notmuch-tag-face) ")")))))\r
+ \r
+-(defun notmuch-search-show-result (result)\r
++(defun notmuch-search-show-result (result &optional pos)\r
++ "Insert RESULT at POS or the end of the buffer if POS is null."\r
+ ;; Ignore excluded matches\r
+ (unless (= (plist-get result :matched) 0)\r
+- (let ((beg (point-max)))\r
++ (let ((beg (or pos (point-max))))\r
+ (save-excursion\r
+ (goto-char beg)\r
+ (dolist (spec notmuch-search-result-format)\r
+-- \r
+1.7.10\r
+\r