[PATCH] emacs: Re-work the implementation of highlighting in notmuch-search-mode.

2010-06-07 Thread David Edmondson
Re-write `notmuch-search-color-line', with the following improvements:
 - create overlays only if they will be needed,
 - merge the properties specified for a tag on top of any matching a
   previous tag.
---
 emacs/notmuch.el |   37 +
 1 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 10babe4..ac1da34 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -585,28 +585,33 @@ This function advances the next thread when finished."
 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\"))
+ (setq notmuch-search-line-faces '((\"delete\" . '(:foreground \"red\"
+  :background \"blue\"))
(\"unread\" . '(:foreground \"green\"

-Order matters: for lines with multiple tags, the the first
-matching will be applied."
+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 (list))
   :group 'notmuch)

 (defun notmuch-search-color-line (start end line-tag-list)
-  "Colorize lines in notmuch-show based on tags"
-  (if notmuch-search-line-faces
-  (let ((overlay (make-overlay start end))
-   (tags-faces (copy-alist notmuch-search-line-faces)))
-   (while tags-faces
- (let* ((tag-face (car tags-faces))
-(tag (car tag-face))
-(face (cdr tag-face)))
-   (cond ((member tag line-tag-list)
-  (overlay-put overlay 'face face)
-  (setq tags-faces nil))
- (t
-  (setq tags-faces (cdr tags-faces)
+  "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)))

 (defun notmuch-search-isearch-authors-show (overlay)
   (remove-from-invisibility-spec (cons (overlay-get overlay 'invisible) t)))
-- 
1.7.1



[PATCH] emacs: Re-work the implementation of highlighting in notmuch-search-mode.

2010-10-29 Thread Carl Worth
On Mon,  7 Jun 2010 15:35:10 +0100, David Edmondson  wrote:
> Re-write `notmuch-search-color-line', with the following improvements:
>  - create overlays only if they will be needed,
>  - merge the properties specified for a tag on top of any matching a
>previous tag.
...
> +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."

Thanks David,

That looks like a very useful change. All pushed now.

(Though I don't yet have any automated tests to cover colors in emacs
buffers. Anyone care to cook something up?)

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[PATCH] emacs: Re-work the implementation of highlighting in notmuch-search-mode.

2010-06-07 Thread David Edmondson
Re-write `notmuch-search-color-line', with the following improvements:
 - create overlays only if they will be needed,
 - merge the properties specified for a tag on top of any matching a
   previous tag.
---
 emacs/notmuch.el |   37 +
 1 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 10babe4..ac1da34 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -585,28 +585,33 @@ This function advances the next thread when finished."
 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\"))
+ (setq notmuch-search-line-faces '((\"delete\" . '(:foreground \"red\"
+  :background \"blue\"))
(\"unread\" . '(:foreground \"green\"
 
-Order matters: for lines with multiple tags, the the first
-matching will be applied."
+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 (list))
   :group 'notmuch)
 
 (defun notmuch-search-color-line (start end line-tag-list)
-  "Colorize lines in notmuch-show based on tags"
-  (if notmuch-search-line-faces
-  (let ((overlay (make-overlay start end))
-   (tags-faces (copy-alist notmuch-search-line-faces)))
-   (while tags-faces
- (let* ((tag-face (car tags-faces))
-(tag (car tag-face))
-(face (cdr tag-face)))
-   (cond ((member tag line-tag-list)
-  (overlay-put overlay 'face face)
-  (setq tags-faces nil))
- (t
-  (setq tags-faces (cdr tags-faces)
+  "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)))
 
 (defun notmuch-search-isearch-authors-show (overlay)
   (remove-from-invisibility-spec (cons (overlay-get overlay 'invisible) t)))
-- 
1.7.1

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] emacs: Re-work the implementation of highlighting in notmuch-search-mode.

2010-10-29 Thread Carl Worth
On Mon,  7 Jun 2010 15:35:10 +0100, David Edmondson  wrote:
> Re-write `notmuch-search-color-line', with the following improvements:
>  - create overlays only if they will be needed,
>  - merge the properties specified for a tag on top of any matching a
>previous tag.
...
> +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."

Thanks David,

That looks like a very useful change. All pushed now.

(Though I don't yet have any automated tests to cover colors in emacs
buffers. Anyone care to cook something up?)

-Carl


pgp8WLpHqrXBw.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch