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
| | ;; notmuch-tagger.el --- Library to improve the way tags are displayed
;;
;; Copyright © Damien Cassou
;;
;; This file is part of Notmuch.
;;
;; Notmuch 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.
;;
;; Notmuch 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 Notmuch. If not, see <http://www.gnu.org/licenses/>.
;;
;; Authors: Damien Cassou <damien.cassou@gmail.com>
;;; Commentary:
;;
;;; Comments
;;
;; Example use:
;;
;; Capitalize the tag 'important' and set its color
;; (notmuch-tagger-rename "important" "Important" :foreground "red")
;;
;; Use a star icon for the 'starred' tag
;; (notmuch-tagger-image-star "starred")
;;
;;; Code:
;;
(require 'cl)
(defun notmuch-tagger-image-path (image)
"Get full path for IMAGE name in the resources/ sub-directory."
(expand-file-name
image
(expand-file-name "resources"
(file-name-directory
(or
(locate-library "notmuch-tagger")
(buffer-file-name))))))
(defvar notmuch-tagger-formats
`(("unread"
(:propertize "unread" face
(:foreground "red")))
("flagged"
(:propertize "flagged" display
(image :type svg
:file ,(notmuch-tagger-image-path "star.svg")
:ascent center :mask heuristic))))
"Contains pairs of (KEY FORMAT) to format a tag matching KEY.
KEY must be a string with a tag name. In the future, KEY could
also be a regexp or list of keys to be matched against tags.
The default value set the unread tag to be red and the flagged
tag to have a star picture attached. Those are just examples so
you get an idea of what you can do.")
(defun notmuch-tagger-set-format (key format)
"Set that tags matched by KEY must be displayed using FORMAT.
This function updates `notmuch-tagger-formats' according to its
parameters.
Instead of calling this function, use one of the higher-level
ones like `notmuch-tagger-rename', `notmuch-tagger-propertize',
`notmuch-tagger-hide', and `notmuch-tagger-image'."
(let ((pair (assoc key notmuch-tagger-formats)))
(if pair
(setf (cdr pair) (list format))
(add-to-list 'notmuch-tagger-formats (list key format)))))
(defun notmuch-tagger-rename (key new-name &rest face)
"Display tags matching KEY as NEW-NAME with a particular FACE.
Use this function like this:
\(notmuch-tagger-rename \"draft\" \"Draft\" :foreground \"red\")
This will present the draft tag with a capital and in red."
(notmuch-tagger-set-format key
`(:propertize ,new-name face ,(or face 'notmuch-tag-face))))
(defun notmuch-tagger-propertize (key &rest face)
"Render tags matching KEY with a particular face.
Use this function like this:
\(notmuch-tagger-propertize \"draft\" :foreground \"red\")
This will present the draft tag in red."
(apply 'notmuch-tagger-rename key key face))
(defun notmuch-tagger-hide (key)
"Hide tags matching KEY."
(notmuch-tagger-set-format key nil))
(defun notmuch-tagger-image (key file type)
"Show tags matching KEY as images taken from FILE with type TYPE.
See Info node `(elisp)Image Formats' for possible values for
TYPE (e.g., 'svg and 'png).
There is a set of predefined pictures that you can use by calling
functions like `notmuch-tagger-image-star' and
`notmuch-tagger-image-tag'."
(notmuch-tagger-set-format
key
`(:propertize ,key display
(image :type ,type
:file ,file
:ascent center
:mask heuristic))))
(defun notmuch-tagger-provided-image (key image)
"Show tags matching KEY as IMAGE provided by notmuch-tagger."
(notmuch-tagger-image
key
(notmuch-tagger-image-path image)
(intern (file-name-extension image))))
(defun notmuch-tagger-image-star (key)
"Show tags matching KEY as resources/star.svg."
(notmuch-tagger-provided-image key "star.svg"))
(defun notmuch-tagger-image-star-empty (key)
"Show tags matching KEY as resources/star-empty.svg."
(notmuch-tagger-provided-image key "star-empty.svg"))
(defun notmuch-tagger-image-tag (tag)
"Show tags matching KEY as resources/tag.svg."
(notmuch-tagger-provided-image tag "tag.svg"))
(defun notmuch-tagger-tag-format (tag)
"Format TAG as a `mode-line-format' template.
The format to apply to TAG is searched in
`notmuch-tagger-formats'. If not found, the default
`notmuch-tag-face' is used."
(let ((match (assoc tag notmuch-tagger-formats)))
(if match
(cadr match)
`(:propertize ,tag face notmuch-tag-face))))
(defun notmuch-tagger-tags-format (tags)
"Format TAGS as a `mode-line-format' template."
(notmuch-intersperse
(remove nil (mapcar #'notmuch-tagger-tag-format tags))
" "))
(defun notmuch-tagger-present-tags (tags)
"Return a string that represent TAGS with their format."
(format-mode-line (notmuch-tagger-tags-format tags)))
(provide 'notmuch-tagger)
;;; notmuch-tagger.el ends here
|