Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 1675C431FC0 for ; Fri, 18 Jan 2013 08:04:25 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v43EK9lMjHjH for ; Fri, 18 Jan 2013 08:04:23 -0800 (PST) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 4F1C8431FD6 for ; Fri, 18 Jan 2013 08:04:18 -0800 (PST) Received: by mail-wi0-f175.google.com with SMTP id hm11so5372254wib.2 for ; Fri, 18 Jan 2013 08:04:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=PZJsaNl15a64PqWdNvMy5MhROJsArJxiu2ujkxVfLEY=; b=a+6GmVZyRiAxOx9P9GFardAbQm0pBbSLmPmBsi8g73mNVAK6tc5gGVPcECWPzTEUIR 9vHsjrOsXv6/hz2Sw0LqbE5o2ulthb+55TxYMalDd9Gk3fi+wnnfa+loROLlV+bx2Jrj i2gbaCnmGxnH9g4VxEp37oY4+YXknEaqdRNZ7BPfEA9bwTvEEBJmWvUd/i2r3lHUnD8M h4eR490JOKW3K7Ato6fRhc0ym6zM0Q9SnBAylJrhlrYAqhtLNm3iIe6s4zQXWgEGfdCg SweZxe3C04gzOteIUsZLLIloTmxPUuWAUX/SXsPvedi90fL29HrCVUFIu1/Whk430ohu CJ+A== X-Received: by 10.194.172.228 with SMTP id bf4mr15155624wjc.38.1358525057161; Fri, 18 Jan 2013 08:04:17 -0800 (PST) Received: from luz3.lille.inria.fr ([193.51.236.44]) by mx.google.com with ESMTPS id i2sm4073866wiw.3.2013.01.18.08.04.15 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Jan 2013 08:04:16 -0800 (PST) From: Damien Cassou To: notmuch mailing list Subject: [PATCH 4/4] emacs: provide convenience functions for notmuch-tagger configuration Date: Fri, 18 Jan 2013 17:03:58 +0100 Message-Id: <1358525039-13569-5-git-send-email-damien.cassou@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1358525039-13569-1-git-send-email-damien.cassou@gmail.com> References: <1358525039-13569-1-git-send-email-damien.cassou@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jan 2013 16:04:25 -0000 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 --- 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