[PATCH 3/4] emacs: possibility to customize the rendering of tags
authorDamien Cassou <damien.cassou@gmail.com>
Fri, 18 Jan 2013 16:03:57 +0000 (17:03 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:10 +0000 (09:53 -0800)
35/8289a326c231cc1dd8341fb0b6565ed17c088b [new file with mode: 0644]

diff --git a/35/8289a326c231cc1dd8341fb0b6565ed17c088b b/35/8289a326c231cc1dd8341fb0b6565ed17c088b
new file mode 100644 (file)
index 0000000..626c0ab
--- /dev/null
@@ -0,0 +1,231 @@
+Return-Path: <damien.cassou@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id B2B4E431FC7\r
+       for <notmuch@notmuchmail.org>; Fri, 18 Jan 2013 08:04:23 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id PajPoLpN0zHv for <notmuch@notmuchmail.org>;\r
+       Fri, 18 Jan 2013 08:04:20 -0800 (PST)\r
+Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
+       [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 08E10431FBD\r
+       for <notmuch@notmuchmail.org>; Fri, 18 Jan 2013 08:04:16 -0800 (PST)\r
+Received: by mail-wi0-f173.google.com with SMTP id hn17so5372406wib.6\r
+       for <notmuch@notmuchmail.org>; Fri, 18 Jan 2013 08:04:15 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
+       :references:mime-version:content-type:content-transfer-encoding;\r
+       bh=BSHBNDKgtZlDoHTPhclYOsZGKPit+swxFajCc5Q/S8U=;\r
+       b=ThTn+woO874YCyCENuYHqo5P0Bl0WbDCj/Ebsp8ikPu4Y/aQvcnoWUGrTmJ+kd4d1c\r
+       /T/7lBbogJ0RGJpDu+mxt+BQUUID3NMi/Hk+fOzX9M+KB6HVcwchub94yXo7YsXJ7zW5\r
+       tDpMjnRTAQzMOjbFyS8DSgYCv3ylEbFABQeW/cQqq8KnS1PxtTf6r8mT37AbAiRRKStP\r
+       vZf7rtzjDsfiEXwf/ol8/Tf6ZAhYmw1VnsUAUkA0DANHQzRr3IdfiQg2uP7iM8RSUW/i\r
+       6Qd2ly3fHqLs2Y4cslGfs0SRxj4UtBKxRxCZ3iCmqQlodk+y+zjFyPmUPn0oJ526/cYa\r
+       uX1A==\r
+X-Received: by 10.194.174.234 with SMTP id bv10mr15135530wjc.47.1358525055856;\r
+       Fri, 18 Jan 2013 08:04:15 -0800 (PST)\r
+Received: from luz3.lille.inria.fr ([193.51.236.44])\r
+       by mx.google.com with ESMTPS id i2sm4073866wiw.3.2013.01.18.08.04.14\r
+       (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);\r
+       Fri, 18 Jan 2013 08:04:15 -0800 (PST)\r
+From: Damien Cassou <damien.cassou@gmail.com>\r
+To: notmuch mailing list <notmuch@notmuchmail.org>\r
+Subject: [PATCH 3/4] emacs: possibility to customize the rendering of tags\r
+Date: Fri, 18 Jan 2013 17:03:57 +0100\r
+Message-Id: <1358525039-13569-4-git-send-email-damien.cassou@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1358525039-13569-1-git-send-email-damien.cassou@gmail.com>\r
+References: <1358525039-13569-1-git-send-email-damien.cassou@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 18 Jan 2013 16:04:24 -0000\r
+\r
+This patch extracts the rendering of tags in notmuch-show to a\r
+dedicated notmuch-tagger file.\r
+\r
+This new file introduces a `notmuch-tagger-formats' variable that\r
+associates each tag to a particular format. For example,\r
+\r
+(("unread"\r
+  (:propertize "unread" face\r
+               (:foreground "red")))\r
+ ("flagged"\r
+  (:propertize "flagged" display\r
+               (image :type svg :file "~/notmuch/emacs/resources/star.svg" :ascent center :mask heuristic))))\r
+\r
+associates a red font to the "unread" tag and a star picture to\r
+the "flagged" tag.\r
+\r
+In the future, I would like to use the Customization interface of\r
+Emacs to edit this variable and also to provide high-lever\r
+functions to manipulate it such\r
+that (notmuch-tagger-propertize "unread" :foreground "red")\r
+and (notmuch-tagger-picture "flagged" "star.svg").\r
+\r
+`mode-line-format' templates are used to represent the format for\r
+each tag. This is a concize format that can also be used in\r
+`header-line-format' if later desired.\r
+\r
+Signed-off-by: Damien Cassou <damien.cassou@gmail.com>\r
+---\r
+ emacs/notmuch-show.el   |    7 ++---\r
+ emacs/notmuch-tagger.el |   75 +++++++++++++++++++++++++++++++++++++++++++++++\r
+ emacs/notmuch.el        |    5 ++--\r
+ 3 files changed, 80 insertions(+), 7 deletions(-)\r
+ create mode 100644 emacs/notmuch-tagger.el\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 1864dd1..7bf9f3c 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -36,6 +36,7 @@\r
+ (require 'notmuch-mua)\r
+ (require 'notmuch-crypto)\r
+ (require 'notmuch-print)\r
++(require 'notmuch-tagger)\r
\r
+ (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))\r
+ (declare-function notmuch-fontify-headers "notmuch" nil)\r
+@@ -362,8 +363,7 @@ operation on the contents of the current buffer."\r
+     (if (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)\r
+       (let ((inhibit-read-only t))\r
+         (replace-match (concat "("\r
+-                               (propertize (mapconcat 'identity tags " ")\r
+-                                           'face 'notmuch-tag-face)\r
++                               (notmuch-tagger-present-tags tags)\r
+                                ")"))))))\r
\r
+ (defun notmuch-clean-address (address)\r
+@@ -441,8 +441,7 @@ message at DEPTH in the current thread."\r
+           " ("\r
+           date\r
+           ") ("\r
+-          (propertize (mapconcat 'identity tags " ")\r
+-                      'face 'notmuch-tag-face)\r
++          (notmuch-tagger-present-tags tags)\r
+           ")\n")\r
+     (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face)))\r
\r
+diff --git a/emacs/notmuch-tagger.el b/emacs/notmuch-tagger.el\r
+new file mode 100644\r
+index 0000000..90730f6\r
+--- /dev/null\r
++++ b/emacs/notmuch-tagger.el\r
+@@ -0,0 +1,75 @@\r
++;; notmuch-tagger.el --- Library to improve the way tags are displayed\r
++;;\r
++;; Copyright © Damien Cassou\r
++;;\r
++;; This file is part of Notmuch.\r
++;;\r
++;; Notmuch is free software: you can redistribute it and/or modify it\r
++;; under the terms of the GNU General Public License as published by\r
++;; the Free Software Foundation, either version 3 of the License, or\r
++;; (at your option) any later version.\r
++;;\r
++;; Notmuch is distributed in the hope that it will be useful, but\r
++;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
++;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
++;; General Public License for more details.\r
++;;\r
++;; You should have received a copy of the GNU General Public License\r
++;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
++;;\r
++;; Authors: Damien Cassou <damien.cassou@gmail.com>\r
++;;; Commentary:\r
++;;\r
++;;; Comments\r
++;;\r
++;;; Code:\r
++;;\r
++\r
++(require 'cl)\r
++\r
++(defvar notmuch-tagger-formats\r
++  `(("unread"\r
++     (:propertize "unread" face\r
++                  (:foreground "red")))\r
++    ("flagged"\r
++     (:propertize "flagged" display\r
++                  (image :type svg :file\r
++                         ,(expand-file-name\r
++                           "resources/star.svg"\r
++                           (file-name-directory\r
++                            (or\r
++                             (locate-library "notmuch-tagger")\r
++                             (buffer-file-name))))\r
++                         :ascent center :mask heuristic))))\r
++  "Contains pairs of (KEY FORMAT) to format a tag matching KEY.\r
++\r
++KEY must be a string with a tag name. In the future, KEY could\r
++also be a regexp or list of keys to be matched against tags.\r
++\r
++The default value set the unread tag to be red and the flagged\r
++tag to have a star picture attached. Those are just examples so\r
++you get an idea of what you can do.")\r
++\r
++(defun notmuch-tagger-tag-format (tag)\r
++  "Format TAG as a `mode-line-format' template.\r
++\r
++The format to apply to TAG is searched in\r
++`notmuch-tagger-formats'. If not found, the default\r
++`notmuch-tag-face' is used."\r
++  (let ((match (assoc tag notmuch-tagger-formats)))\r
++    (if match\r
++        (cadr match)\r
++      `(:propertize ,tag face notmuch-tag-face))))\r
++\r
++(defun notmuch-tagger-tags-format (tags)\r
++  "Format TAGS as a `mode-line-format' template."\r
++  (notmuch-intersperse\r
++   (remove nil (mapcar #'notmuch-tagger-tag-format tags))\r
++   " "))\r
++\r
++(defun notmuch-tagger-present-tags (tags)\r
++  "Return a string that represent TAGS with their format."\r
++  (format-mode-line (notmuch-tagger-tags-format tags)))\r
++\r
++(provide 'notmuch-tagger)\r
++;;; notmuch-tagger.el ends here\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index c98a4fe..c607905 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -797,9 +797,8 @@ non-authors is found, assume that all of the authors match."\r
+     (notmuch-search-insert-authors format-string (plist-get result :authors)))\r
\r
+    ((string-equal field "tags")\r
+-    (let ((tags-str (mapconcat 'identity (plist-get result :tags) " ")))\r
+-      (insert (propertize (format format-string tags-str)\r
+-                        'face 'notmuch-tag-face))))))\r
++    (let ((tags (plist-get result :tags)))\r
++      (insert (format format-string (notmuch-tagger-present-tags tags)))))))\r
\r
+ (defun notmuch-search-show-result (result &optional pos)\r
+   "Insert RESULT at POS or the end of the buffer if POS is null."\r
+-- \r
+1.7.10.4\r
+\r