blob: 22562596a301f56151aef37c03bf4d1653baa93e (
plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
;;; evil-collection-notmuch.el --- Bindings for `notmuch' -*- lexical-binding: t -*-
;; Copyright (C) 2017 James Nguyen
;; Author: James Nguyen <james@jojojames.com>
;; Maintainer: James Nguyen <james@jojojames.com>
;; Pierre Neidhardt <mail@ambrevar.xyz>
;; URL: https://github.com/emacs-evil/evil-collection
;; Version: 0.0.1
;; Package-Requires: ((emacs "26.3"))
;; Keywords: emacs, tools, evil
;; This program 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.
;; This program 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
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Bindings for `notmuch'.
;;; Code:
(require 'notmuch nil t)
(require 'evil-collection)
(defcustom evil-collection-notmuch-delete-tag "deleted"
"Tag toggled by the delete bindings (`d') in notmuch modes.
Defaults to \"deleted\" for backwards compatibility with the self-hosted
notmuch convention where a cron job removes files matching `tag:deleted'.
Set to \"trash\" when syncing with services that map a Trash tag/label
back to the server (e.g. lieer/Gmail's TRASH label, or an IMAP setup
that moves trashed messages out of the inbox)."
:type 'string
:group 'evil-collection-notmuch)
(declare-function notmuch-show-get-tags "notmuch-show")
(declare-function notmuch-show-tag "notmuch-show")
(declare-function notmuch-search-get-tags "notmuch")
(declare-function notmuch-search-tag "notmuch")
(declare-function notmuch-tree-tag "notmuch-tree")
(declare-function widget-field-at "wid-edit")
(declare-function widget-field-activate "wid-edit")
(declare-function widget-button-press "wid-edit")
;; Since all the other maps in `evil-collection-notmuch-maps`
;; have notmuch-common-keymap as parent
;; https://git.notmuchmail.org/git?p=notmuch;a=blob;f=emacs/notmuch-hello.el;h=fa31694ff0f79a7f2781849394390a673f75aade;hb=HEAD#l651
;;
;; When `evil-collection-setup-hook` runs, if it changes keymaps
;; using a `dolist` over `evil-collection-notmuch-maps`, then a binding might
;; see 2 changes at once. To avoid that, notmuch-common-keymap is last
(defconst evil-collection-notmuch-maps '(notmuch-hello-mode-map
notmuch-show-mode-map
notmuch-show-part-map
notmuch-tree-mode-map
notmuch-search-mode-map
notmuch-search-stash-map
notmuch-common-keymap))
(defun evil-collection-notmuch-toggle-tag (tag mode &optional next-function)
"Toggle TAG tag for message in MODE."
(let ((get (intern (format "notmuch-%s-get-tags" mode)))
(set (intern (format "notmuch-%s-tag" mode)))
(next (or next-function (intern (format "notmuch-%s-next-message" mode)))))
(funcall set (list (concat (if (member tag (funcall get))
"-" "+")
tag)))
(funcall next)))
(defun evil-collection-notmuch-show-toggle-delete ()
"Toggle `evil-collection-notmuch-delete-tag' for message."
(interactive)
(evil-collection-notmuch-toggle-tag evil-collection-notmuch-delete-tag "show"))
(defun evil-collection-notmuch-tree-toggle-delete ()
"Toggle `evil-collection-notmuch-delete-tag' for message."
(interactive)
(evil-collection-notmuch-toggle-tag evil-collection-notmuch-delete-tag "tree"))
(defun evil-collection-notmuch-search-toggle-delete ()
"Toggle `evil-collection-notmuch-delete-tag' for message."
(interactive)
(evil-collection-notmuch-toggle-tag evil-collection-notmuch-delete-tag "search" 'notmuch-search-next-thread))
(defun evil-collection-notmuch-tree-toggle-unread ()
"Toggle unread tag for message."
(interactive)
(evil-collection-notmuch-toggle-tag "unread" "tree"))
(defun evil-collection-notmuch-search-toggle-unread ()
"Toggle unread tag for message."
(interactive)
(evil-collection-notmuch-toggle-tag "unread" "search" 'notmuch-search-next-thread))
(defun evil-collection-notmuch-show-toggle-flagged ()
"Toggle flagged tag for message."
(interactive)
(evil-collection-notmuch-toggle-tag "flagged" "show"))
(defun evil-collection-notmuch-tree-toggle-flagged ()
"Toggle flagged tag for message."
(interactive)
(evil-collection-notmuch-toggle-tag "flagged" "tree"))
(defun evil-collection-notmuch-search-toggle-flagged ()
"Toggle flagged tag for message."
(interactive)
(evil-collection-notmuch-toggle-tag "flagged" "search" 'notmuch-search-next-thread))
(defun evil-collection-notmuch-hello-ret ()
(interactive)
(if (widget-field-at (point))
(call-interactively #'widget-field-activate)
(call-interactively #'widget-button-press)))
;;;###autoload
(defun evil-collection-notmuch-setup ()
"Set up `evil' bindings for `notmuch'."
(evil-collection-inhibit-insert-state 'notmuch-show-mode-map)
(evil-collection-inhibit-insert-state 'notmuch-search-mode-map)
(evil-collection-inhibit-insert-state 'notmuch-tree-mode-map)
(evil-set-initial-state 'notmuch-show-mode 'normal)
(evil-set-initial-state 'notmuch-search-mode 'normal)
(evil-set-initial-state 'notmuch-hello-mode 'normal)
(evil-set-initial-state 'notmuch-tree-mode 'normal)
(evil-collection-define-key 'normal 'notmuch-common-keymap
"g?" 'notmuch-help
"q" 'notmuch-bury-or-kill-this-buffer
"s" 'notmuch-search
"S" 'notmuch-tree
"C" 'notmuch-mua-new-mail ; like mu4e
"cc" 'notmuch-mua-new-mail ; like mu4e
"gr" 'notmuch-refresh-this-buffer
"gA" 'notmuch-refresh-all-buffers
"gR" 'notmuch-poll-and-refresh-this-buffer
"J" 'notmuch-jump-search)
(evil-collection-define-key 'normal 'notmuch-hello-mode-map
"g?" 'notmuch-version
(kbd "TAB") 'widget-forward
(kbd "RET") 'evil-collection-notmuch-hello-ret
(kbd "S-TAB") 'widget-backward
(kbd "<C-tab>") 'widget-backward)
(evil-collection-define-key 'normal 'notmuch-show-mode-map
"gd" 'goto-address-at-point
"p" 'notmuch-show-save-attachments ; like mu4e
"A" 'notmuch-show-archive-thread-then-next
"S" 'notmuch-show-filter-thread
"K" 'notmuch-tag-jump
"C" 'notmuch-mua-new-mail ; like mu4e
"cc" 'notmuch-mua-new-mail ; like mu4e
"cR" 'notmuch-show-reply
"cf" 'notmuch-show-forward-message
"X" 'notmuch-show-archive-thread-then-exit
"zv" 'notmuch-tree-from-show-current-query ; like mu4e-conversation
"<" 'notmuch-show-toggle-thread-indentation
"a" 'notmuch-show-archive-message-then-next-or-next-thread
"d" 'evil-collection-notmuch-show-toggle-delete
"=" 'evil-collection-notmuch-show-toggle-flagged
"H" 'notmuch-show-toggle-visibility-headers
"gj" 'notmuch-show-next-open-message
"gk" 'notmuch-show-previous-open-message
"]]" 'notmuch-show-next-message
"[[" 'notmuch-show-previous-message
(kbd "C-j") 'notmuch-show-next-message
(kbd "C-k") 'notmuch-show-previous-message
(kbd "M-j") 'notmuch-show-next-thread-show
(kbd "M-k") 'notmuch-show-previous-thread-show
"cr" 'notmuch-show-reply-sender
(kbd "x") 'notmuch-show-archive-message-then-next-or-exit
"|" 'notmuch-show-pipe-message
"*" 'notmuch-show-tag-all
"-" 'notmuch-show-remove-tag
"+" 'notmuch-show-add-tag
(kbd "TAB") 'notmuch-show-next-button
(kbd "<backtab>") 'notmuch-show-previous-button
(kbd "RET") 'notmuch-show-toggle-message
"." 'notmuch-show-part-map)
(evil-collection-define-key 'normal 'notmuch-tree-mode-map
"g?" 'notmuch-help
"q" 'notmuch-tree-quit
"S" 'notmuch-tree-to-search
"C" 'notmuch-mua-new-mail ; like mu4e
"cc" 'notmuch-mua-new-mail ; like mu4e
"J" 'notmuch-jump-search
"zv" 'notmuch-search-from-tree-current-query ; like mu4e-conversation
"cr" 'notmuch-show-reply-sender ; like mu4e
"cR" 'notmuch-show-reply
"d" 'evil-collection-notmuch-tree-toggle-delete
"!" 'evil-collection-notmuch-tree-toggle-unread
"=" 'evil-collection-notmuch-tree-toggle-flagged
"K" 'notmuch-tag-jump
(kbd "RET") 'notmuch-tree-show-message
[mouse-1] 'notmuch-tree-show-message
"A" 'notmuch-tree-archive-thread-then-next
"a" 'notmuch-tree-archive-message-then-next
"s" 'notmuch-tree-to-tree
"gj" 'notmuch-tree-next-matching-message
"gk" 'notmuch-tree-prev-matching-message
"]]" 'notmuch-tree-next-message
"[[" 'notmuch-tree-prev-message
(kbd "C-k") 'notmuch-tree-prev-thread
(kbd "C-j") 'notmuch-tree-next-thread
"|" 'notmuch-show-pipe-message
"-" 'notmuch-tree-remove-tag
"+" 'notmuch-tree-add-tag
"*" 'notmuch-tree-tag-thread
"e" 'notmuch-tree-resume-message)
(dolist (state '(normal visual))
(evil-collection-define-key state 'notmuch-search-mode-map
"cC" 'compose-mail-other-frame
"J" 'notmuch-jump-search
"S" 'notmuch-search-filter
"K" 'notmuch-tag-jump
"o" 'notmuch-search-toggle-order
"zv" 'notmuch-tree-from-search-current-query
"*" 'notmuch-search-tag-all
"a" 'notmuch-search-archive-thread
"cc" 'compose-mail ; like mu4e
"d" 'evil-collection-notmuch-search-toggle-delete
"!" 'evil-collection-notmuch-search-toggle-unread
"=" 'evil-collection-notmuch-search-toggle-flagged
"q" 'notmuch-bury-or-kill-this-buffer
"cr" 'notmuch-search-reply-to-thread-sender
"cR" 'notmuch-search-reply-to-thread
"t" 'notmuch-search-filter-by-tag
[mouse-1] 'notmuch-search-show-thread
"-" 'notmuch-search-remove-tag
"+" 'notmuch-search-add-tag
(kbd "RET") 'notmuch-search-show-thread))
;; ys
(evil-collection-define-operator-key 'yank 'notmuch-search-mode-map
"s" 'notmuch-search-stash-map)
;; ys
(evil-collection-define-operator-key 'yank 'notmuch-show-mode-map
"s" 'notmuch-show-stash-map))
(provide 'evil-collection-notmuch)
;;; evil-collection-notmuch.el ends here
|