unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: Fix regression in (notmuch-)message-mode initialization
@ 2015-11-03 17:52 Michal Sojka
  2015-11-09 12:17 ` David Bremner
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Sojka @ 2015-11-03 17:52 UTC (permalink / raw)
  To: notmuch

Recent addition of notmuch-message-mode introduced a few regressions.
I use message-setup-hook to set some buffer local variables and this
stopped working. The reason is that notmuch-message-mode, which cleans
all buffer local variables, is called after calling message-mail,
which calls the message-setup-hook. Another problem with the previous
implementation might be that the message-mode-hook is called twice -
first when message-mail calls message-mode and second when
notmuch-message-mode calls it. This can be problematic when the hook
has side effects.

This commit uses advice mechanism to call notmuch-message-mode instead
of message-mode. This way, a call to message-mail initializes directly
notmuch-message-mode rather than message-mode which is later changed
to notmuch-message-mode. The advice is constructed in such a way, that
it is effective only once and when called by notmuch. The second call
to message-mode (from notmuch-message-mode) calls the original
message-mode.

This implementation uses the new advice mechanism introduced in Emacs
24.4. If we want to support older version, this must be changed.
---
 emacs/notmuch-mua.el | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index fd98ea4..540a676 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -276,6 +276,19 @@ Note that these functions use `mail-citation-hook' if that is non-nil."
 (define-key notmuch-message-mode-map (kbd "C-c C-c") #'notmuch-mua-send-and-exit)
 (define-key notmuch-message-mode-map (kbd "C-c C-s") #'notmuch-mua-send)
 
+(defun message-mode--notmuch-advice ()
+  (if (boundp 'use-notmuch-message-mode)
+      (progn
+	(makunbound 'use-notmuch-message-mode)
+	(notmuch-message-mode)
+	nil) ; Do not call original message-mode
+    t))	     ; Call original message-mode
+
+;; Advice message-mode to call notmuch-message-mode when
+;; use-notmuch-message-mode is bound. Otherwise message-mode is called
+;; without changes.
+(advice-add 'message-mode :before-while #'message-mode--notmuch-advice)
+
 (defun notmuch-mua-mail (&optional to subject other-headers &rest other-args)
   "Invoke the notmuch mail composition window.
 
@@ -291,8 +304,11 @@ OTHER-ARGS are passed through to `message-mail'."
     (push (cons 'From (concat
 		       (notmuch-user-name) " <" (notmuch-user-primary-email) ">")) other-headers))
 
-  (apply #'message-mail to subject other-headers other-args)
-  (notmuch-message-mode)
+  ;; message-mail calls message-mode directly (via
+  ;; message-pop-to-buffer). We want it to call notmuch-message-mode
+  ;; instead.
+  (let ((use-notmuch-message-mode))
+    (apply #'message-mail to subject other-headers other-args))
   (notmuch-fcc-header-setup)
   (message-sort-headers)
   (message-hide-headers)
-- 
2.5.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-11-09 20:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-03 17:52 [PATCH] emacs: Fix regression in (notmuch-)message-mode initialization Michal Sojka
2015-11-09 12:17 ` David Bremner
2015-11-09 12:50   ` Michal Sojka
2015-11-09 14:26     ` David Bremner
2015-11-09 20:52     ` Tomi Ollila

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).