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 6818F431FD0 for ; Tue, 27 Dec 2011 11:57:42 -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 EQXk+FQmZklk for ; Tue, 27 Dec 2011 11:57:41 -0800 (PST) Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com [74.125.83.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 2E6C7431FB6 for ; Tue, 27 Dec 2011 11:57:40 -0800 (PST) Received: by eekd41 with SMTP id d41so14397251eek.26 for ; Tue, 27 Dec 2011 11:57:40 -0800 (PST) Received: by 10.213.14.131 with SMTP id g3mr5970331eba.63.1325015858370; Tue, 27 Dec 2011 11:57:38 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id z43sm110750221eef.7.2011.12.27.11.57.35 (version=SSLv3 cipher=OTHER); Tue, 27 Dec 2011 11:57:37 -0800 (PST) From: Jani Nikula To: David Edmondson , notmuch@notmuchmail.org Subject: Re: [PATCH] emacs: Add `notmuch-show-line-faces' and apply it. In-Reply-To: <1325006003-27152-1-git-send-email-dme@dme.org> References: <1325006003-27152-1-git-send-email-dme@dme.org> User-Agent: Notmuch/0.10.2+133~gb08a3ab (http://notmuchmail.org) Emacs/23.3.1 (i686-pc-linux-gnu) Date: Tue, 27 Dec 2011 21:57:33 +0200 Message-ID: <87d3b923f6.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 19:57:42 -0000 On Tue, 27 Dec 2011 17:13:23 +0000, David Edmondson wrote: > 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. Hi David, I've only given this a quick test drive, but so far it seems to work as expected. I think this would be a useful feature to have. The patch failed to apply cleanly without "emacs: Don't attempt to colour tags in `notmuch-show-mode'." Is there a dependency, or was this accidental? BR, Jani. > --- > 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 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch