From 8841a958695ba672b32bb0c1f1fa83d1fbe1e30a Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sat, 14 Jul 2012 23:43:23 +2000 Subject: [PATCH] [PATCH v2 4/7] emacs: Use result text properties for search result iteration --- 36/f76e64f3b0ae3b15352ecae3aba546f746b59b | 175 ++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 36/f76e64f3b0ae3b15352ecae3aba546f746b59b diff --git a/36/f76e64f3b0ae3b15352ecae3aba546f746b59b b/36/f76e64f3b0ae3b15352ecae3aba546f746b59b new file mode 100644 index 000000000..d9ab0969b --- /dev/null +++ b/36/f76e64f3b0ae3b15352ecae3aba546f746b59b @@ -0,0 +1,175 @@ +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 016B841ED7D + for ; Fri, 13 Jul 2012 20:43:45 -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 U1+YxoQzYFiy for ; + Fri, 13 Jul 2012 20:43:42 -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 EC362421163 + for ; Fri, 13 Jul 2012 20:43:39 -0700 (PDT) +X-AuditID: 1209190d-b7fd56d000000933-f7-5000eaeb3535 +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP + id 75.89.02355.BEAE0005; Fri, 13 Jul 2012 23:43:39 -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 q6E3hcIW029858; + Fri, 13 Jul 2012 23:43:38 -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 q6E3hbqA021330 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Fri, 13 Jul 2012 23:43:38 -0400 (EDT) +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1SptGa-0000a2-Qa; Fri, 13 Jul 2012 23:43:36 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 4/7] emacs: Use result text properties for search result + iteration +Date: Fri, 13 Jul 2012 23:43:23 -0400 +Message-Id: <1342237406-32507-5-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10 +In-Reply-To: <1342237406-32507-1-git-send-email-amdragon@mit.edu> +References: <1342140319-19859-1-git-send-email-amdragon@mit.edu> + <1342237406-32507-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixCmqrPv6FUOAwZGPPBar5/JYXL85k9mB + yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgylgz4yRbwSGFigNTFrA2ME6S6mLk5JAQMJE4 + PHsNK4QtJnHh3nq2LkYuDiGBfYwSHV9msEM4GxglPr2dwwrhPGKS2NZ/A8qZyyixtPsKO0g/ + m4CGxLb9yxlBbBEBaYmdd2eDzWUWcJT4vH8RG4gtLBAq8fXCDDCbRUBVYmfnIbBeXgEHiWtN + i1gg7pCXeHq/D6yGE6i3rfc22EwhgXKJ69/WME1g5F/AyLCKUTYlt0o3NzEzpzg1Wbc4OTEv + L7VI10gvN7NELzWldBMjOJQkeXcwvjuodIhRgINRiYc31Z8hQIg1say4MvcQoyQHk5IoLy8w + EIX4kvJTKjMSizPii0pzUosPMUpwMCuJ8Jq3AeV4UxIrq1KL8mFS0hwsSuK8V1Ju+gsJpCeW + pGanphakFsFkZTg4lCR4hUGGChalpqdWpGXmlCCkmTg4QYbzAA2XBqnhLS5IzC3OTIfIn2JU + lBLnvfwSKCEAksgozYPrhcX6K0ZxoFeEeW1A2nmAaQKu+xXQYCagwbN+/vMHGlySiJCSamD0 + PtXabXji4lmX725RfCvZzEq1G82M4nOXqd7690A85qzVE9VJEkvta15mXrT0dO6M7D25qVPK + UODVVqnZlzMm6+/exmXwgNmP+WTvz5YYC17ZHy8F725tn1buvt5ioszzv4Wt8nfZDT6YPjHc + vmhFxiSLZQLPclbOiGe1LWld5f6qefuh5bxKLMUZiYZazEXFiQByvzDB0AIAAA== +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, 14 Jul 2012 03:43:45 -0000 + +This simplifies the traversal of regions of results and eliminates the +need for save-excursions (which tend to get in the way of maintaining +point when we make changes to the buffer). It also fixes some strange +corner cases in the old line-based code where results that bordered +the region but were not included in it could be affected by region +commands. Coincidentally, this also essentially enables multi-line +search result formats; the only remaining non-multi-line-capable +functions are notmuch-search-{next,previous}-thread, which are only +used interactively. +--- + emacs/notmuch.el | 61 ++++++++++++++++++++++++++++++------------------------ + 1 file changed, 34 insertions(+), 27 deletions(-) + +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index 8e1a769..92ba2c1 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -427,17 +427,33 @@ returns nil" + (next-single-property-change (or pos (point)) 'notmuch-search-result + nil (point-max)))) + ++(defmacro notmuch-search-do-results (beg end pos-sym &rest body) ++ "Invoke BODY for each result between BEG and END. ++ ++POS-SYM will be bound to the point at the beginning of the ++current result." ++ (declare (indent 3)) ++ (let ((end-sym (make-symbol "end")) ++ (first-sym (make-symbol "first"))) ++ `(let ((,pos-sym (notmuch-search-result-beginning ,beg)) ++ ;; End must be a marker in case body changes the text ++ (,end-sym (copy-marker ,end)) ++ ;; Make sure we examine one result, even if (= beg end) ++ (,first-sym t)) ++ ;; We have to be careful if the region extends beyond the ++ ;; results. In this case, pos could be null or there could be ++ ;; no result at pos. ++ (while (and ,pos-sym (or (< ,pos-sym ,end-sym) ,first-sym)) ++ (when (notmuch-search-get-result ,pos-sym) ++ ,@body) ++ (setq ,pos-sym (notmuch-search-result-end ,pos-sym) ++ ,first-sym nil))))) ++ + (defun notmuch-search-properties-in-region (property beg end) +- (save-excursion +- (let ((output nil) +- (last-line (line-number-at-pos end)) +- (max-line (- (line-number-at-pos (point-max)) 2))) +- (goto-char beg) +- (beginning-of-line) +- (while (<= (line-number-at-pos) (min last-line max-line)) +- (setq output (cons (get-text-property (point) property) output)) +- (forward-line 1)) +- output))) ++ (let (output) ++ (notmuch-search-do-results beg end pos ++ (push (get-text-property pos property) output)) ++ output)) + + (defun notmuch-search-find-thread-id () + "Return the thread for the current thread" +@@ -517,28 +533,19 @@ and will also appear in a buffer named \"*Notmuch errors*\"." + (plist-get (notmuch-search-get-result pos) :tags)) + + (defun notmuch-search-get-tags-region (beg end) +- (save-excursion +- (let ((output nil) +- (last-line (line-number-at-pos end)) +- (max-line (- (line-number-at-pos (point-max)) 2))) +- (goto-char beg) +- (while (<= (line-number-at-pos) (min last-line max-line)) +- (setq output (append output (notmuch-search-get-tags))) +- (forward-line 1)) +- output))) ++ (let (output) ++ (notmuch-search-do-results beg end pos ++ (setq output (append output (notmuch-search-get-tags pos)))) ++ output)) + + (defun notmuch-search-tag-region (beg end &optional tag-changes) + "Change tags for threads in the given region." + (let ((search-string (notmuch-search-find-thread-id-region-search beg end))) + (setq tag-changes (funcall 'notmuch-tag search-string tag-changes)) +- (save-excursion +- (let ((last-line (line-number-at-pos end)) +- (max-line (- (line-number-at-pos (point-max)) 2))) +- (goto-char beg) +- (while (<= (line-number-at-pos) (min last-line max-line)) +- (notmuch-search-set-tags +- (notmuch-update-tags (notmuch-search-get-tags) tag-changes)) +- (forward-line)))))) ++ (notmuch-search-do-results beg end pos ++ (notmuch-search-set-tags ++ (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes) ++ pos)))) + + (defun notmuch-search-tag (&optional tag-changes) + "Change tags for the currently selected thread or region. +-- +1.7.10 + -- 2.26.2