From: Mark Walters Date: Tue, 22 Apr 2014 20:11:47 +0000 (+0100) Subject: [WIP PATCH 1/4] emacs: search: tidy notmuch-search-foreach-result X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b5860db98882f51d95e4b2dd0a23892a5fbe08d1;p=notmuch-archives.git [WIP PATCH 1/4] emacs: search: tidy notmuch-search-foreach-result --- diff --git a/8d/77d53825e6443efab9686a28456796385578a9 b/8d/77d53825e6443efab9686a28456796385578a9 new file mode 100644 index 000000000..f3df6acca --- /dev/null +++ b/8d/77d53825e6443efab9686a28456796385578a9 @@ -0,0 +1,159 @@ +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 123DE431FC3 + for ; Tue, 22 Apr 2014 13:12:12 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, + 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 m6vSpttSWi+4 for ; + Tue, 22 Apr 2014 13:12:08 -0700 (PDT) +Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com + [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 4AA13431FBF + for ; Tue, 22 Apr 2014 13:12:08 -0700 (PDT) +Received: by mail-wi0-f173.google.com with SMTP id z2so3903824wiv.0 + for ; Tue, 22 Apr 2014 13:12:05 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:in-reply-to:references; + bh=weUmrjQ6ICY+xSyHDhBDPP4hsICP4Gq9OTL/Kk5Cp10=; + b=zUFs1qnHTlzm3cUP9jyOeutQT2ySmu6ngPEy5UTorE571O+LaLJ3lYhkSt5jFVBV6p + R8awIPrUxi9qWSJaDP3t+7dB9Lnx1n1hmaAKkChV0We6aiESqCFpPzG4NuHzwzNnm61S + +uKdvsK5fzSnpua2WzOGW8/Tb7ji9EkE9qeabDls+jpxyEj06vFTs2JhNuxLmawFZK1S + Wo9fMBOssGn9WkZ1VLZqclcJ38Z0kNoUCp5rkG+AMRvSx1t3jWwEjcuVg8vccnZgc4gA + IbNO7mHLu9OzVjJMO7+HR83pYJCnN/wpz/kcZXTGtYRzTwdZTJYBEP16F2dzXS1S9bm5 + eYbQ== +X-Received: by 10.180.149.143 with SMTP id ua15mr5304wib.36.1398197525869; + Tue, 22 Apr 2014 13:12:05 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by mx.google.com with ESMTPSA id + by1sm63298495wjc.26.2014.04.22.13.12.05 for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Tue, 22 Apr 2014 13:12:05 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [WIP PATCH 1/4] emacs: search: tidy notmuch-search-foreach-result +Date: Tue, 22 Apr 2014 21:11:47 +0100 +Message-Id: <1398197510-28224-2-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1398197510-28224-1-git-send-email-markwalters1009@gmail.com> +References: <1398197510-28224-1-git-send-email-markwalters1009@gmail.com> +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: Tue, 22 Apr 2014 20:12:12 -0000 + +notmuch-search-foreach-result is cumbersome as it applies the callback +function with the position of the start of the thread as the +argument. It is more natural to move point to the start of each +relevant thread and not pass any arguments to the callback function. +--- + emacs/notmuch.el | 52 ++++++++++++++++++++++++---------------------------- + 1 file changed, 24 insertions(+), 28 deletions(-) + +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index 6c0bc1b..cb7c006 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -378,27 +378,24 @@ (defun notmuch-search-result-end (&optional pos) + (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)))) ++FUNCTION should take no arguments. It will be applied at 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." ++ ++ (when (notmuch-search-get-result) ++ (save-excursion ++ ;; End must be a marker in case function changes the text. ++ (lexical-let ((end (copy-marker end))) ++ ;; We always apply function at least once: even if (= BEG END). ++ (goto-char (notmuch-search-result-beginning beg)) ++ (funcall function) ++ (notmuch-search-next-thread) ++ (while (and (notmuch-search-get-result) ++ (< (notmuch-search-result-beginning) end)) ++ (funcall function) ++ (notmuch-search-next-thread)))))) ++ + ;; 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) +@@ -406,8 +403,8 @@ (defun notmuch-search-foreach-result (beg end function) + (defun notmuch-search-properties-in-region (property beg end) + (let (output) + (notmuch-search-foreach-result beg end +- (lambda (pos) +- (push (plist-get (notmuch-search-get-result pos) property) output))) ++ (lambda () ++ (push (plist-get (notmuch-search-get-result) property) output))) + output)) + + (defun notmuch-search-find-thread-id (&optional bare) +@@ -503,8 +500,8 @@ (defun notmuch-search-get-tags (&optional pos) + (defun notmuch-search-get-tags-region (beg end) + (let (output) + (notmuch-search-foreach-result beg end +- (lambda (pos) +- (setq output (append output (notmuch-search-get-tags pos))))) ++ (lambda () ++ (setq output (append output (notmuch-search-get-tags))))) + output)) + + (defun notmuch-search-interactive-region () +@@ -543,10 +540,9 @@ (defun notmuch-search-tag (tag-changes &optional beg end only-matched) + beg end only-matched))) + (notmuch-tag search-string tag-changes) + (notmuch-search-foreach-result beg end +- (lambda (pos) ++ (lambda () + (notmuch-search-set-tags +- (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes) +- pos))))) ++ (notmuch-update-tags (notmuch-search-get-tags) tag-changes)))))) + + (defun notmuch-search-add-tag (tag-changes &optional beg end) + "Change tags for the current thread or region (defaulting to add). +-- +1.7.10.4 +