From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 55961431FD6 for ; Sat, 21 Jul 2012 10:37:23 -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 SJekj+QhNwDA for ; Sat, 21 Jul 2012 10:37:21 -0700 (PDT) Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU [18.7.68.36]) by olra.theworths.org (Postfix) with ESMTP id 2D468431FC3 for ; Sat, 21 Jul 2012 10:37:20 -0700 (PDT) X-AuditID: 12074424-b7f2a6d0000008bf-77-500ae8ce4d48 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP id 46.3D.02239.EC8EA005; Sat, 21 Jul 2012 13:37:18 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q6LHbHDJ029419; Sat, 21 Jul 2012 13:37:17 -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 q6LHbFrj008015 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 21 Jul 2012 13:37:16 -0400 (EDT) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1SsdcB-0001Zi-9y; Sat, 21 Jul 2012 13:37:15 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v4 3/8] emacs: Update tags by rewriting the search result line in place Date: Sat, 21 Jul 2012 13:37:07 -0400 Message-Id: <1342892232-5659-4-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1342892232-5659-1-git-send-email-amdragon@mit.edu> References: <1341354059-29396-1-git-send-email-amdragon@mit.edu> <1342892232-5659-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsUixCmqrHvuBVeAwYevkhZ79nlZrJ7LY3H9 5kxmB2aPu6e5PHbOusvu8WzVLeYA5igum5TUnMyy1CJ9uwSujLsd/9gLnspVrP/0j7WB8bJE FyMnh4SAicS0l4uZIWwxiQv31rN1MXJxCAnsY5SYvWEGM4SzgVHi+KvzUJlHTBLTWjeyQjhz GSWab7exg/SzCWhIbNu/nBHEFhGQlth5dzYriM0skCbxvf0tWFxYIFyi5+cqsHoWAVWJ+08n soHYvAL2EltP9rND3CEv8fR+H1icU8BB4tHZAywgtpBAmcTijsOMExj5FzAyrGKUTcmt0s1N zMwpTk3WLU5OzMtLLdI118vNLNFLTSndxAgKLXYXlR2MzYeUDjEKcDAq8fBaKnEFCLEmlhVX 5h5ilORgUhLl7bsPFOJLyk+pzEgszogvKs1JLT7EKMHBrCTCu+k0UI43JbGyKrUoHyYlzcGi JM57PeWmv5BAemJJanZqakFqEUxWhoNDSYLXHRhDQoJFqempFWmZOSUIaSYOTpDhPEDDg0Fq eIsLEnOLM9Mh8qcYFaXEee1AEgIgiYzSPLheWOy/YhQHekWY1wCkigeYNuC6XwENZgIaLJ0F NrgkESEl1cCY+NTjXeZl7zf5Hds8DuSJnE9uMVYOmRAflMxqb8/l9m9+23yRddvXXfefsPLd XM0LstePVpbcThG5bWtx7IFE5h6jSxy/WLc1vFG/d1RGo+fPMu+JvDyyop/b/rht+MPMc3bH naSIT7mbpXq+hRlPnvXFul3D9e4DHq1ln2YG/DLewltpadmoxFKckWioxVxUnAgAGKRjldgC AAA= 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: Sat, 21 Jul 2012 17:37:23 -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 | 61 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 82c148d..6995482 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,34 @@ This function advances the next thread when finished." (notmuch-search-tag '("-inbox")) (notmuch-search-next-thread)) +(defun notmuch-search-update-result (result &optional pos) + "Replace the result object of the thread at POS (or point) by +RESULT and redraw it. + +This will keep point in a reasonable location. However, if there +are enclosing save-excursions and the saved point is in the +result being updated, the point will be restored to the beginning +of the result." + (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) + ;; If point was inside the old result, make an educated guess + ;; about where to place it now. Unfortunately, this won't work + ;; with save-excursion (or any other markers that would be nice to + ;; preserve, such as the window start), but there's nothing we can + ;; do about that without a way to retrieve markers in a region. + (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))))) + (goto-char 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 +757,11 @@ 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) + "Insert RESULT at POS or the end of the buffer if POS is null." ;; 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