config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

notmuch-query.el (2528B)


      1 ;;; notmuch-query.el --- provide an emacs api to query notmuch  -*- lexical-binding: t -*-
      2 ;;
      3 ;; Copyright © David Bremner
      4 ;;
      5 ;; This file is part of Notmuch.
      6 ;;
      7 ;; Notmuch is free software: you can redistribute it and/or modify it
      8 ;; under the terms of the GNU General Public License as published by
      9 ;; the Free Software Foundation, either version 3 of the License, or
     10 ;; (at your option) any later version.
     11 ;;
     12 ;; Notmuch is distributed in the hope that it will be useful, but
     13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
     14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15 ;; General Public License for more details.
     16 ;;
     17 ;; You should have received a copy of the GNU General Public License
     18 ;; along with Notmuch.  If not, see <https://www.gnu.org/licenses/>.
     19 ;;
     20 ;; Authors: David Bremner <david@tethera.net>
     21 
     22 ;;; Code:
     23 
     24 (require 'notmuch-lib)
     25 
     26 ;;; Basic query function
     27 
     28 (define-obsolete-function-alias
     29   'notmuch-query-get-threads
     30   #'notmuch--run-show
     31   "notmuch 0.37")
     32 
     33 ;;; Mapping functions across collections of messages
     34 
     35 (defun notmuch-query-map-aux  (mapper function seq)
     36   "Private function to do the actual mapping and flattening."
     37   (cl-mapcan (lambda (tree)
     38 	       (funcall mapper function tree))
     39 	     seq))
     40 
     41 (defun notmuch-query-map-threads (fn threads)
     42   "Apply function FN to every thread in THREADS.
     43 Flatten results to a list.  See the function
     44 `notmuch-query-get-threads' for more information."
     45   (notmuch-query-map-aux 'notmuch-query-map-forest fn threads))
     46 
     47 (defun notmuch-query-map-forest (fn forest)
     48   "Apply function FN to every message in FOREST.
     49 Flatten results to a list.  See the function
     50 `notmuch-query-get-threads' for more information."
     51   (notmuch-query-map-aux 'notmuch-query-map-tree fn forest))
     52 
     53 (defun notmuch-query-map-tree (fn tree)
     54   "Apply function FN to every message in TREE.
     55 Flatten results to a list.  See the function
     56 `notmuch--run-show' for more information."
     57   (cons (funcall fn (car tree))
     58 	(notmuch-query-map-forest fn (cadr tree))))
     59 
     60 ;;; Predefined queries
     61 
     62 (defun notmuch-query-get-message-ids (&rest search-terms)
     63   "Return a list of message-ids of messages that match SEARCH-TERMS."
     64   (notmuch-query-map-threads
     65    (lambda (msg) (plist-get msg :id))
     66    (notmuch--run-show search-terms)))
     67 
     68 ;;; Everything in this library is obsolete
     69 (dolist (fun '(map-aux map-threads map-forest map-tree get-message-ids))
     70   (make-obsolete (intern (format "notmuch-query-%s" fun)) nil "notmuch 0.37"))
     71 
     72 (provide 'notmuch-query)
     73 
     74 ;;; notmuch-query.el ends here