--- /dev/null
+Return-Path: <dme@dme.org>\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 CB0FF429E25\r
+ for <notmuch@notmuchmail.org>; Wed, 28 Dec 2011 00:30:04 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[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 HPQxuZFapChg for <notmuch@notmuchmail.org>;\r
+ Wed, 28 Dec 2011 00:30:04 -0800 (PST)\r
+Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
+ [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 29AF4431FB6\r
+ for <notmuch@notmuchmail.org>; Wed, 28 Dec 2011 00:30:04 -0800 (PST)\r
+Received: by wibhq2 with SMTP id hq2so6574947wib.26\r
+ for <notmuch@notmuchmail.org>; Wed, 28 Dec 2011 00:30:03 -0800 (PST)\r
+Received: by 10.180.91.201 with SMTP id cg9mr68289772wib.15.1325061002940;\r
+ Wed, 28 Dec 2011 00:30:02 -0800 (PST)\r
+Received: from hotblack-desiato.hh.sledj.net\r
+ (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
+ by mx.google.com with ESMTPS id k5sm72525358wiz.9.2011.12.28.00.30.01\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Wed, 28 Dec 2011 00:30:01 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+ id E8100A0334; Wed, 28 Dec 2011 08:29:59 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2] emacs: Cycle through notmuch buffers rather than jumping\r
+ to the last.\r
+Date: Wed, 28 Dec 2011 08:29:58 +0000\r
+Message-Id: <1325060998-25567-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <1324983044-29249-1-git-send-email-dme@dme.org>\r
+References: <1324983044-29249-1-git-send-email-dme@dme.org>\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: Wed, 28 Dec 2011 08:30:04 -0000\r
+\r
+As suggested by j4ni in #notmuch, rename\r
+`notmuch-jump-to-recent-buffer' as `notmuch-cycle-notmuch-buffers' and\r
+have it behave accordingly.\r
+\r
+Consider `message-mode' buffers to be of interest.\r
+---\r
+ emacs/notmuch.el | 42 ++++++++++++++++++++++++++++++------------\r
+ 1 files changed, 30 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index c678c93..6a44d49 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -1055,21 +1055,39 @@ current search results AND that are tagged with the given tag."\r
+ (interactive)\r
+ (notmuch-hello))\r
+ \r
++(defun notmuch-interesting-buffer (b)\r
++ "Is the current buffer of interest to a notmuch user?"\r
++ (with-current-buffer b\r
++ (memq major-mode '(notmuch-show-mode\r
++ notmuch-search-mode\r
++ notmuch-hello-mode\r
++ message-mode))))\r
++\r
+ ;;;###autoload\r
+-(defun notmuch-jump-to-recent-buffer ()\r
+- "Jump to the most recent notmuch buffer (search, show or hello).\r
++(defun notmuch-cycle-notmuch-buffers ()\r
++ "Cycle through any existing notmuch buffers (search, show or hello).\r
+ \r
+-If no recent buffer is found, run `notmuch'."\r
++If the current buffer is the only notmuch buffer, bury it. If no\r
++notmuch buffers exist, run `notmuch'."\r
+ (interactive)\r
+- (let ((last\r
+- (loop for buffer in (buffer-list)\r
+- if (with-current-buffer buffer\r
+- (memq major-mode '(notmuch-show-mode\r
+- notmuch-search-mode\r
+- notmuch-hello-mode)))\r
+- return buffer)))\r
+- (if last\r
+- (switch-to-buffer last)\r
++\r
++ (let (start first)\r
++ ;; If the current buffer is a notmuch buffer, remember it and then\r
++ ;; bury it.\r
++ (when (notmuch-interesting-buffer (current-buffer))\r
++ (setq start (current-buffer))\r
++ (bury-buffer))\r
++\r
++ ;; Find the first notmuch buffer.\r
++ (setq first (loop for buffer in (buffer-list)\r
++ if (notmuch-interesting-buffer buffer)\r
++ return buffer))\r
++\r
++ (if first\r
++ ;; If the first one we found is any other than the starting\r
++ ;; buffer, switch to it.\r
++ (unless (eq first start)\r
++ (switch-to-buffer first))\r
+ (notmuch))))\r
+ \r
+ (setq mail-user-agent 'notmuch-user-agent)\r
+-- \r
+1.7.7.3\r
+\r