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 C8802431FD0 for ; Tue, 27 Dec 2011 09:13:32 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 9gUAIMBs-Ow7 for ; Tue, 27 Dec 2011 09:13:32 -0800 (PST) Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id CD509431FB6 for ; Tue, 27 Dec 2011 09:13:31 -0800 (PST) Received: by wgbds13 with SMTP id ds13so17492224wgb.2 for ; Tue, 27 Dec 2011 09:13:30 -0800 (PST) Received: by 10.227.208.134 with SMTP id gc6mr28160473wbb.3.1325006010527; Tue, 27 Dec 2011 09:13:30 -0800 (PST) Received: from hotblack-desiato.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25]) by mx.google.com with ESMTPS id fy5sm67223800wib.7.2011.12.27.09.13.28 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Dec 2011 09:13:29 -0800 (PST) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id 8BB6CA07D5; Tue, 27 Dec 2011 17:13:27 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Add `notmuch-show-line-faces' and apply it. Date: Tue, 27 Dec 2011 17:13:23 +0000 Message-Id: <1325006003-27152-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.7.3 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: Tue, 27 Dec 2011 17:13:33 -0000 Similar to `notmuch-search-line-faces', `notmuch-show-line-faces' allows the header line in `notmuch-show-mode' buffers to be coloured according to the tags of the message. --- emacs/notmuch-lib.el | 18 ++++++++++++++++++ emacs/notmuch-show.el | 32 ++++++++++++++++++++++++++++---- emacs/notmuch.el | 17 ++--------------- 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 0f856bf..1f00fe0 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -96,6 +96,24 @@ the user hasn't set this variable with the old or new value." (interactive) (kill-buffer (current-buffer))) +(defun notmuch-color-line (start end line-tag-list spec) + "Colorize a line based on tags." + ;; Create the overlay only if the message has tags which match one + ;; of those specified in `spec'. + (let (overlay) + (mapc (lambda (elem) + (let ((tag (car elem)) + (attributes (cdr elem))) + (when (member tag line-tag-list) + (when (not overlay) + (setq overlay (make-overlay start end)) + (overlay-put overlay 'priority 5)) + ;; Merge the specified properties with any already + ;; applied from an earlier match. + (overlay-put overlay 'face + (append (overlay-get overlay 'face) attributes))))) + spec))) + ;; (defun notmuch-common-do-stash (text) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 24f0b40..0885bd5 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -88,6 +88,23 @@ any given message." notmuch-wash-elide-blank-lines notmuch-wash-excerpt-citations)) +(defcustom notmuch-show-line-faces nil + "Tag to face mapping for header line highlighting in `notmuch-show-mode'. + +Here is an example of how to color search results based on tags. + (the following text would be placed in your ~/.emacs file): + + (setq notmuch-search-line-faces '((\"delete\" . (:foreground \"red\" + :background \"blue\")) + (\"unread\" . (:foreground \"green\")))) + +The attributes defined for matching tags are merged, with later +attributes overriding earlier. A message having both \"delete\" +and \"unread\" tags with the above settings would have a green +foreground and blue background." + :type '(alist :key-type (string) :value-type (custom-face-edit)) + :group 'notmuch) + ;; Mostly useful for debugging. (defcustom notmuch-show-all-multipart/alternative-parts t "Should all parts of multipart/alternative parts be shown?" @@ -269,7 +286,8 @@ unchanged ADDRESS if parsing fails." (defun notmuch-show-insert-headerline (headers date tags depth) "Insert a notmuch style headerline based on HEADERS for a message at DEPTH in the current thread." - (let ((start (point))) + (let ((start (point)) + overlay) (insert (notmuch-show-spaces-n (* notmuch-indent-messages-width depth)) (notmuch-show-clean-address (plist-get headers :From)) " (" @@ -277,7 +295,9 @@ message at DEPTH in the current thread." ") (" (mapconcat 'identity tags " ") ")\n") - (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face))) + (setq overlay (make-overlay start (point))) + (overlay-put overlay 'face 'notmuch-message-summary-face) + (overlay-put overlay 'priority 2))) (defun notmuch-show-insert-header (header header-value) "Insert a single header." @@ -712,7 +732,8 @@ current buffer, if possible." body-start body-end (headers-invis-spec (notmuch-show-make-symbol "header")) (message-invis-spec (notmuch-show-make-symbol "message")) - (bare-subject (notmuch-show-strip-re (plist-get headers :Subject)))) + (bare-subject (notmuch-show-strip-re (plist-get headers :Subject))) + (tags (plist-get msg :tags))) ;; Set `buffer-invisibility-spec' to `nil' (a list), otherwise ;; removing items from `buffer-invisibility-spec' (which is what @@ -737,10 +758,13 @@ current buffer, if possible." (plist-get msg :date_relative) nil) (plist-get headers :Date)) - (plist-get msg :tags) depth) + tags depth) (setq content-start (point-marker)) + ;; Colour the header line according to the tags of the message. + (notmuch-color-line message-start content-start tags notmuch-show-line-faces) + (plist-put msg :headers-invis-spec headers-invis-spec) (plist-put msg :message-invis-spec message-invis-spec) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 4844385..56d35d0 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -641,7 +641,7 @@ This function advances the next thread when finished." (forward-line (1- notmuch-search-target-line)))))))) (defcustom notmuch-search-line-faces nil - "Tag/face mapping for line highlighting in notmuch-search. + "Tag to face mapping for line highlighting in `notmuch-search-mode'. Here is an example of how to color search results based on tags. (the following text would be placed in your ~/.emacs file): @@ -659,20 +659,7 @@ foreground and blue background." (defun notmuch-search-color-line (start end line-tag-list) "Colorize lines in `notmuch-show' based on tags." - ;; Create the overlay only if the message has tags which match one - ;; of those specified in `notmuch-search-line-faces'. - (let (overlay) - (mapc (lambda (elem) - (let ((tag (car elem)) - (attributes (cdr elem))) - (when (member tag line-tag-list) - (when (not overlay) - (setq overlay (make-overlay start end))) - ;; Merge the specified properties with any already - ;; applied from an earlier match. - (overlay-put overlay 'face - (append (overlay-get overlay 'face) attributes))))) - notmuch-search-line-faces))) + (notmuch-color-line start end line-tag-list notmuch-search-line-faces)) (defun notmuch-search-author-propertize (authors) "Split `authors' into matching and non-matching authors and -- 1.7.7.3