This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
el-secretario-notmuch.el
79 lines (74 loc) · 3.03 KB
/
el-secretario-notmuch.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;;; el-secretario-notmuch.el Notmuch implementation for el-secretario -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2020 Leo
;;
;; Author: Leo Okawa Ericson <http://github/Zetagon>
;; Maintainer: Leo <[email protected]>
;; Created: September 20, 2020
;; Modified: October 17, 2020
;; Version: 0.0.1
;; Keywords:
;; Homepage: https://github.com/Zetagon/el-secretario
;; Package-Requires: ((emacs 26.1) (cl-lib "0.5") (hydra "0.15.0")(org-ql "0.6-pre"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;;
;;
;;; Code:
(defun el-secretario-notmuch-make-source (query &optional next-item-hook hydra)
"Convenience macro for creating a source for notmuch mail.
QUERY is a normal notmuch query.
NEXT-ITEM-HOOk is called on each heading.
HYDRA is an hydra to use during review of this source"
(make-el-secretario-source
:init-function (lambda () (el-secretario--notmuch-init query))
:next-function #'el-secretario--notmuch-show-next-thread
:prev-function #'notmuch-show-previous-thread-show
:hydra-body (or hydra #'el-secretario-default-hydra/body)
:finished-hook (lambda ())
:next-item-hook (or next-item-hook (lambda ()))) )
(defun el-secretario--notmuch-init (&optional query)
(notmuch-search (or query "tag:unread")
't
nil
0
nil)
(notmuch-search-first-thread)
(sit-for 0.1)
(el-secretario--notmuch-search-show-thread)
(funcall (el-secretario-source-hydra-body
(car el-secretario-current-source-list))))
(defun el-secretario--notmuch-show-next-thread (&optional previous)
"Like `notmuch-show-next-thread' but call `el-secretario--notmuch-search-show-thread' instead"
(interactive "P")
(let ((parent-buffer notmuch-show-parent-buffer))
(notmuch-bury-or-kill-this-buffer)
(when (buffer-live-p parent-buffer)
(switch-to-buffer parent-buffer)
(and (if previous
(notmuch-search-previous-thread)
(notmuch-search-next-thread))
(el-secretario--notmuch-search-show-thread)))))
(defun el-secretario--notmuch-search-show-thread (&optional elide-toggle)
"Like `notmuch-search-show-thread' but call `el-secretario--next-source' if there are no more mail."
(interactive "P")
(let ((thread-id (notmuch-search-find-thread-id))
(subject (notmuch-search-find-subject)))
(if (> (length thread-id) 0)
(progn (notmuch-show thread-id
elide-toggle
(current-buffer)
notmuch-search-query-string
;; Name the buffer based on the subject.
(concat "*"
(truncate-string-to-width subject 30 nil nil t)
"*"))
(funcall (el-secretario-source-hydra-body
(car el-secretario-current-source-list))))
(message "End of search results.")
(el-secretario--next-source))))
(provide 'el-secretario-notmuch)
;;; el-secretario-notmuch.el ends here