This patch adds functions like `notmuch-tagger-rename',
`notmuch-tagger-hide', and `notmuch-tagger-image-star' to facilitate
the manipulation of `notmuch-tagger-formats'. For example, a typical
.init.el file would contain:

    ;; 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")

Signed-off-by: Damien Cassou <damien.cassou at gmail.com>
---
 emacs/notmuch-tagger.el |  101 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 94 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-tagger.el b/emacs/notmuch-tagger.el
index 90730f6..f798757 100644
--- a/emacs/notmuch-tagger.el
+++ b/emacs/notmuch-tagger.el
@@ -22,24 +22,37 @@
 ;;
 ;;; 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
-                         ,(expand-file-name
-                           "resources/star.svg"
-                           (file-name-directory
-                            (or
-                             (locate-library "notmuch-tagger")
-                             (buffer-file-name))))
+                  (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.

@@ -50,6 +63,80 @@ 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.

-- 
1.7.10.4

Reply via email to