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 1681C431FB6 for ; Fri, 13 Jul 2012 11:33:33 -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 eAEQvN5cmui0 for ; Fri, 13 Jul 2012 11:33:31 -0700 (PDT) Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU [18.9.25.13]) by olra.theworths.org (Postfix) with ESMTP id 504AE431FAE for ; Fri, 13 Jul 2012 11:33:31 -0700 (PDT) X-AuditID: 1209190d-b7fd56d000000933-a4-500069fa3b63 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP id EB.C9.02355.AF960005; Fri, 13 Jul 2012 14:33:30 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q6DIXUet026676; Fri, 13 Jul 2012 14:33:30 -0400 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6DIXS13018093 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 13 Jul 2012 14:33:29 -0400 (EDT) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1SpkgC-0008BS-Km; Fri, 13 Jul 2012 14:33:28 -0400 Date: Fri, 13 Jul 2012 14:33:28 -0400 From: Austin Clements To: Mark Walters Subject: Re: [PATCH 3/7] emacs: Update tags by rewriting the search result line in place Message-ID: <20120713183328.GA31182@mit.edu> References: <1342140319-19859-1-git-send-email-amdragon@mit.edu> <1342140319-19859-4-git-send-email-amdragon@mit.edu> <87a9z38ryo.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a9z38ryo.fsf@qmul.ac.uk> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkleLIzCtJLcpLzFFi42IRYrdT0f2dyRBgcJvNYvVcHovrN2cyOzB5 7Jx1l93j2apbzAFMUVw2Kak5mWWpRfp2CVwZJw5/Yi/4r1Hx58gd9gbGZ/JdjJwcEgImElea etggbDGJC/fWA9lcHEIC+xglJlzcwgjhbGCUeLX7MTuEc5JJYuGLv8wgLUICSxglTqwVBbFZ BFQlLi19zgpiswloSGzbv5wRxBYR0JG4fWgBO4jNLCAt8e13MxOILSwQJbHvyjWgORwcvEA1 7bulIOZPZZTou3KcBaSGV0BQ4uTMJywQvVoSN/69ZAKpB5mz/B8HSJgTaNWljklgH4gKqEhM ObmNbQKj0Cwk3bOQdM9C6F7AyLyKUTYlt0o3NzEzpzg1Wbc4OTEvL7VI10gvN7NELzWldBMj KKQ5JXl3ML47qHSIUYCDUYmHN9WfIUCINbGsuDL3EKMkB5OSKO/eVKAQX1J+SmVGYnFGfFFp TmrxIUYJDmYlEV4dY6Acb0piZVVqUT5MSpqDRUmc90rKTX8hgfTEktTs1NSC1CKYrAwHh5IE LzswdoUEi1LTUyvSMnNKENJMHJwgw3mAhpuC1PAWFyTmFmemQ+RPMSpKiUM0C4AkMkrz4Hph KecVozjQK8K8vzOAqniA6Qqu+xXQYCagwbN+/vMHGlySiJCSamCc3Rud2Wnn9dVYN1npTU1Q +Ht7t3iWxye5ko+6v6q0Et4UIXxglwC3SqvG5KzrvOdtWdf++lfrsv5llYoX/77HR9ZMEN5x RKIyeHa8yZs3G5d8NJr5kGG76drbnzOYxFb1Gii3iLFOU5EvyLMt4qtdYC2o9eC8XraH4c+1 EzpOPdpVyP97cpQSS3FGoqEWc1FxIgCG7WFDFAMAAA== Cc: notmuch@notmuchmail.org 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 18:33:33 -0000 Quoth Mark Walters on Jul 13 at 6:57 pm: > On Fri, 13 Jul 2012, Austin Clements wrote: > > 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." > > I think this comment reads a little awkwardly. Maybe "Replace the result > object of the current thread by RESULT and redraw it"? Better. I should also say that it's the thread at POS (or point). > > + (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)))))) > > I think this doesn't always do quite the right thing with multiline > results: the one that I can reproduce reliably is if you are on the > second line of the first result, and the first line of this result is > the first visible line in the window, and update it (eg by marking > unread) then the window scrolls so that the second line of the first > result is the first line visible in the window (ie the window scrolls up > one line) Nice catch! I really wish Emacs had a "replace text" function that did sane things with markers and the window position and such; without that anything I do is going to be finicky. I'll see if saving and restoring the window scroll position fixes this. > > + > > (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) > > > Perhaps a documentation line? along the lines of Insert RESULT in buffer > at POS or the end of buffer. Good idea. > Best wishes > > Mark > > > ;; 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)