-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathakmuch-summarize.el
85 lines (76 loc) · 2.42 KB
/
akmuch-summarize.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
80
81
82
83
84
85
(defvar akmuch-summarize-buffer "*mail summary*")
(defun akmuch-summarize ()
(interactive)
(let ((sbuff akmuch-search-buffer))
(pop-to-buffer akmuch-summarize-buffer)
(akmuch-summary-mode)
(akmuch-summary-update)
(setq akmuch-search-buffer sbuff)))
(defun akmuch-summary-update ()
(with-current-buffer akmuch-summarize-buffer
(let ((terms akmuch-summary-terms)
(buffer-read-only nil)
psave)
(when (not (listp akmuch-summary-terms))
(message "no summary terms registered"))
(erase-buffer)
(save-excursion
(while terms
(insert (cdr (car terms)))
(insert "\n")
(setq terms (cdr terms)))
(shell-command-on-region
(point-min) (point-max)
"notmuch count --batch"
(current-buffer) t)
(goto-char (point-min))
(setq terms akmuch-summary-terms)
(while terms
(when (> (string-to-number
(buffer-substring (point) (point-at-eol))) 40)
(put-text-property (point) (point-at-eol)
'face 'font-lock-warning-face))
(insert (format "%-15s" (car (car terms))))
(forward-line 1)
(setq terms (cdr terms)))))))
(defun akmuch-summary-get-terms ()
(let (index terms i)
(save-excursion
(goto-char (point-at-bol))
(search-forward-regexp " ")
(forward-char -1)
(setq index (buffer-substring
(point-at-bol)
(point)))
(setq i akmuch-summary-terms)
(while i
(when (string= index (caar i))
(setq terms (cdar i)))
(setq i (cdr i))))
terms)
)
(defun akmuch-summary-search ()
(interactive)
(let ((terms (akmuch-summary-get-terms)))
(when (and terms akmuch-search-buffer)
(pop-to-buffer akmuch-search-buffer)
(akmuch-search terms))))
(defun akmuch-summary-next ()
(interactive)
(forward-line 1))
(defun akmuch-summary-prev ()
(interactive)
(forward-line -1))
(defvar akmuch-summary-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "RET") 'akmuch-summary-search)
(define-key map (kbd "n") 'akmuch-summary-next)
(define-key map (kbd "p") 'akmuch-summary-prev)
(define-key map (kbd "t") 'akmuch-summary-tag)
(define-key map (kbd "o") 'other-window)
map))
(define-derived-mode akmuch-summary-mode nil "Akmuch [summary]"
"Major mode for mail using notmuch (message buffers)"
(make-local-variable 'akmuch-search-buffer)
(setq buffer-read-only t))
(provide 'akmuch-summarize)