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

* Re: [PATCH] emacs: Fix regression in (notmuch-)message-mode initialization
  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
  0 siblings, 1 reply; 5+ messages in thread
From: David Bremner @ 2015-11-09 12:17 UTC (permalink / raw)
  To: Michal Sojka, notmuch

Michal Sojka <sojkam1@fel.cvut.cz> writes:

> 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.

I wanted to answer this with an alternative patch, but I haven't had
time.

I admit to being somewhat prejudiced against shipping code with advice
in it (IMHO it's fine for user specific customization, but not very
maintainable).

I think we might be better off in the long run replacing the call to
message-mail. Code duplication is obviously not great, but perhaps some
of the complexity of message-mail / message-pop-to-buffer can be
eliminated, since we don't need to support all of the use cases of
message-mail.

> This implementation uses the new advice mechanism introduced in Emacs
> 24.4. If we want to support older version, this must be changed.

We do try to support Emacs 23 still (except for some optional
features). Unfortunately old advice is even nastier.

d

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

* Re: [PATCH] emacs: Fix regression in (notmuch-)message-mode initialization
  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
  0 siblings, 2 replies; 5+ messages in thread
From: Michal Sojka @ 2015-11-09 12:50 UTC (permalink / raw)
  To: David Bremner, notmuch

On Mon, Nov 09 2015, David Bremner wrote:
> Michal Sojka <sojkam1@fel.cvut.cz> writes:
>
>> 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.
>
> I wanted to answer this with an alternative patch, but I haven't had
> time.
>
> I admit to being somewhat prejudiced against shipping code with advice
> in it (IMHO it's fine for user specific customization, but not very
> maintainable).
>
> I think we might be better off in the long run replacing the call to
> message-mail. Code duplication is obviously not great, but perhaps some
> of the complexity of message-mail / message-pop-to-buffer can be
> eliminated, since we don't need to support all of the use cases of
> message-mail.

OK. I'll try implement notmuch-message-mail as a simpler alternative to
message-mail. Let's see how it will look like.

>
>> This implementation uses the new advice mechanism introduced in Emacs
>> 24.4. If we want to support older version, this must be changed.
>
> We do try to support Emacs 23 still (except for some optional
> features). Unfortunately old advice is even nastier.

Hopefully, advises won't be needed then.

Thanks,
-Michal

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

* Re: [PATCH] emacs: Fix regression in (notmuch-)message-mode initialization
  2015-11-09 12:50   ` Michal Sojka
@ 2015-11-09 14:26     ` David Bremner
  2015-11-09 20:52     ` Tomi Ollila
  1 sibling, 0 replies; 5+ messages in thread
From: David Bremner @ 2015-11-09 14:26 UTC (permalink / raw)
  To: Michal Sojka, notmuch

Michal Sojka <sojkam1@fel.cvut.cz> writes:

>> I think we might be better off in the long run replacing the call to
>> message-mail. Code duplication is obviously not great, but perhaps some
>> of the complexity of message-mail / message-pop-to-buffer can be
>> eliminated, since we don't need to support all of the use cases of
>> message-mail.
>
> OK. I'll try implement notmuch-message-mail as a simpler alternative to
> message-mail. Let's see how it will look like.

Thanks for giving it a try.

David

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

* Re: [PATCH] emacs: Fix regression in (notmuch-)message-mode initialization
  2015-11-09 12:50   ` Michal Sojka
  2015-11-09 14:26     ` David Bremner
@ 2015-11-09 20:52     ` Tomi Ollila
  1 sibling, 0 replies; 5+ messages in thread
From: Tomi Ollila @ 2015-11-09 20:52 UTC (permalink / raw)
  To: Michal Sojka, David Bremner, notmuch

On Mon, Nov 09 2015, Michal Sojka <sojkam1@fel.cvut.cz> wrote:

> On Mon, Nov 09 2015, David Bremner wrote:
>> Michal Sojka <sojkam1@fel.cvut.cz> writes:
>>
>>> 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.
>>
>> I wanted to answer this with an alternative patch, but I haven't had
>> time.
>>
>> I admit to being somewhat prejudiced against shipping code with advice
>> in it (IMHO it's fine for user specific customization, but not very
>> maintainable).
>>
>> I think we might be better off in the long run replacing the call to
>> message-mail. Code duplication is obviously not great, but perhaps some
>> of the complexity of message-mail / message-pop-to-buffer can be
>> eliminated, since we don't need to support all of the use cases of
>> message-mail.
>
> OK. I'll try implement notmuch-message-mail as a simpler alternative to
> message-mail. Let's see how it will look like.

that might be better than my vague thought of let-binding that particular
hook (to nil) and run-hooks it later...

Tomi (sending from my N9)
 
>
>>
>>> This implementation uses the new advice mechanism introduced in Emacs
>>> 24.4. If we want to support older version, this must be changed.
>>
>> We do try to support Emacs 23 still (except for some optional
>> features). Unfortunately old advice is even nastier.
>
> Hopefully, advises won't be needed then.
>
> Thanks,
> -Michal
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[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).