+ "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)))
+
+(defun notmuch-search-insert-authors (format-string authors)
+ (let* ((propertized-authors
+ ;; Need to save the match data to avoid interfering with
+ ;; `notmuch-search-process-filter'.
+ (save-match-data
+ ;; Authors that don't match the search query are shown in a
+ ;; different font.
+ (if (string-match "\\(.*\\)|\\(..*\\)" authors)
+ (concat (propertize (concat (match-string 1 authors) ",")
+ 'face 'notmuch-search-matching-authors)
+ (propertize (match-string 2 authors)
+ 'face 'notmuch-search-non-matching-authors))
+ (propertize authors 'face 'notmuch-search-matching-authors))))
+
+ (formatted-sample (format format-string ""))
+ (formatted-authors (format format-string propertized-authors))
+ visible-string invisible-string)
+
+ ;; Determine the part of the authors that will be visible by
+ ;; default.
+ (if (> (length formatted-authors)
+ (length formatted-sample))
+ ;; 4 is `(length "... ")'.
+ (let ((visible-length (- (length formatted-sample) 4)))
+ (setq visible-string (substring propertized-authors 0 visible-length)
+ invisible-string (substring propertized-authors visible-length)))
+ (setq visible-string formatted-authors
+ invisible-string nil))
+
+ ;; Insert both the visible and invisible author strings.
+ (insert visible-string)
+ (when invisible-string
+ (let ((start (point))
+ (invis-spec (make-symbol "notmuch-search-authors"))
+ overlay)
+ (insert invisible-string)
+ ;; Using a cons-cell here causes an ellipsis to be inserted
+ ;; instead of the invisible text.
+ (add-to-invisibility-spec (cons invis-spec t))
+ (setq overlay (make-overlay start (point)))
+ (overlay-put overlay 'invisible invis-spec)
+ (overlay-put overlay 'isearch-open-invisible #'notmuch-search-isearch-authors-show)
+ (insert " ")))))
+
+(defun notmuch-search-insert-field (field date count authors subject tags)
+ (cond
+ ((string-equal field "date")
+ (insert (propertize (format (cdr (assoc field notmuch-search-result-format)) date)
+ 'face 'notmuch-search-date)))
+ ((string-equal field "count")
+ (insert (propertize (format (cdr (assoc field notmuch-search-result-format)) count)
+ 'face 'notmuch-search-count)))
+ ((string-equal field "subject")
+ (insert (propertize (format (cdr (assoc field notmuch-search-result-format)) subject)
+ 'face 'notmuch-search-subject)))
+
+ ((string-equal field "authors")
+ (notmuch-search-insert-authors (cdr (assoc field notmuch-search-result-format)) authors))
+
+ ((string-equal field "tags")
+ (insert (concat "(" (propertize tags 'font-lock-face 'notmuch-tag-face) ")")))))
+
+(defun notmuch-search-show-result (date count authors subject tags)
+ (let ((fields) (field))
+ (setq fields (mapcar 'car notmuch-search-result-format))
+ (loop for field in fields
+ do (notmuch-search-insert-field field date count authors subject tags)))
+ (insert "\n"))