--- /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 28D8B431FCB\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 13:12:14 -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 448xH2R6yVh3 for <notmuch@notmuchmail.org>;\r
+ Tue, 22 Apr 2014 13:12:12 -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 95338431FC2\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 13:12:10 -0700 (PDT)\r
+Received: by mail-wi0-f173.google.com with SMTP id z2so3903894wiv.0\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 13:12:09 -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=tcWOUiPa0t2iWTfMBp54srjI2fxmmQmzNUsJzEJmKmw=;\r
+ b=FueXz3sSMvipKnaK9NLMoYOPFNXqXsyD6oL4ToLRo8BzXDSSXy4asfNXlZLNgzf9nu\r
+ TwiyGh3XIjlvixZSrhPIS3LEuHuWyGIY5kpoHVw1uvoUEmRQSsLitxWo4ijzzRNNPEhR\r
+ 333i0sE1c1DwK73BilBDV/WTfIvrDujExXABHo4736qc/Ad3ysN3iTYz1AelVk7D3RGJ\r
+ or2ofANyq4r4T4bC1UXo8ZmdwpdI1OS4XMOZlsxHK0ZuKtSDVCGdXLfQo8ReVcn2aZo3\r
+ wDj6vijFekZ52wOAWpueXXWDGivvizEd+LkRx+jC8AppGPd85LrNOemy9SthSwQU+ciu\r
+ sSBA==\r
+X-Received: by 10.194.59.43 with SMTP id w11mr4049809wjq.65.1398197529549;\r
+ Tue, 22 Apr 2014 13:12:09 -0700 (PDT)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by mx.google.com with ESMTPSA id jd2sm24558632wic.9.2014.04.22.13.12.08\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Tue, 22 Apr 2014 13:12:09 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP PATCH 3/4] emacs: search: split foreach-result into list and\r
+ region variants\r
+Date: Tue, 22 Apr 2014 21:11:49 +0100\r
+Message-Id: <1398197510-28224-4-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:14 -0000\r
+\r
+---\r
+ emacs/notmuch.el | 20 +++++++++++++++++++-\r
+ 1 file changed, 19 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 7b06458..e1ece47 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -380,7 +380,20 @@ (defun notmuch-search-result-end (&optional pos)\r
+ (next-single-property-change (or pos (point)) 'notmuch-search-result\r
+ nil (point-max))))\r
+ \r
+-(defun notmuch-search-foreach-result (beg end thread-list function)\r
++(defun notmuch-search-foreach-result-in-list (thread-list function)\r
++ "Invoke function for each thread in list."\r
++ (lexical-let ((thread-list (copy-sequence thread-list)))\r
++ (save-excursion\r
++ (goto-char (point-min))\r
++ (while (and (notmuch-search-get-result)\r
++ thread-list)\r
++ (let ((thread (notmuch-search-find-thread-id)))\r
++ (when (member thread thread-list)\r
++ (funcall function)\r
++ (setq thread-list (delete thread thread-list))))\r
++ (notmuch-search-next-thread)))))\r
++\r
++(defun notmuch-search-foreach-result-in-region (beg end function)\r
+ "Invoke FUNCTION for each result between BEG and END.\r
+ \r
+ FUNCTION should take no arguments. It will be applied at the\r
+@@ -401,6 +414,11 @@ (defun notmuch-search-foreach-result (beg end thread-list function)\r
+ (funcall function)\r
+ (notmuch-search-next-thread))))))\r
+ \r
++(defun notmuch-search-foreach-result (beg end thread-list function)\r
++ (if thread-list\r
++ (notmuch-search-foreach-result-in-list thread-list function)\r
++ (notmuch-search-foreach-result-in-region beg end function)))\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
+-- \r
+1.7.10.4\r
+\r