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 6F88C431FB6 for ; Sat, 28 Jan 2012 03:06:51 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.098 X-Spam-Level: X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 JztbtZz+Ihgw for ; Sat, 28 Jan 2012 03:06:50 -0800 (PST) Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 349AC431FAE for ; Sat, 28 Jan 2012 03:06:50 -0800 (PST) Received: from smtp.qmul.ac.uk ([138.37.6.40]) by mail2.qmul.ac.uk with esmtp (Exim 4.71) (envelope-from ) id 1Rr67M-0000Qt-5u; Sat, 28 Jan 2012 11:06:48 +0000 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] helo=localhost) by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1Rr67L-0001XR-OF; Sat, 28 Jan 2012 11:06:48 +0000 From: Mark Walters To: David Edmondson Subject: Re: [PATCH] emacs: add default value to notmuch-search-line-faces In-Reply-To: References: <1327605679-15213-1-git-send-email-jani@nikula.org> <87y5st4ewt.fsf@qmul.ac.uk> User-Agent: Notmuch/0.11+107~g185f859 (http://notmuchmail.org) Emacs/23.2.1 (i486-pc-linux-gnu) Date: Sat, 28 Jan 2012 11:07:51 +0000 Message-ID: <871uqk6q60.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Sender-Host-Address: 94.192.233.223 X-QM-SPAM-Info: Sender has good ham record. :) X-QM-Body-MD5: 046f23133340c558ed1a97dc0491b70a (of first 20000 bytes) X-SpamAssassin-Score: -1.8 X-SpamAssassin-SpamBar: - X-SpamAssassin-Report: The QM spam filters have analysed this message to determine if it is spam. We require at least 5.0 points to mark a message as spam. This message scored -1.8 points. Summary of the scoring: * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, * medium trust * [138.37.6.40 listed in list.dnswl.org] * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider * (markwalters1009[at]gmail.com) * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay * domain * 0.5 AWL AWL: From: address is in the auto white-list X-QM-Scan-Virus: ClamAV says the message is clean Cc: Notmuch Mail 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: Sat, 28 Jan 2012 11:06:51 -0000 On Fri, 27 Jan 2012 10:37:43 +0000, David Edmondson wrote: > On Fri, 27 Jan 2012 10:29:22 +0000, Mark Walters wrote: > > I am not sure if this is the place > > Here or #notmuch. > > > to ask but is there a corresponding option for colouring the summary > > line in notmuch-show depending on tags/flags? > > There's id:"1325006003-27152-1-git-send-email-dme@dme.org", but it's a > bit old and may not apply cleanly any more. That's great! One hunk didn't apply but the merge was so trivial I am not sure why it did not apply. Anyway in case anyone else wants it I include the rebased version below (I also moved the defcustom under notmuch-show). Best wishes Mark Subject: [PATCH] rebased id:"1325006003-27152-1-git-send-email-dme@dme.org" --- emacs/notmuch-lib.el | 18 ++++++++++++++++++ emacs/notmuch-show.el | 33 +++++++++++++++++++++++++++++---- emacs/notmuch.el | 17 ++--------------- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index c906ca7..ab1d8e8 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -133,6 +133,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 84ac624..c448ab2 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -92,6 +92,24 @@ any given message." :group 'notmuch-show :group 'notmuch-hooks) +(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-show + :group 'notmuch-faces) + ;; Mostly useful for debugging. (defcustom notmuch-show-all-multipart/alternative-parts t "Should all parts of multipart/alternative parts be shown?" @@ -340,7 +358,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-show-indent-messages-width depth)) (notmuch-show-clean-address (plist-get headers :From)) " (" @@ -349,7 +368,9 @@ message at DEPTH in the current thread." (propertize (mapconcat 'identity tags " ") 'face 'notmuch-tag-face) ")\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." @@ -818,7 +839,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 @@ -843,10 +865,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 72f78ed..244fafa 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -690,7 +690,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): @@ -709,20 +709,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.2.3