unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Edmondson <dme@dme.org>
To: notmuch@notmuchmail.org
Subject: [PATCH v2] emacs: Cycle through notmuch buffers rather than jumping to the last.
Date: Wed, 28 Dec 2011 08:29:58 +0000	[thread overview]
Message-ID: <1325060998-25567-1-git-send-email-dme@dme.org> (raw)
In-Reply-To: <1324983044-29249-1-git-send-email-dme@dme.org>

As suggested by j4ni in #notmuch, rename
`notmuch-jump-to-recent-buffer' as `notmuch-cycle-notmuch-buffers' and
have it behave accordingly.

Consider `message-mode' buffers to be of interest.
---
 emacs/notmuch.el |   42 ++++++++++++++++++++++++++++++------------
 1 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index c678c93..6a44d49 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -1055,21 +1055,39 @@ current search results AND that are tagged with the given tag."
   (interactive)
   (notmuch-hello))
 
+(defun notmuch-interesting-buffer (b)
+  "Is the current buffer of interest to a notmuch user?"
+  (with-current-buffer b
+    (memq major-mode '(notmuch-show-mode
+		       notmuch-search-mode
+		       notmuch-hello-mode
+		       message-mode))))
+
 ;;;###autoload
-(defun notmuch-jump-to-recent-buffer ()
-  "Jump to the most recent notmuch buffer (search, show or hello).
+(defun notmuch-cycle-notmuch-buffers ()
+  "Cycle through any existing notmuch buffers (search, show or hello).
 
-If no recent buffer is found, run `notmuch'."
+If the current buffer is the only notmuch buffer, bury it. If no
+notmuch buffers exist, run `notmuch'."
   (interactive)
-  (let ((last
-	 (loop for buffer in (buffer-list)
-	       if (with-current-buffer buffer
-		    (memq major-mode '(notmuch-show-mode
-				       notmuch-search-mode
-				       notmuch-hello-mode)))
-	       return buffer)))
-    (if last
-	(switch-to-buffer last)
+
+  (let (start first)
+    ;; If the current buffer is a notmuch buffer, remember it and then
+    ;; bury it.
+    (when (notmuch-interesting-buffer (current-buffer))
+      (setq start (current-buffer))
+      (bury-buffer))
+
+    ;; Find the first notmuch buffer.
+    (setq first (loop for buffer in (buffer-list)
+		     if (notmuch-interesting-buffer buffer)
+		     return buffer))
+
+    (if first
+	;; If the first one we found is any other than the starting
+	;; buffer, switch to it.
+	(unless (eq first start)
+	  (switch-to-buffer first))
       (notmuch))))
 
 (setq mail-user-agent 'notmuch-user-agent)
-- 
1.7.7.3

  parent reply	other threads:[~2011-12-28  8:30 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-27 10:50 [PATCH] emacs: Cycle through notmuch buffers rather than jumping to the last David Edmondson
2011-12-27 11:02 ` David Edmondson
2011-12-27 19:23 ` Jani Nikula
2011-12-28  8:20   ` David Edmondson
2011-12-28  8:29 ` David Edmondson [this message]
2012-01-10 16:55   ` [PATCH v2] " David Edmondson
2012-01-10 20:15     ` Jani Nikula
2012-01-14  9:32       ` Pieter Praet
2012-01-14  9:29   ` Pieter Praet
2012-01-15 11:55     ` David Edmondson
2012-01-16  3:01       ` Austin Clements
2012-01-16  8:43         ` David Edmondson
2012-01-16 10:42           ` [PATCH] [RFC] emacs: merge overhauled `notmuch-cycle-notmuch-buffers' into `notmuch' Pieter Praet
2012-01-16 11:06             ` David Edmondson
2012-01-16 11:28               ` Pieter Praet
2012-01-16 11:32                 ` Pieter Praet
2012-01-16 11:47                 ` David Edmondson
2012-01-16 16:45                   ` Pieter Praet
2012-01-16 16:46                     ` [PATCH] v2 " Pieter Praet
2012-01-16 17:03                       ` David Edmondson
2012-01-18 10:03                         ` Pieter Praet
2012-01-18 10:04                           ` [RFC] [PATCH v3] emacs: rewrite `notmuch-cycle-notmuch-buffers' Pieter Praet
2012-01-18 10:13                           ` [PATCH] v2 [RFC] emacs: merge overhauled `notmuch-cycle-notmuch-buffers' into `notmuch' David Edmondson
2012-01-18 12:15                             ` Pieter Praet
2012-01-18 12:57                               ` David Edmondson
     [not found]                                 ` <cunboq1mad1.fsf@hotblack-desiato.hh.sledj.net>
2012-01-18 13:48                                   ` Pieter Praet
2012-01-18 22:18                                     ` Aaron Ecay
2012-01-19  0:48                                       ` Austin Clements
2012-01-19  8:19                                       ` David Edmondson
2012-01-19 19:13                                       ` Pieter Praet
2012-01-16 21:10                       ` Jani Nikula
2012-01-18 10:07                         ` Pieter Praet
2012-01-16  2:45   ` [PATCH v2] emacs: Cycle through notmuch buffers rather than jumping to the last David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1325060998-25567-1-git-send-email-dme@dme.org \
    --to=dme@dme.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).