2021-01-10 15:00:47 +01:00
|
|
|
;;; notmuch-query.el --- provide an emacs api to query notmuch -*- lexical-binding: t -*-
|
2010-04-05 18:46:16 +02:00
|
|
|
;;
|
|
|
|
;; Copyright © David Bremner
|
|
|
|
;;
|
|
|
|
;; This file is part of Notmuch.
|
|
|
|
;;
|
|
|
|
;; Notmuch is free software: you can redistribute it and/or modify it
|
|
|
|
;; under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; Notmuch is distributed in the hope that it will be useful, but
|
|
|
|
;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
;; General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2016-06-02 18:26:14 +02:00
|
|
|
;; along with Notmuch. If not, see <https://www.gnu.org/licenses/>.
|
2010-04-05 18:46:16 +02:00
|
|
|
;;
|
|
|
|
;; Authors: David Bremner <david@tethera.net>
|
|
|
|
|
2016-04-13 09:58:47 +02:00
|
|
|
;;; Code:
|
|
|
|
|
2010-04-05 18:46:16 +02:00
|
|
|
(require 'notmuch-lib)
|
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Basic query function
|
|
|
|
|
2011-05-26 03:01:19 +02:00
|
|
|
(defun notmuch-query-get-threads (search-terms)
|
2010-04-05 18:46:16 +02:00
|
|
|
"Return a list of threads of messages matching SEARCH-TERMS.
|
|
|
|
|
|
|
|
A thread is a forest or list of trees. A tree is a two element
|
|
|
|
list where the first element is a message, and the second element
|
2020-05-24 21:17:56 +02:00
|
|
|
is a possibly empty forest of replies."
|
2017-06-03 19:47:34 +02:00
|
|
|
(let ((args '("show" "--format=sexp" "--format-version=4")))
|
2020-08-08 13:49:43 +02:00
|
|
|
(when notmuch-show-process-crypto
|
|
|
|
(setq args (append args '("--decrypt=true"))))
|
2011-05-26 03:01:19 +02:00
|
|
|
(setq args (append args search-terms))
|
2013-06-24 01:43:18 +02:00
|
|
|
(apply #'notmuch-call-notmuch-sexp args)))
|
2010-04-05 18:46:16 +02:00
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Mapping functions across collections of messages
|
2010-04-05 18:46:16 +02:00
|
|
|
|
|
|
|
(defun notmuch-query-map-aux (mapper function seq)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Private function to do the actual mapping and flattening."
|
2021-01-13 18:37:50 +01:00
|
|
|
(cl-mapcan (lambda (tree)
|
|
|
|
(funcall mapper function tree))
|
|
|
|
seq))
|
2010-04-05 18:46:16 +02:00
|
|
|
|
|
|
|
(defun notmuch-query-map-threads (fn threads)
|
2020-08-08 13:49:50 +02:00
|
|
|
"Apply function FN to every thread in THREADS.
|
|
|
|
Flatten results to a list. See the function
|
|
|
|
`notmuch-query-get-threads' for more information."
|
2010-04-05 18:46:16 +02:00
|
|
|
(notmuch-query-map-aux 'notmuch-query-map-forest fn threads))
|
|
|
|
|
|
|
|
(defun notmuch-query-map-forest (fn forest)
|
2020-08-08 13:49:50 +02:00
|
|
|
"Apply function FN to every message in FOREST.
|
|
|
|
Flatten results to a list. See the function
|
|
|
|
`notmuch-query-get-threads' for more information."
|
2010-04-05 18:46:16 +02:00
|
|
|
(notmuch-query-map-aux 'notmuch-query-map-tree fn forest))
|
|
|
|
|
|
|
|
(defun notmuch-query-map-tree (fn tree)
|
2020-08-08 13:49:50 +02:00
|
|
|
"Apply function FN to every message in TREE.
|
|
|
|
Flatten results to a list. See the function
|
|
|
|
`notmuch-query-get-threads' for more information."
|
2021-01-13 18:37:50 +01:00
|
|
|
(cons (funcall fn (car tree))
|
|
|
|
(notmuch-query-map-forest fn (cadr tree))))
|
2010-04-05 18:46:16 +02:00
|
|
|
|
emacs: make headings outline-minor-mode compatible
`outline-minor-mode' treats comments that begin with three or more
semicolons as headings. That makes it very convenient to navigate
code and to show/hide parts of a file.
Elips libraries typically have four top-level sections, e.g.:
;;; notmuch.el --- run notmuch within emacs...
;;; Commentary:...
;;; Code:...
;;; notmuch.el ends here
In this package many libraries lack a "Commentary:" section, which is
not optimal but okay for most libraries, except major entry points.
Depending on how one chooses to look at it, the "... ends here" line
is not really a heading that begins a section, because it should never
have a "section" body (after all it marks eof).
If the file is rather short, then I left "Code:" as the only section
that contains code. Otherwise I split the file into multiple sibling
sections. The "Code:" section continues to contain `require' and
`declare-function' forms and other such "front matter".
If and only if I have split the code into multiple sections anyway,
then I also added an additional section named just "_" before the
`provide' form and shortly before the "...end here" line. This
section could also be called "Back matter", but I feel it would be
distracting to be that explicit about it. (The IMO unnecessary but
unfortunately still obligatory "... ends here" line is already
distracting enough as far as I am concerned.)
Before this commit some libraries already uses section headings, some
of them consistently. When a library already had some headings, then
this commit often sticks to that style, even at the cost inconsistent
styling across all libraries.
A very limited number of variable and function definitions have to be
moved around because they would otherwise end up in sections they do
not belong into.
Sections, including but not limited to their heading, can and should
be further improved in the future.
2021-01-10 15:00:46 +01:00
|
|
|
;;; Predefined queries
|
2010-04-05 18:46:16 +02:00
|
|
|
|
|
|
|
(defun notmuch-query-get-message-ids (&rest search-terms)
|
2020-05-24 21:17:56 +02:00
|
|
|
"Return a list of message-ids of messages that match SEARCH-TERMS."
|
2010-04-05 18:46:16 +02:00
|
|
|
(notmuch-query-map-threads
|
|
|
|
(lambda (msg) (plist-get msg :id))
|
|
|
|
(notmuch-query-get-threads search-terms)))
|
|
|
|
|
|
|
|
(provide 'notmuch-query)
|
2016-04-13 09:58:47 +02:00
|
|
|
|
|
|
|
;;; notmuch-query.el ends here
|