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

classic Classic list List threaded Threaded
4 messages Options
Aneesh Kumar K.V Aneesh Kumar K.V
Reply | Threaded
Open this post in threaded view
|

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

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 <[hidden email]>
---
 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


Carl Worth-2 Carl Worth-2
Reply | Threaded
Open this post in threaded view
|

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

On Fri, 20 Nov 2009 20:57:24 +0530, "Aneesh Kumar K.V" <[hidden email]> wrote:
> 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

Hi Aneesh,

This looks like very interesting stuff, but I wasn't able to get it to
work. Initially I was running emacs within a terminal (emacs -nw) so I
thought that might be preventing me from seeing the face differences or
so.

But I can't seem to see anything in graphical emacs either.

Is there something more I need to do to make this work?

-Carl

Aneesh Kumar K.V Aneesh Kumar K.V
Reply | Threaded
Open this post in threaded view
|

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

On Sat, Nov 21, 2009 at 03:59:12AM +0100, Carl Worth wrote:

> On Fri, 20 Nov 2009 20:57:24 +0530, "Aneesh Kumar K.V" <[hidden email]> wrote:
> > 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
>
> Hi Aneesh,
>
> This looks like very interesting stuff, but I wasn't able to get it to
> work. Initially I was running emacs within a terminal (emacs -nw) so I
> thought that might be preventing me from seeing the face differences or
> so.
>
> But I can't seem to see anything in graphical emacs either.
>
> Is there something more I need to do to make this work?

To verify whether i have some setting in .emacs i ran emacs -q and still
i am able see the colors. So not sure what extra is needed. I also tried
emacs23 and that also worked. Are you able to see this faces via customize-face
command ? And what is the color they display in customize-face ?

-aneesh


Carl Worth-2 Carl Worth-2
Reply | Threaded
Open this post in threaded view
|

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

On Sat, 21 Nov 2009 09:37:30 +0530, "Aneesh Kumar K.V" <[hidden email]> wrote:
> To verify whether i have some setting in .emacs i ran emacs -q and still
> i am able see the colors. So not sure what extra is needed. I also tried
> emacs23 and that also worked. Are you able to see this faces via customize-face
> command ? And what is the color they display in customize-face ?

I think this was user-error on my part. So sorry about the noise.

For one thing, I recently broke the Makefiles to install
notmuch.el/notmuch.elc into the wrong directory.

Fixes shortly...

-Carl