X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=emacs%2Fnotmuch.el;h=2a87ab92ca5261013e6407914f2413256ed3fbf3;hb=d064bd696ccc443a7ece9cfc8816999c69943223;hp=7c9c028e294bd74f092b5abdd7dd8f600a9ffae0;hpb=f2525ed18fd7f06896accf21d1b28672f88e11df;p=notmuch diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 7c9c028e..2a87ab92 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -47,7 +47,7 @@ ; kudos: Notmuch list (subscription is not ; required, but is available from http://notmuchmail.org). -(require 'cl) +(eval-when-compile (require 'cl)) (require 'mm-view) (require 'message) @@ -329,7 +329,6 @@ For a mouse binding, return nil." "Face used in search mode face for tags." :group 'notmuch) -;;;###autoload (defun notmuch-search-mode () "Major mode displaying results of a notmuch search. @@ -575,9 +574,10 @@ This function advances the next thread when finished." (if (and atbob (not (string= notmuch-search-target-thread "found"))) (set 'never-found-target-thread t)))))) - (if (and never-found-target-thread + (when (and never-found-target-thread notmuch-search-target-line) - (goto-line notmuch-search-target-line))))))) + (goto-char (point-min)) + (forward-line (1- notmuch-search-target-line)))))))) (defcustom notmuch-search-line-faces nil "Tag/face mapping for line highlighting in notmuch-search. @@ -585,46 +585,80 @@ 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))) (defun notmuch-search-insert-authors (format-string authors) - (insert (let* ((formatted-sample (format format-string "")) - (formatted-authors (format format-string authors)) - (truncated-string - (if (> (length formatted-authors) - (length formatted-sample)) - (concat (substring authors 0 (- (length formatted-sample) 4)) "... ") - formatted-authors))) - ;; Need to save the match data to avoid interfering with - ;; `notmuch-search-process-filter'. - (save-match-data - (if (string-match "\\(.*\\)|\\(..*\\)" truncated-string) - (concat (propertize (concat (match-string 1 truncated-string) ",") - 'face 'notmuch-search-matching-authors) - (propertize (match-string 2 truncated-string) - 'face 'notmuch-search-non-matching-authors)) - (propertize truncated-string 'face 'notmuch-search-matching-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 @@ -662,7 +696,7 @@ matching will be applied." (more t) (inhibit-read-only t)) (while more - (if (string-match "^\\(thread:[0-9A-Fa-f]*\\) \\(.*\\) \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" string line) + (if (string-match "^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" string line) (let* ((thread-id (match-string 1 string)) (date (match-string 2 string)) (count (match-string 3 string)) @@ -712,10 +746,16 @@ characters as well as `_.+-'. (defun notmuch-search-buffer-title (query) "Returns the title for a buffer with notmuch search results." - (let* ((saved-search (rassoc-if (lambda (key) - (string-match (concat "^" (regexp-quote key)) - query)) - (reverse (notmuch-saved-searches)))) + (let* ((saved-search + (let (longest + (longest-length 0)) + (loop for tuple in notmuch-saved-searches + if (let ((quoted-query (regexp-quote (cdr tuple)))) + (and (string-match (concat "^" quoted-query) query) + (> (length (match-string 0 query)) + longest-length))) + do (setq longest tuple)) + longest)) (saved-search-name (car saved-search)) (saved-search-query (cdr saved-search))) (cond ((and saved-search (equal saved-search-query query)) @@ -759,10 +799,13 @@ The optional parameters are used as follows: (erase-buffer) (goto-char (point-min)) (save-excursion - (let ((proc (start-process-shell-command - "notmuch-search" buffer notmuch-command "search" - (if oldest-first "--sort=oldest-first" "--sort=newest-first") - (shell-quote-argument query)))) + (let ((proc (start-process + "notmuch-search" buffer + notmuch-command "search" + (if oldest-first + "--sort=oldest-first" + "--sort=newest-first") + query))) (set-process-sentinel proc 'notmuch-search-process-sentinel) (set-process-filter proc 'notmuch-search-process-filter)))) (run-hooks 'notmuch-search-hook)))