From: Austin Clements Date: Sat, 21 Jul 2012 17:37:08 +0000 (+2000) Subject: [PATCH v4 4/8] emacs: Use result text properties for search result iteration X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=bd5ae790b94d07aacee9ebc16b9c48fc8bdbcabd;p=notmuch-archives.git [PATCH v4 4/8] emacs: Use result text properties for search result iteration --- diff --git a/e0/30a189665cd887cbf06a20a705c03c40d58c91 b/e0/30a189665cd887cbf06a20a705c03c40d58c91 new file mode 100644 index 000000000..32e47f6ab --- /dev/null +++ b/e0/30a189665cd887cbf06a20a705c03c40d58c91 @@ -0,0 +1,199 @@ +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 132B1431FAE + for ; Sat, 21 Jul 2012 10:37:21 -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 AXkZLTqCf9ZS for ; + Sat, 21 Jul 2012 10:37:19 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU + [18.9.25.14]) + by olra.theworths.org (Postfix) with ESMTP id B4051431FAF + for ; Sat, 21 Jul 2012 10:37:19 -0700 (PDT) +X-AuditID: 1209190e-b7fb56d0000008b2-3b-500ae8ce825d +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id EA.13.02226.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-3.mit.edu (8.13.8/8.9.2) with ESMTP id q6LHbHRx018463; + 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 q6LHbFJu008016 + (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-0001Zl-Ba; Sat, 21 Jul 2012 13:37:15 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v4 4/8] emacs: Use result text properties for search result + iteration +Date: Sat, 21 Jul 2012 13:37:08 -0400 +Message-Id: <1342892232-5659-5-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+NgFjrMIsWRmVeSWpSXmKPExsUixCmqrXvuBVeAQdsrUYs9+7wsVs/lsbh+ + cyazA7PH3dNcHjtn3WX3eLbqFnMAcxSXTUpqTmZZapG+XQJXxutPK5gK9mtU/F+9m7mB8aZC + FyMnh4SAiUT71FVsELaYxIV764FsLg4hgX2MEkuu3WSHcDYwSrSs+c0IUiUk8IhJ4vvjCojE + XEaJjp417CAJNgENiW37l4MViQhIS+y8O5sVxGYWSJP43v4WKM7BISwQKnH7lTtImEVAVeL1 + 6YVg5bwC9hKHnj1kh7hCXuLp/T6wizgFHCQenT3AArG3TGJxx2HGCYz8CxgZVjHKpuRW6eYm + ZuYUpybrFicn5uWlFuka6+VmluilppRuYgSHlSTfDsavB5UOMQpwMCrx8HrM4gwQYk0sK67M + PcQoycGkJMrbd58rQIgvKT+lMiOxOCO+qDQntfgQowQHs5II76bTQDnelMTKqtSifJiUNAeL + kjjvlZSb/kIC6YklqdmpqQWpRTBZGQ4OJQled2D8CAkWpaanVqRl5pQgpJk4OEGG8wANDwap + 4S0uSMwtzkyHyJ9iVJQS57UDSQiAJDJK8+B6YXH/ilEc6BVh3m/Pgap4gCkDrvsV0GAmoMHS + WWCDSxIRUlINjAs/KgsKzuVtrnockMPhEcJT+1Sv9YfB4hu7Wo6xX/irpuTKmmeuqh/ee6ov + XsRUQjr//1vb/JWTg1zZppw/er3647amczpSN3mzVafH/4qQ2nbYZW6sQFPob40X5a7vN3+f + 1rr+xhGD54eNTqfWR34Rrj0aXeookaJhOsPkzel3EtLB93wPKLEUZyQaajEXFScCABHskUvW AgAA +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:21 -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 for interactive navigation. +--- + emacs/notmuch.el | 78 ++++++++++++++++++++++++++++++++++-------------------- + 1 file changed, 50 insertions(+), 28 deletions(-) + +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index 6995482..f79d004 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -69,7 +69,13 @@ + date, count, authors, subject, tags + For example: + (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\) +- \(\"subject\" . \"%s\"\)\)\)" ++ \(\"subject\" . \"%s\"\)\)\) ++Line breaks are permitted in format strings (though this is ++currently experimental). Note that a line break at the end of an ++\"authors\" field will get elided if the authors list is long; ++place it instead at the beginning of the following field. To ++enter a line break when setting this variable with setq, use \\n. ++To enter a line break in customize, press \\[quoted-insert] C-j." + :type '(alist :key-type (string) :value-type (string)) + :group 'notmuch-search) + +@@ -427,17 +433,40 @@ returns nil" + (next-single-property-change (or pos (point)) 'notmuch-search-result + nil (point-max)))) + ++(defun notmuch-search-foreach-result (beg end function) ++ "Invoke FUNCTION for each result between BEG and END. ++ ++FUNCTION should take one argument. It will be applied to the ++character position of the beginning of each result that overlaps ++the region between points BEG and END. As a special case, if (= ++BEG END), FUNCTION will be applied to the result containing point ++BEG." ++ ++ (lexical-let ((pos (notmuch-search-result-beginning beg)) ++ ;; End must be a marker in case function changes the ++ ;; text. ++ (end (copy-marker end)) ++ ;; Make sure we examine at least one result, even if ++ ;; (= beg end). ++ (first 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 (or (< pos end) first)) ++ (when (notmuch-search-get-result pos) ++ (funcall function pos)) ++ (setq pos (notmuch-search-result-end pos) ++ first nil)))) ++;; Unindent the function argument of notmuch-search-foreach-result so ++;; the indentation of callers doesn't get out of hand. ++(put 'notmuch-search-foreach-result 'lisp-indent-function 2) ++ + (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-foreach-result beg end ++ (lambda (pos) ++ (push (get-text-property pos property) output))) ++ output)) + + (defun notmuch-search-find-thread-id () + "Return the thread for the current thread" +@@ -517,28 +546,21 @@ 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-foreach-result beg end ++ (lambda (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-foreach-result beg end ++ (lambda (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 +