From: Michal Sojka <sojkam1@fel.cvut.cz>
To: notmuch@notmuchmail.org
Subject: [PATCH] emacs: Fix regression in (notmuch-)message-mode initialization
Date: Tue, 3 Nov 2015 18:52:41 +0100 [thread overview]
Message-ID: <1446573161-28068-1-git-send-email-sojkam1@fel.cvut.cz> (raw)
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
next reply other threads:[~2015-11-03 17:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-03 17:52 Michal Sojka [this message]
2015-11-09 12:17 ` [PATCH] emacs: Fix regression in (notmuch-)message-mode initialization David Bremner
2015-11-09 12:50 ` Michal Sojka
2015-11-09 14:26 ` David Bremner
2015-11-09 20:52 ` Tomi Ollila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1446573161-28068-1-git-send-email-sojkam1@fel.cvut.cz \
--to=sojkam1@fel.cvut.cz \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).