* using notmuch programmatically from emacs
@ 2014-07-18 13:09 Alan Schmitt
2014-07-18 19:40 ` David Bremner
0 siblings, 1 reply; 3+ messages in thread
From: Alan Schmitt @ 2014-07-18 13:09 UTC (permalink / raw)
To: notmuch
[-- Attachment #1: Type: text/plain, Size: 974 bytes --]
Hello,
I sometimes have to find a message knowing only its message id. I know
how to use a notmuch search in emacs to find the message, then use
another function to display it in gnus, but I would like to do it
directly without going through the *notmuch-search* buffer.
Right now I'm doing the following:
#+begin_src emacs-lisp
(defun as/msgid-to-gnus (msgid)
"Search for the MSGID using notmuch, then open the message with
gnus."
(let ((file (shell-command-to-string (concat "notmuch search --output=files 'id:" msgid "'"))))
(gnus-summary-read-group (notmuch-file-to-group file))
(gnus-summary-refer-article msgid)))
#+end_src
(the `notmuch-file-to-group' function takes a file name and finds the
corresponding gnus group).
Is there a way to do the same thing using notmuch.el functionality
(i.e., without having to do the `shell-command-to-string' myself)?
Thanks,
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
[-- Attachment #2: Type: application/pgp-signature, Size: 494 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: using notmuch programmatically from emacs
2014-07-18 13:09 using notmuch programmatically from emacs Alan Schmitt
@ 2014-07-18 19:40 ` David Bremner
2014-07-21 15:10 ` Alan Schmitt
0 siblings, 1 reply; 3+ messages in thread
From: David Bremner @ 2014-07-18 19:40 UTC (permalink / raw)
To: Alan Schmitt, notmuch
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Hello,
>
> I sometimes have to find a message knowing only its message id. I know
> how to use a notmuch search in emacs to find the message, then use
> another function to display it in gnus, but I would like to do it
> directly without going through the *notmuch-search* buffer.
>
> Right now I'm doing the following:
>
> #+begin_src emacs-lisp
> (defun as/msgid-to-gnus (msgid)
> "Search for the MSGID using notmuch, then open the message with
> gnus."
> (let ((file (shell-command-to-string (concat "notmuch search --output=files 'id:" msgid "'"))))
The structured output formats (sexp, json) include file names, so you
should be able to use something like the following
(defun notmuch-query-get-message-filenames (&rest search-terms)
"Return a list of message-ids of messages that match SEARCH-TERMS"
(notmuch-query-map-threads
(lambda (msg) (plist-get msg :filename))
(notmuch-query-get-threads search-terms)))
This is based on the example at the bottom of notmuch-query.el
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: using notmuch programmatically from emacs
2014-07-18 19:40 ` David Bremner
@ 2014-07-21 15:10 ` Alan Schmitt
0 siblings, 0 replies; 3+ messages in thread
From: Alan Schmitt @ 2014-07-21 15:10 UTC (permalink / raw)
To: David Bremner; +Cc: notmuch
[-- Attachment #1: Type: text/plain, Size: 2057 bytes --]
On 2014-07-18 21:40, David Bremner <david@tethera.net> writes:
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> Hello,
>>
>> I sometimes have to find a message knowing only its message id. I know
>> how to use a notmuch search in emacs to find the message, then use
>> another function to display it in gnus, but I would like to do it
>> directly without going through the *notmuch-search* buffer.
>>
>> Right now I'm doing the following:
>>
>> #+begin_src emacs-lisp
>> (defun as/msgid-to-gnus (msgid)
>> "Search for the MSGID using notmuch, then open the message with
>> gnus."
>> (let ((file (shell-command-to-string (concat "notmuch search --output=files 'id:" msgid "'"))))
>
> The structured output formats (sexp, json) include file names, so you
> should be able to use something like the following
>
> (defun notmuch-query-get-message-filenames (&rest search-terms)
> "Return a list of message-ids of messages that match SEARCH-TERMS"
> (notmuch-query-map-threads
> (lambda (msg) (plist-get msg :filename))
> (notmuch-query-get-threads search-terms)))
>
> This is based on the example at the bottom of notmuch-query.el
Thanks a lot, this put me on the right track. I had to slightly modify
your example as it returns every message in the thread (and not just
the matching one). So I first test for id, and the filter the list to
return only the matching message. Here is the code I wrote.
#+begin_src emacs-lisp
(defun notmuch-query-get-message-filenames (msgid)
"Return the message filename where the message id matches MSGID
and `nil' if no such message is found"
(car (remove nil
(notmuch-query-map-threads
(lambda (msg) (if (equal (plist-get msg :id) msgid)
(plist-get msg :filename)
nil))
(notmuch-query-get-threads (list (concat "id:" msgid)))))))
#+end_src
Thanks again,
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
[-- Attachment #2: Type: application/pgp-signature, Size: 494 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-07-21 20:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-18 13:09 using notmuch programmatically from emacs Alan Schmitt
2014-07-18 19:40 ` David Bremner
2014-07-21 15:10 ` Alan Schmitt
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).