]> git.notmuchmail.org Git - notmuch/blob - emacs/notmuch-lib.el
emacs: Add a notmuch-saved-searches function.
[notmuch] / emacs / notmuch-lib.el
1 ;; notmuch-lib.el --- common variables, functions and function declarations
2 ;;
3 ;; Copyright © Carl Worth
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 <http://www.gnu.org/licenses/>.
19 ;;
20 ;; Authors: Carl Worth <cworth@cworth.org>
21
22 ;; This is an part of an emacs-based interface to the notmuch mail system.
23
24 (defvar notmuch-command "notmuch"
25   "Command to run the notmuch binary.")
26
27 (defgroup notmuch nil
28   "Notmuch mail reader for Emacs."
29   :group 'mail)
30
31 (defcustom notmuch-folders '(("inbox" . "tag:inbox") ("unread" . "tag:unread"))
32   "List of searches for the notmuch folder view"
33   :type '(alist :key-type (string) :value-type (string))
34   :group 'notmuch)
35
36 (defcustom notmuch-search-oldest-first t
37   "Show the oldest mail first when searching."
38   :type 'boolean
39   :group 'notmuch)
40
41 ;;
42
43 (defcustom notmuch-saved-searches nil
44   "A list of saved searches to display."
45   :type '(alist :key-type string :value-type string)
46   :group 'notmuch)
47
48 (defun notmuch-saved-searches ()
49   "Common function for querying the notmuch-saved-searches variable.
50
51 We do this as a function to support the old name of the
52 variable (`notmuch-folders') as well as for the default value if
53 the user hasn't set this variable with the old or new value."
54   (if notmuch-saved-searches
55       notmuch-saved-searches
56     (if notmuch-folders
57         notmuch-folders
58       '(("inbox" . "tag:inbox")
59         ("unread" . "tag:unread")))))
60
61 (defun notmuch-version ()
62   "Return a string with the notmuch version number."
63   (let ((long-string
64          ;; Trim off the trailing newline.
65          (substring (shell-command-to-string
66                      (concat notmuch-command " --version"))
67                     0 -1)))
68     (if (string-match "^notmuch\\( version\\)? \\(.*\\)$"
69                       long-string)
70         (match-string 2 long-string)
71       "unknown")))
72
73 ;;
74
75 ;; XXX: This should be a generic function in emacs somewhere, not
76 ;; here.
77 (defun point-invisible-p ()
78   "Return whether the character at point is invisible.
79
80 Here visibility is determined by `buffer-invisibility-spec' and
81 the invisible property of any overlays for point. It doesn't have
82 anything to do with whether point is currently being displayed
83 within the current window."
84   (let ((prop (get-char-property (point) 'invisible)))
85     (if (eq buffer-invisibility-spec t)
86         prop
87       (or (memq prop buffer-invisibility-spec)
88           (assq prop buffer-invisibility-spec)))))
89
90 (provide 'notmuch-lib)