From: Austin Clements Date: Fri, 13 Jul 2012 00:45:15 +0000 (+2000) Subject: [PATCH 3/7] emacs: Update tags by rewriting the search result line in place X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=3eb60ad148e9968c522fb5e400b79e92bf3b645b;p=notmuch-archives.git [PATCH 3/7] emacs: Update tags by rewriting the search result line in place --- diff --git a/57/1897b08279ed8ad87d6813fa11ec33654a6a92 b/57/1897b08279ed8ad87d6813fa11ec33654a6a92 new file mode 100644 index 000000000..7bc846ff0 --- /dev/null +++ b/57/1897b08279ed8ad87d6813fa11ec33654a6a92 @@ -0,0 +1,168 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 18A2E41ED73 + for ; Thu, 12 Jul 2012 17:45:29 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id Qgfl8TpxqarU for ; + Thu, 12 Jul 2012 17:45:26 -0700 (PDT) +Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU + [18.7.68.35]) + by olra.theworths.org (Postfix) with ESMTP id 787C6429E47 + for ; Thu, 12 Jul 2012 17:45:26 -0700 (PDT) +X-AuditID: 12074423-b7f396d0000008f4-84-4fff6fa522f2 +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP + id 3E.8F.02292.5AF6FFF4; Thu, 12 Jul 2012 20:45:26 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q6D0jP3S011236; + Thu, 12 Jul 2012 20:45:25 -0400 +Received: from drake.dyndns.org + (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [209.6.116.242]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6D0jNAm010664 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 12 Jul 2012 20:45:24 -0400 (EDT) +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1SpU0Z-0005Rz-IB; Thu, 12 Jul 2012 20:45:23 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 3/7] emacs: Update tags by rewriting the search result line in + place +Date: Thu, 12 Jul 2012 20:45:15 -0400 +Message-Id: <1342140319-19859-4-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10 +In-Reply-To: <1342140319-19859-1-git-send-email-amdragon@mit.edu> +References: <1342140319-19859-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixCmqrbss/7+/wZUjzBbXb85kdmD0eLbq + FnMAYxSXTUpqTmZZapG+XQJXxo9PvewFX2UqHv5bwtrAOEe8i5GTQ0LAROLgrS5WCFtM4sK9 + 9WxdjFwcQgL7GCVebOxhhXA2MErsudgOlXnEJLHo/Gx2CGcuo8SWh5PYQPrZBDQktu1fzghi + iwhIS+y8OxuonYODWUBN4k+XCkhYWCBEYtPsg+wgYRYBVYmmI1wgYV4BB4k5vRdZIK6Ql3h6 + vw9sIqeAo8SGLxfArhMCqmk8NpN5AiP/AkaGVYyyKblVurmJmTnFqcm6xcmJeXmpRbpmermZ + JXqpKaWbGEFBw+6ivIPxz0GlQ4wCHIxKPLyLov/7C7EmlhVX5h5ilORgUhLldckGCvEl5adU + ZiQWZ8QXleakFh9ilOBgVhLhXWcPlONNSaysSi3Kh0lJc7AoifNeS7npLySQnliSmp2aWpBa + BJOV4eBQkuDlBEaHkGBRanpqRVpmTglCmomDE2Q4D9DwbXkgw4sLEnOLM9Mh8qcYFaXEeS+A + JARAEhmleXC9sKh+xSgO9Iow7xeQKh5gQoDrfgU0mAlo8Kyf/0AGlyQipKQaGFs1PBlTVmz7 + qbwtuOxIVMgsk/+e/o+PC7++fSjqjWl0tY9clIXz/deP+RRulTatTdrpP+HRra4pZizG+x/9 + D77xqXna66W8e872ckt7yNreV/z90OjV/AMGbcskX7wWU1z7aFL/3xmhbko7PtUpzsqJnOGS + qcUYk1wzI2OjYDKLTXZFYEvAZiWW4oxEQy3mouJEAHCKqtvFAgAA +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 13 Jul 2012 00:45:29 -0000 + +Now that we keep the full thread result object, we can refresh a +result after any changes by simply deleting and reconstructing the +result line from scratch. + +A convenient side-effect of this wholesale replacement is that search +now re-applies notmuch-search-line-faces when tags change. +--- + emacs/notmuch.el | 55 ++++++++++++++++++++++++++++++------------------------ + 1 file changed, 31 insertions(+), 24 deletions(-) + +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index 82c148d..2f83425 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -509,28 +509,12 @@ and will also appear in a buffer named \"*Notmuch errors*\"." + (error (buffer-substring beg end)) + )))))) + +-(defun notmuch-search-set-tags (tags) +- (save-excursion +- (end-of-line) +- (re-search-backward "(") +- (forward-char) +- (let ((beg (point)) +- (inhibit-read-only t)) +- (re-search-forward ")") +- (backward-char) +- (let ((end (point))) +- (delete-region beg end) +- (insert (propertize (mapconcat 'identity tags " ") +- 'face 'notmuch-tag-face)))))) +- +-(defun notmuch-search-get-tags () +- (save-excursion +- (end-of-line) +- (re-search-backward "(") +- (let ((beg (+ (point) 1))) +- (re-search-forward ")") +- (let ((end (- (point) 1))) +- (split-string (buffer-substring-no-properties beg end)))))) ++(defun notmuch-search-set-tags (tags &optional pos) ++ (let ((new-result (plist-put (notmuch-search-get-result pos) :tags tags))) ++ (notmuch-search-update-result new-result pos))) ++ ++(defun notmuch-search-get-tags (&optional pos) ++ (plist-get (notmuch-search-get-result pos) :tags)) + + (defun notmuch-search-get-tags-region (beg end) + (save-excursion +@@ -583,6 +567,29 @@ This function advances the next thread when finished." + (notmuch-search-tag '("-inbox")) + (notmuch-search-next-thread)) + ++(defun notmuch-search-update-result (result &optional pos) ++ "Update the result object of the current thread and redraw it." ++ (let ((start (notmuch-search-result-beginning pos)) ++ (end (notmuch-search-result-end pos)) ++ (init-point (point)) ++ (inhibit-read-only t)) ++ ;; Delete the current thread ++ (delete-region start end) ++ ;; Insert the updated thread ++ (notmuch-search-show-result result start) ++ ;; There may have been markers pointing into the text we just ++ ;; replaced. For the most part, there's nothing we can do about ++ ;; this, but we can fix markers that were at point (which includes ++ ;; point itself and any save-excursions for which point hasn't ++ ;; moved) by re-inserting the text that should come before point ++ ;; before markers. ++ (when (and (>= init-point start) (<= init-point end)) ++ (let* ((new-end (notmuch-search-result-end start)) ++ (new-point (if (= init-point end) ++ new-end ++ (min init-point (- new-end 1))))) ++ (insert-before-markers (delete-and-extract-region start new-point)))))) ++ + (defun notmuch-search-process-sentinel (proc msg) + "Add a message to let user know when \"notmuch search\" exits" + (let ((buffer (process-buffer proc)) +@@ -745,10 +752,10 @@ non-authors is found, assume that all of the authors match." + (mapconcat 'identity (plist-get result :tags) " ") + 'font-lock-face 'notmuch-tag-face) ")"))))) + +-(defun notmuch-search-show-result (result) ++(defun notmuch-search-show-result (result &optional pos) + ;; Ignore excluded matches + (unless (= (plist-get result :matched) 0) +- (let ((beg (point-max))) ++ (let ((beg (or pos (point-max)))) + (save-excursion + (goto-char beg) + (dolist (spec notmuch-search-result-format) +-- +1.7.10 +