From 3b0c205eb43b23fad4bf8617966b116a56fc4981 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Fri, 18 Jan 2013 17:03:57 +0100 Subject: [PATCH] [PATCH 3/4] emacs: possibility to customize the rendering of tags --- 35/8289a326c231cc1dd8341fb0b6565ed17c088b | 231 ++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 35/8289a326c231cc1dd8341fb0b6565ed17c088b diff --git a/35/8289a326c231cc1dd8341fb0b6565ed17c088b b/35/8289a326c231cc1dd8341fb0b6565ed17c088b new file mode 100644 index 000000000..626c0abc5 --- /dev/null +++ b/35/8289a326c231cc1dd8341fb0b6565ed17c088b @@ -0,0 +1,231 @@ +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 B2B4E431FC7 + for ; Fri, 18 Jan 2013 08:04:23 -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 PajPoLpN0zHv for ; + Fri, 18 Jan 2013 08:04:20 -0800 (PST) +Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com + [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 08E10431FBD + for ; Fri, 18 Jan 2013 08:04:16 -0800 (PST) +Received: by mail-wi0-f173.google.com with SMTP id hn17so5372406wib.6 + for ; Fri, 18 Jan 2013 08:04:15 -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:mime-version:content-type:content-transfer-encoding; + bh=BSHBNDKgtZlDoHTPhclYOsZGKPit+swxFajCc5Q/S8U=; + b=ThTn+woO874YCyCENuYHqo5P0Bl0WbDCj/Ebsp8ikPu4Y/aQvcnoWUGrTmJ+kd4d1c + /T/7lBbogJ0RGJpDu+mxt+BQUUID3NMi/Hk+fOzX9M+KB6HVcwchub94yXo7YsXJ7zW5 + tDpMjnRTAQzMOjbFyS8DSgYCv3ylEbFABQeW/cQqq8KnS1PxtTf6r8mT37AbAiRRKStP + vZf7rtzjDsfiEXwf/ol8/Tf6ZAhYmw1VnsUAUkA0DANHQzRr3IdfiQg2uP7iM8RSUW/i + 6Qd2ly3fHqLs2Y4cslGfs0SRxj4UtBKxRxCZ3iCmqQlodk+y+zjFyPmUPn0oJ526/cYa + uX1A== +X-Received: by 10.194.174.234 with SMTP id bv10mr15135530wjc.47.1358525055856; + Fri, 18 Jan 2013 08:04:15 -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.14 + (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); + Fri, 18 Jan 2013 08:04:15 -0800 (PST) +From: Damien Cassou +To: notmuch mailing list +Subject: [PATCH 3/4] emacs: possibility to customize the rendering of tags +Date: Fri, 18 Jan 2013 17:03:57 +0100 +Message-Id: <1358525039-13569-4-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> +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +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:24 -0000 + +This patch extracts the rendering of tags in notmuch-show to a +dedicated notmuch-tagger file. + +This new file introduces a `notmuch-tagger-formats' variable that +associates each tag to a particular format. For example, + +(("unread" + (:propertize "unread" face + (:foreground "red"))) + ("flagged" + (:propertize "flagged" display + (image :type svg :file "~/notmuch/emacs/resources/star.svg" :ascent center :mask heuristic)))) + +associates a red font to the "unread" tag and a star picture to +the "flagged" tag. + +In the future, I would like to use the Customization interface of +Emacs to edit this variable and also to provide high-lever +functions to manipulate it such +that (notmuch-tagger-propertize "unread" :foreground "red") +and (notmuch-tagger-picture "flagged" "star.svg"). + +`mode-line-format' templates are used to represent the format for +each tag. This is a concize format that can also be used in +`header-line-format' if later desired. + +Signed-off-by: Damien Cassou +--- + emacs/notmuch-show.el | 7 ++--- + emacs/notmuch-tagger.el | 75 +++++++++++++++++++++++++++++++++++++++++++++++ + emacs/notmuch.el | 5 ++-- + 3 files changed, 80 insertions(+), 7 deletions(-) + create mode 100644 emacs/notmuch-tagger.el + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index 1864dd1..7bf9f3c 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -36,6 +36,7 @@ + (require 'notmuch-mua) + (require 'notmuch-crypto) + (require 'notmuch-print) ++(require 'notmuch-tagger) + + (declare-function notmuch-call-notmuch-process "notmuch" (&rest args)) + (declare-function notmuch-fontify-headers "notmuch" nil) +@@ -362,8 +363,7 @@ operation on the contents of the current buffer." + (if (re-search-forward "(\\([^()]*\\))$" (line-end-position) t) + (let ((inhibit-read-only t)) + (replace-match (concat "(" +- (propertize (mapconcat 'identity tags " ") +- 'face 'notmuch-tag-face) ++ (notmuch-tagger-present-tags tags) + ")")))))) + + (defun notmuch-clean-address (address) +@@ -441,8 +441,7 @@ message at DEPTH in the current thread." + " (" + date + ") (" +- (propertize (mapconcat 'identity tags " ") +- 'face 'notmuch-tag-face) ++ (notmuch-tagger-present-tags tags) + ")\n") + (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face))) + +diff --git a/emacs/notmuch-tagger.el b/emacs/notmuch-tagger.el +new file mode 100644 +index 0000000..90730f6 +--- /dev/null ++++ b/emacs/notmuch-tagger.el +@@ -0,0 +1,75 @@ ++;; 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 . ++;; ++;; Authors: Damien Cassou ++;;; Commentary: ++;; ++;;; Comments ++;; ++;;; Code: ++;; ++ ++(require 'cl) ++ ++(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)))) ++ :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-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 +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index c98a4fe..c607905 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -797,9 +797,8 @@ non-authors is found, assume that all of the authors match." + (notmuch-search-insert-authors format-string (plist-get result :authors))) + + ((string-equal field "tags") +- (let ((tags-str (mapconcat 'identity (plist-get result :tags) " "))) +- (insert (propertize (format format-string tags-str) +- 'face 'notmuch-tag-face)))))) ++ (let ((tags (plist-get result :tags))) ++ (insert (format format-string (notmuch-tagger-present-tags tags))))))) + + (defun notmuch-search-show-result (result &optional pos) + "Insert RESULT at POS or the end of the buffer if POS is null." +-- +1.7.10.4 + -- 2.26.2