[PATCH] notmuch: Add hooks for show-mode and search-mode

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

[PATCH] notmuch: Add hooks for show-mode and search-mode


>From e3a801c90ed5e037b68bd16807606388e6dbe6e8 Mon Sep 17 00:00:00 2001
From: Aneesh Kumar K.V <[hidden email]>
Date: Wed, 18 Nov 2009 20:43:13 +0530
Subject: [PATCH] notmuch: Add hooks for show-mode and search-mode

This enables to do things like

(add-hook 'notmuch-search-mode-hook
          (lambda()
            (hl-line-mode 1) ))

Signed-off-by: Aneesh Kumar K.V <[hidden email]>
---
 notmuch.el |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 014d15b..87116f9 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -57,6 +57,12 @@
   "Keymap for \"notmuch show\" buffers.")
 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
 
+(defvar notmuch-show-mode-hook nil
+  "Hooks run when notmuch-show-mode is enabled")
+
+(defvar notmuch-search-mode-hook nil
+  "Hooks run when notmuch-search-mode is enabled")
+
 (defvar notmuch-show-signature-regexp "\\(-- ?\\|_+\\)$"
   "Pattern to match a line that separates content from signature.
 
@@ -636,7 +642,8 @@ 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)
+  (run-hooks 'notmuch-show-mode-hook))
 
 (defun notmuch-show (thread-id &optional parent-buffer)
   "Run \"notmuch show\" with the given thread ID and display results.
@@ -759,7 +766,8 @@ global search.
   (use-local-map notmuch-search-mode-map)
   (setq major-mode 'notmuch-search-mode
  mode-name "notmuch-search")
-  (setq buffer-read-only t))
+  (setq buffer-read-only t)
+  (run-hooks 'notmuch-search-mode-hook))
 
 (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: Add hooks for show-mode and search-mode

On Wed, 18 Nov 2009 20:44:58 +0530, [hidden email] (Aneesh Kumar K.V) wrote:
> From: Aneesh Kumar K.V <[hidden email]>
> Date: Wed, 18 Nov 2009 20:43:13 +0530
> Subject: [PATCH] notmuch: Add hooks for show-mode and search-mode
>
> This enables to do things like
>
> (add-hook 'notmuch-search-mode-hook
>           (lambda()
>             (hl-line-mode 1) ))

Hi Aneesh,

Thanks for the patch. I think the hooks will be genuinely useful. I
haven't pushed this yet for two questions:

1. I recently merged an independent patch from Keith to add one hook
already. (And it looks like Keith got fancy and used defcustom instead
of defvar.) Could you re-do your patch on top of master and match the
style he used? [*]

2. If this hl-line-mode thing is interesting for you, might it not be
interesting for all users? (What does it do anyway?)

One concern I have with hooks is that people will use them to fix things
locally and prevent the defaults getting fixed to improve things for
everybody. (Granted, sometimes there's an honest difference of opinion,
so the defaults can't always satisfy everyone, and we'll want the
hooks.)

I guess I'm just hoping that people will at least attempt to get
improvements to be integrated into the defaults instead of just changing
local hooks.

-Carl

[*] Independently, it might be nice to switch all of our variables
intended to be tweaked by the user from defvar to defcustom.