[notmuch] [PATCH] notmuch.el: Add face support to search and show mode

Aneesh Kumar K.V aneesh.kumar at linux.vnet.ibm.com
Fri Nov 20 07:27:24 PST 2009


This add two faces, notmuch-show-subject-face and
notmuch-tag-unread-face. The first face is used to show the subject
line in the notmuch-show-mode and the second one the unread tag in
the notmuch-search-mode.

The changes are done looking at message.el in emacs source

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar at linux.vnet.ibm.com>
---
 notmuch.el |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 4b2936a..71e9dea 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -603,9 +603,37 @@ which this thread was originally shown."
   (force-window-update)
   (redisplay t))
 
+(defun notmuch-font-lock-matcher (regexp)
+  (let ((form
+         `(lambda (limit)
+            (let ((start (point)))
+              (save-restriction
+                (widen)
+                (goto-char (point-min))
+		(setq limit (min limit (point-max)))
+                (goto-char start))
+              (and (< start limit)
+                   (re-search-forward ,regexp limit t))))))
+    (if (featurep 'bytecomp)
+        (byte-compile form)
+      form)))
+
+(defface notmuch-show-subject-face
+ '((((class color) (background light)) (:foreground "yellow" :bold t))
+    (((class color) (background dark)) (:foreground "yellow" :bold t)))
+  "Notmuch show mode face used to highligh subject line."
+  :group 'notmuch)
+
+(defvar notmuch-show-font-lock-keywords
+  (let ((content ""))
+    `((,(notmuch-font-lock-matcher
+	 (concat "\\(Subject:.*$\\)" content))
+	 (1 'notmuch-show-subject-face nil t))))
+  "Additonal expression to hightlight in notmuch-search-mode")
+
 ;;;###autoload
-(defun notmuch-show-mode ()
-  "Major mode for viewing a thread with notmuch.
+(define-derived-mode notmuch-show-mode text-mode "notmuch-show"
+"Major mode for viewing a thread with notmuch.
 
 This buffer contains the results of the \"notmuch show\" command
 for displaying a single thread of email from your email archives.
@@ -643,7 +671,9 @@ view, (remove the \"inbox\" tag from each), with
   (use-local-map notmuch-show-mode-map)
   (setq major-mode 'notmuch-show-mode
 	mode-name "notmuch-show")
-  (setq buffer-read-only t))
+  (setq buffer-read-only t)
+  (set (make-local-variable 'font-lock-defaults)
+         '(notmuch-show-font-lock-keywords t)))
 
 ;;;###autoload
 
@@ -769,8 +799,21 @@ thread from that buffer can be show when done with this one)."
   (end-of-buffer arg)
   (forward-line -1))
 
+(defface notmuch-tag-unread-face
+ '((((class color) (background light)) (:foreground "goldenrod" :bold t))
+    (((class color) (background dark)) (:foreground "goldenrod" :bold t)))
+  "Notmuch search mode face used to highligh inbox tags."
+  :group 'notmuch)
+
+(defvar notmuch-search-font-lock-keywords
+  (let ((content ""))
+    `((,(notmuch-font-lock-matcher
+	 (concat "\\(unread\\)" content))
+	 (1 'notmuch-tag-unread-face nil t))))
+  "Additonal expression to hightlight in notmuch-search-mode")
+
 ;;;###autoload
-(defun notmuch-search-mode ()
+(define-derived-mode notmuch-search-mode text-mode "notmuch-search"
   "Major mode for searching mail with notmuch.
 
 This buffer contains the results of a \"notmuch search\" of your
@@ -799,7 +842,9 @@ global search.
   (setq truncate-lines t)
   (setq major-mode 'notmuch-search-mode
 	mode-name "notmuch-search")
-  (setq buffer-read-only t))
+  (setq buffer-read-only t)
+  (set (make-local-variable 'font-lock-defaults)
+         '(notmuch-search-font-lock-keywords t)))
 
 (defun notmuch-search-find-thread-id ()
   (save-excursion
-- 
1.6.5.2.74.g610f9



More information about the notmuch mailing list