mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
emacs: Re-work the implementation of highlighting in notmuch-search-mode.
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.
This commit is contained in:
parent
bec47efeeb
commit
f99ad42da0
1 changed files with 21 additions and 16 deletions
|
@ -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.
|
Here is an example of how to color search results based on tags.
|
||||||
(the following text would be placed in your ~/.emacs file):
|
(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\"))))
|
(\"unread\" . '(:foreground \"green\"))))
|
||||||
|
|
||||||
Order matters: for lines with multiple tags, the the first
|
The attributes defined for matching tags are merged, with later
|
||||||
matching will be applied."
|
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))
|
:type '(alist :key-type (string) :value-type (list))
|
||||||
:group 'notmuch)
|
:group 'notmuch)
|
||||||
|
|
||||||
(defun notmuch-search-color-line (start end line-tag-list)
|
(defun notmuch-search-color-line (start end line-tag-list)
|
||||||
"Colorize lines in notmuch-show based on tags"
|
"Colorize lines in `notmuch-show' based on tags."
|
||||||
(if notmuch-search-line-faces
|
;; Create the overlay only if the message has tags which match one
|
||||||
(let ((overlay (make-overlay start end))
|
;; of those specified in `notmuch-search-line-faces'.
|
||||||
(tags-faces (copy-alist notmuch-search-line-faces)))
|
(let (overlay)
|
||||||
(while tags-faces
|
(mapc '(lambda (elem)
|
||||||
(let* ((tag-face (car tags-faces))
|
(let ((tag (car elem))
|
||||||
(tag (car tag-face))
|
(attributes (cdr elem)))
|
||||||
(face (cdr tag-face)))
|
(when (member tag line-tag-list)
|
||||||
(cond ((member tag line-tag-list)
|
(when (not overlay)
|
||||||
(overlay-put overlay 'face face)
|
(setq overlay (make-overlay start end)))
|
||||||
(setq tags-faces nil))
|
;; Merge the specified properties with any already
|
||||||
(t
|
;; applied from an earlier match.
|
||||||
(setq tags-faces (cdr tags-faces)))))))))
|
(overlay-put overlay 'face
|
||||||
|
(append (overlay-get overlay 'face) attributes)))))
|
||||||
|
notmuch-search-line-faces)))
|
||||||
|
|
||||||
(defun notmuch-search-isearch-authors-show (overlay)
|
(defun notmuch-search-isearch-authors-show (overlay)
|
||||||
(remove-from-invisibility-spec (cons (overlay-get overlay 'invisible) t)))
|
(remove-from-invisibility-spec (cons (overlay-get overlay 'invisible) t)))
|
||||||
|
|
Loading…
Reference in a new issue