--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 123DE431FC3\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 13:12:12 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id m6vSpttSWi+4 for <notmuch@notmuchmail.org>;\r
+ Tue, 22 Apr 2014 13:12:08 -0700 (PDT)\r
+Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
+ [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 4AA13431FBF\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 13:12:08 -0700 (PDT)\r
+Received: by mail-wi0-f173.google.com with SMTP id z2so3903824wiv.0\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 13:12:05 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=weUmrjQ6ICY+xSyHDhBDPP4hsICP4Gq9OTL/Kk5Cp10=;\r
+ b=zUFs1qnHTlzm3cUP9jyOeutQT2ySmu6ngPEy5UTorE571O+LaLJ3lYhkSt5jFVBV6p\r
+ R8awIPrUxi9qWSJaDP3t+7dB9Lnx1n1hmaAKkChV0We6aiESqCFpPzG4NuHzwzNnm61S\r
+ +uKdvsK5fzSnpua2WzOGW8/Tb7ji9EkE9qeabDls+jpxyEj06vFTs2JhNuxLmawFZK1S\r
+ Wo9fMBOssGn9WkZ1VLZqclcJ38Z0kNoUCp5rkG+AMRvSx1t3jWwEjcuVg8vccnZgc4gA\r
+ IbNO7mHLu9OzVjJMO7+HR83pYJCnN/wpz/kcZXTGtYRzTwdZTJYBEP16F2dzXS1S9bm5\r
+ eYbQ==\r
+X-Received: by 10.180.149.143 with SMTP id ua15mr5304wib.36.1398197525869;\r
+ Tue, 22 Apr 2014 13:12:05 -0700 (PDT)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by mx.google.com with ESMTPSA id\r
+ by1sm63298495wjc.26.2014.04.22.13.12.05 for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Tue, 22 Apr 2014 13:12:05 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP PATCH 1/4] emacs: search: tidy notmuch-search-foreach-result\r
+Date: Tue, 22 Apr 2014 21:11:47 +0100\r
+Message-Id: <1398197510-28224-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1398197510-28224-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1398197510-28224-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 22 Apr 2014 20:12:12 -0000\r
+\r
+notmuch-search-foreach-result is cumbersome as it applies the callback\r
+function with the position of the start of the thread as the\r
+argument. It is more natural to move point to the start of each\r
+relevant thread and not pass any arguments to the callback function.\r
+---\r
+ emacs/notmuch.el | 52 ++++++++++++++++++++++++----------------------------\r
+ 1 file changed, 24 insertions(+), 28 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 6c0bc1b..cb7c006 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -378,27 +378,24 @@ (defun notmuch-search-result-end (&optional pos)\r
+ (defun notmuch-search-foreach-result (beg end function)\r
+ "Invoke FUNCTION for each result between BEG and END.\r
+ \r
+-FUNCTION should take one argument. It will be applied to the\r
+-character position of the beginning of each result that overlaps\r
+-the region between points BEG and END. As a special case, if (=\r
+-BEG END), FUNCTION will be applied to the result containing point\r
+-BEG."\r
+-\r
+- (lexical-let ((pos (notmuch-search-result-beginning beg))\r
+- ;; End must be a marker in case function changes the\r
+- ;; text.\r
+- (end (copy-marker end))\r
+- ;; Make sure we examine at least one result, even if\r
+- ;; (= beg end).\r
+- (first t))\r
+- ;; We have to be careful if the region extends beyond the results.\r
+- ;; In this case, pos could be null or there could be no result at\r
+- ;; pos.\r
+- (while (and pos (or (< pos end) first))\r
+- (when (notmuch-search-get-result pos)\r
+- (funcall function pos))\r
+- (setq pos (notmuch-search-result-end pos)\r
+- first nil))))\r
++FUNCTION should take no arguments. It will be applied at the\r
++beginning of each result that overlaps the region between points\r
++BEG and END. As a special case, if (= BEG END), FUNCTION will be\r
++applied to the result containing point BEG."\r
++\r
++ (when (notmuch-search-get-result)\r
++ (save-excursion\r
++ ;; End must be a marker in case function changes the text.\r
++ (lexical-let ((end (copy-marker end)))\r
++ ;; We always apply function at least once: even if (= BEG END).\r
++ (goto-char (notmuch-search-result-beginning beg))\r
++ (funcall function)\r
++ (notmuch-search-next-thread)\r
++ (while (and (notmuch-search-get-result)\r
++ (< (notmuch-search-result-beginning) end))\r
++ (funcall function)\r
++ (notmuch-search-next-thread))))))\r
++\r
+ ;; Unindent the function argument of notmuch-search-foreach-result so\r
+ ;; the indentation of callers doesn't get out of hand.\r
+ (put 'notmuch-search-foreach-result 'lisp-indent-function 2)\r
+@@ -406,8 +403,8 @@ (defun notmuch-search-foreach-result (beg end function)\r
+ (defun notmuch-search-properties-in-region (property beg end)\r
+ (let (output)\r
+ (notmuch-search-foreach-result beg end\r
+- (lambda (pos)\r
+- (push (plist-get (notmuch-search-get-result pos) property) output)))\r
++ (lambda ()\r
++ (push (plist-get (notmuch-search-get-result) property) output)))\r
+ output))\r
+ \r
+ (defun notmuch-search-find-thread-id (&optional bare)\r
+@@ -503,8 +500,8 @@ (defun notmuch-search-get-tags (&optional pos)\r
+ (defun notmuch-search-get-tags-region (beg end)\r
+ (let (output)\r
+ (notmuch-search-foreach-result beg end\r
+- (lambda (pos)\r
+- (setq output (append output (notmuch-search-get-tags pos)))))\r
++ (lambda ()\r
++ (setq output (append output (notmuch-search-get-tags)))))\r
+ output))\r
+ \r
+ (defun notmuch-search-interactive-region ()\r
+@@ -543,10 +540,9 @@ (defun notmuch-search-tag (tag-changes &optional beg end only-matched)\r
+ beg end only-matched)))\r
+ (notmuch-tag search-string tag-changes)\r
+ (notmuch-search-foreach-result beg end\r
+- (lambda (pos)\r
++ (lambda ()\r
+ (notmuch-search-set-tags\r
+- (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
+- pos)))))\r
++ (notmuch-update-tags (notmuch-search-get-tags) tag-changes))))))\r
+ \r
+ (defun notmuch-search-add-tag (tag-changes &optional beg end)\r
+ "Change tags for the current thread or region (defaulting to add).\r
+-- \r
+1.7.10.4\r
+\r