Goto command for existing search windows

2012-03-30 Thread Jani Nikula
On Thu, 29 Mar 2012 13:27:36 -0700, Jameson Graef Rollins  wrote:
> On Thu, Mar 29 2012, Mark Anderson  wrote:
> > On Tue, 27 Mar 2012 14:24:36 -0600, Mark Anderson  > amd.com> wrote:
> >> I was looking for a function which would find a buffer based on one of
> >> my saved searches, and perform the search if it didn't exist.
> >> 
> >> I've gotten it a bit closer, if I perform the search that matches a
> >> saved search, then this routine will find it because of the magic in
> >> notmuch-search-buffer-title, but perhaps someone else feels up to
> >> searching through the saved searches directly?
> 
> Hey, Mark.  I think you can be a little simpler.  The title for search
> buffers is based on the search, so a buffer will always be reused for an
> identical search.  You don't need to do any fancy buffer searching.

Hi, I believe Mark's point was just switching to the buffer if it
exists, *without* refreshing or doing the query, and only doing regular
notmuch-search if a buffer doesn't exist yet.

BR,
Jani.


Goto command for existing search windows

2012-03-29 Thread Jameson Graef Rollins
On Thu, Mar 29 2012, Jani Nikula  wrote:
> Hi, I believe Mark's point was just switching to the buffer if it
> exists, *without* refreshing or doing the query, and only doing regular
> notmuch-search if a buffer doesn't exist yet.

I understand, but searches are so fast, particularly for searches that
you're doing frequently enough to map to a key binding, that I really
doubt it would ever be an issue.  It's certainly not for me.

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



Goto command for existing search windows

2012-03-29 Thread Jameson Graef Rollins
On Thu, Mar 29 2012, Mark Anderson  wrote:
> On Tue, 27 Mar 2012 14:24:36 -0600, Mark Anderson  
> wrote:
>> I was looking for a function which would find a buffer based on one of
>> my saved searches, and perform the search if it didn't exist.
>> 
>> I've gotten it a bit closer, if I perform the search that matches a
>> saved search, then this routine will find it because of the magic in
>> notmuch-search-buffer-title, but perhaps someone else feels up to
>> searching through the saved searches directly?

Hey, Mark.  I think you can be a little simpler.  The title for search
buffers is based on the search, so a buffer will always be reused for an
identical search.  You don't need to do any fancy buffer searching.  For
instance, the following works perfectly for me, and I believe produces
the same results as your technique:

(defun jnotmuch-inbox ()
  "Search: inbox"
  (interactive)
  (notmuch-search "tag:inbox" t))
(define-key notmuch-hello-mode-map "2" 'jnotmuch-inbox)
(define-key notmuch-search-mode-map "2" 'jnotmuch-inbox)
(define-key notmuch-show-mode-map "2" 'jnotmuch-inbox)

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



Goto command for existing search windows

2012-03-29 Thread Mark Anderson
On Tue, 27 Mar 2012 14:24:36 -0600, Mark Anderson  
wrote:
> I was looking for a function which would find a buffer based on one of
> my saved searches, and perform the search if it didn't exist.
> 
> I've gotten it a bit closer, if I perform the search that matches a
> saved search, then this routine will find it because of the magic in
> notmuch-search-buffer-title, but perhaps someone else feels up to
> searching through the saved searches directly?
> 
> 
> 
> (defun notmuch-goto-or-search ( query)
>   "Find a notmuch-search buffer with the given query, or run 
> \"notmuch search\" with the given `query' and display results.
> 
> If `query' is nil, it is read interactively from the minibuffer."
>   (interactive)
>   (if (null query)
>   (setq query (notmuch-read-query "Notmuch goto-or-search: ")))
>   (let ((buffer-name (notmuch-search-buffer-title query)))
> (setq buf (get-buffer buffer-name)))
>   
> (if (not buf)
> (notmuch-search query)
>   (switch-to-buffer buf)
>   )))

I have a slightly better-for-me version now:

(defun notmuch-goto-or-search ( query)
  "Find a notmuch saved-search query with the given name, or a
search with the given query, switching to an existing buffer
without changes in preference to automatically refreshing or
creating the search buffer.

If `query' is nil, it is read interactively from the minibuffer."
  (interactive)
  (if (null query)
  (setq query (notmuch-read-query "Notmuch goto-or-search: ")))
  (let ((saved-search-tuple (assoc query notmuch-saved-searches)))
(setq expanded-query
  (if (null saved-search-tuple)
  query
(cdr saved-search-tuple
  (let ((buffer-name (notmuch-search-buffer-title expanded-query)))
(setq buf (get-buffer buffer-name)))
(if (not buf)
(notmuch-search expanded-query)
  (switch-to-buffer buf)
  ))

This does search the saved searches to see if you entered a saved search
name.  With this I don't have to duplicate my query for saved searches
in key bindings.

(global-set-key [f8] (lambda () (interactive) (notmuch-goto-or-search "Inbox")))
(global-set-key [f9] (lambda () (interactive) (notmuch-goto-or-search "INBOX")))
(global-set-key [f10] (lambda () (interactive) (notmuch-goto-or-search "todo")))


> I then use it something like this:
> 
> (global-set-key [C-f1] (lambda () (interactive) (notmuch-goto-or-search 
> "tag:inbox and tag:unread and not tag:deleted")))
> (global-set-key [C-f2] (lambda () (interactive) (notmuch-goto-or-search 
> "tag:inbox and not tag:deleted")))
> (global-set-key [C-f3] 'notmuch)
> (global-set-key [C-f6] (lambda () (interactive) (notmuch-goto-or-search 
> "tag:todo and not tag:deleted")))
> 
> It would be better if I could use my Inbox, INBOX and todo names for the
> saved searches, but how to do that without breaking generality of
> searching the body of the email?  Do I have to define my own ss: (saved
> search) prefix or something, as I believe some others have?
> 
> This is what I'm willing to do today, and it works for me, I could patch
> notmuch.el, but I wondered about answering the other questions.
> 
> Also, some elisp master could hint about how to make the binding not so
> ugly. ;)
> 
> Another appreciated elisp hint would be how to get the buf variable to
> go inside the let, I keep getting complaints about buffer-name not being
> defined, thus the "ugly" setq, which works.
> 
> Enjoy,
> 
> -Mark



Re: Goto command for existing search windows

2012-03-29 Thread Mark Anderson
On Tue, 27 Mar 2012 14:24:36 -0600, Mark Anderson markr.ander...@amd.com 
wrote:
 I was looking for a function which would find a buffer based on one of
 my saved searches, and perform the search if it didn't exist.
 
 I've gotten it a bit closer, if I perform the search that matches a
 saved search, then this routine will find it because of the magic in
 notmuch-search-buffer-title, but perhaps someone else feels up to
 searching through the saved searches directly?
 
 
 
 (defun notmuch-goto-or-search (optional query)
   Find a notmuch-search buffer with the given query, or run 
 \notmuch search\ with the given `query' and display results.
 
 If `query' is nil, it is read interactively from the minibuffer.
   (interactive)
   (if (null query)
   (setq query (notmuch-read-query Notmuch goto-or-search: )))
   (let ((buffer-name (notmuch-search-buffer-title query)))
 (setq buf (get-buffer buffer-name)))
   
 (if (not buf)
 (notmuch-search query)
   (switch-to-buffer buf)
   )))

I have a slightly better-for-me version now:

(defun notmuch-goto-or-search (optional query)
  Find a notmuch saved-search query with the given name, or a
search with the given query, switching to an existing buffer
without changes in preference to automatically refreshing or
creating the search buffer.

If `query' is nil, it is read interactively from the minibuffer.
  (interactive)
  (if (null query)
  (setq query (notmuch-read-query Notmuch goto-or-search: )))
  (let ((saved-search-tuple (assoc query notmuch-saved-searches)))
(setq expanded-query
  (if (null saved-search-tuple)
  query
(cdr saved-search-tuple
  (let ((buffer-name (notmuch-search-buffer-title expanded-query)))
(setq buf (get-buffer buffer-name)))
(if (not buf)
(notmuch-search expanded-query)
  (switch-to-buffer buf)
  ))

This does search the saved searches to see if you entered a saved search
name.  With this I don't have to duplicate my query for saved searches
in key bindings.

(global-set-key [f8] (lambda () (interactive) (notmuch-goto-or-search Inbox)))
(global-set-key [f9] (lambda () (interactive) (notmuch-goto-or-search INBOX)))
(global-set-key [f10] (lambda () (interactive) (notmuch-goto-or-search todo)))


 I then use it something like this:
 
 (global-set-key [C-f1] (lambda () (interactive) (notmuch-goto-or-search 
 tag:inbox and tag:unread and not tag:deleted)))
 (global-set-key [C-f2] (lambda () (interactive) (notmuch-goto-or-search 
 tag:inbox and not tag:deleted)))
 (global-set-key [C-f3] 'notmuch)
 (global-set-key [C-f6] (lambda () (interactive) (notmuch-goto-or-search 
 tag:todo and not tag:deleted)))
 
 It would be better if I could use my Inbox, INBOX and todo names for the
 saved searches, but how to do that without breaking generality of
 searching the body of the email?  Do I have to define my own ss: (saved
 search) prefix or something, as I believe some others have?
 
 This is what I'm willing to do today, and it works for me, I could patch
 notmuch.el, but I wondered about answering the other questions.
 
 Also, some elisp master could hint about how to make the binding not so
 ugly. ;)
 
 Another appreciated elisp hint would be how to get the buf variable to
 go inside the let, I keep getting complaints about buffer-name not being
 defined, thus the ugly setq, which works.
 
 Enjoy,
 
 -Mark

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: Goto command for existing search windows

2012-03-29 Thread Jameson Graef Rollins
On Thu, Mar 29 2012, Mark Anderson markr.ander...@amd.com wrote:
 On Tue, 27 Mar 2012 14:24:36 -0600, Mark Anderson markr.ander...@amd.com 
 wrote:
 I was looking for a function which would find a buffer based on one of
 my saved searches, and perform the search if it didn't exist.
 
 I've gotten it a bit closer, if I perform the search that matches a
 saved search, then this routine will find it because of the magic in
 notmuch-search-buffer-title, but perhaps someone else feels up to
 searching through the saved searches directly?

Hey, Mark.  I think you can be a little simpler.  The title for search
buffers is based on the search, so a buffer will always be reused for an
identical search.  You don't need to do any fancy buffer searching.  For
instance, the following works perfectly for me, and I believe produces
the same results as your technique:

(defun jnotmuch-inbox ()
  Search: inbox
  (interactive)
  (notmuch-search tag:inbox t))
(define-key notmuch-hello-mode-map 2 'jnotmuch-inbox)
(define-key notmuch-search-mode-map 2 'jnotmuch-inbox)
(define-key notmuch-show-mode-map 2 'jnotmuch-inbox)

jamie.


pgpjZd7WPyGzx.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: Goto command for existing search windows

2012-03-29 Thread Jani Nikula
On Thu, 29 Mar 2012 13:27:36 -0700, Jameson Graef Rollins 
jroll...@finestructure.net wrote:
 On Thu, Mar 29 2012, Mark Anderson markr.ander...@amd.com wrote:
  On Tue, 27 Mar 2012 14:24:36 -0600, Mark Anderson markr.ander...@amd.com 
  wrote:
  I was looking for a function which would find a buffer based on one of
  my saved searches, and perform the search if it didn't exist.
  
  I've gotten it a bit closer, if I perform the search that matches a
  saved search, then this routine will find it because of the magic in
  notmuch-search-buffer-title, but perhaps someone else feels up to
  searching through the saved searches directly?
 
 Hey, Mark.  I think you can be a little simpler.  The title for search
 buffers is based on the search, so a buffer will always be reused for an
 identical search.  You don't need to do any fancy buffer searching.

Hi, I believe Mark's point was just switching to the buffer if it
exists, *without* refreshing or doing the query, and only doing regular
notmuch-search if a buffer doesn't exist yet.

BR,
Jani.
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: Goto command for existing search windows

2012-03-29 Thread Jameson Graef Rollins
On Thu, Mar 29 2012, Jani Nikula j...@nikula.org wrote:
 Hi, I believe Mark's point was just switching to the buffer if it
 exists, *without* refreshing or doing the query, and only doing regular
 notmuch-search if a buffer doesn't exist yet.

I understand, but searches are so fast, particularly for searches that
you're doing frequently enough to map to a key binding, that I really
doubt it would ever be an issue.  It's certainly not for me.

jamie.


pgpnhk9aXuXv6.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Goto command for existing search windows

2012-03-27 Thread Mark Anderson
I was looking for a function which would find a buffer based on one of
my saved searches, and perform the search if it didn't exist.

I've gotten it a bit closer, if I perform the search that matches a
saved search, then this routine will find it because of the magic in
notmuch-search-buffer-title, but perhaps someone else feels up to
searching through the saved searches directly?



(defun notmuch-goto-or-search ( query)
  "Find a notmuch-search buffer with the given query, or run 
\"notmuch search\" with the given `query' and display results.

If `query' is nil, it is read interactively from the minibuffer."
  (interactive)
  (if (null query)
  (setq query (notmuch-read-query "Notmuch goto-or-search: ")))
  (let ((buffer-name (notmuch-search-buffer-title query)))
(setq buf (get-buffer buffer-name)))

(if (not buf)
(notmuch-search query)
  (switch-to-buffer buf)
  )))

I then use it something like this:

(global-set-key [C-f1] (lambda () (interactive) (notmuch-goto-or-search 
"tag:inbox and tag:unread and not tag:deleted")))
(global-set-key [C-f2] (lambda () (interactive) (notmuch-goto-or-search 
"tag:inbox and not tag:deleted")))
(global-set-key [C-f3] 'notmuch)
(global-set-key [C-f6] (lambda () (interactive) (notmuch-goto-or-search 
"tag:todo and not tag:deleted")))

It would be better if I could use my Inbox, INBOX and todo names for the
saved searches, but how to do that without breaking generality of
searching the body of the email?  Do I have to define my own ss: (saved
search) prefix or something, as I believe some others have?

This is what I'm willing to do today, and it works for me, I could patch
notmuch.el, but I wondered about answering the other questions.

Also, some elisp master could hint about how to make the binding not so
ugly. ;)

Another appreciated elisp hint would be how to get the buf variable to
go inside the let, I keep getting complaints about buffer-name not being
defined, thus the "ugly" setq, which works.

Enjoy,

-Mark



Goto command for existing search windows

2012-03-27 Thread Mark Anderson
I was looking for a function which would find a buffer based on one of
my saved searches, and perform the search if it didn't exist.

I've gotten it a bit closer, if I perform the search that matches a
saved search, then this routine will find it because of the magic in
notmuch-search-buffer-title, but perhaps someone else feels up to
searching through the saved searches directly?



(defun notmuch-goto-or-search (optional query)
  Find a notmuch-search buffer with the given query, or run 
\notmuch search\ with the given `query' and display results.

If `query' is nil, it is read interactively from the minibuffer.
  (interactive)
  (if (null query)
  (setq query (notmuch-read-query Notmuch goto-or-search: )))
  (let ((buffer-name (notmuch-search-buffer-title query)))
(setq buf (get-buffer buffer-name)))
  
(if (not buf)
(notmuch-search query)
  (switch-to-buffer buf)
  )))

I then use it something like this:

(global-set-key [C-f1] (lambda () (interactive) (notmuch-goto-or-search 
tag:inbox and tag:unread and not tag:deleted)))
(global-set-key [C-f2] (lambda () (interactive) (notmuch-goto-or-search 
tag:inbox and not tag:deleted)))
(global-set-key [C-f3] 'notmuch)
(global-set-key [C-f6] (lambda () (interactive) (notmuch-goto-or-search 
tag:todo and not tag:deleted)))

It would be better if I could use my Inbox, INBOX and todo names for the
saved searches, but how to do that without breaking generality of
searching the body of the email?  Do I have to define my own ss: (saved
search) prefix or something, as I believe some others have?

This is what I'm willing to do today, and it works for me, I could patch
notmuch.el, but I wondered about answering the other questions.

Also, some elisp master could hint about how to make the binding not so
ugly. ;)

Another appreciated elisp hint would be how to get the buf variable to
go inside the let, I keep getting complaints about buffer-name not being
defined, thus the ugly setq, which works.

Enjoy,

-Mark

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch