Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id CEABA6DE0281 for ; Tue, 3 Nov 2015 09:53:01 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.985 X-Spam-Level: X-Spam-Status: No, score=-0.985 tagged_above=-999 required=5 tests=[AWL=1.865, RCVD_IN_DNSWL_MED=-2.3, RP_MATCHES_RCVD=-0.55] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 03ujwhthBE86 for ; Tue, 3 Nov 2015 09:52:59 -0800 (PST) Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) by arlo.cworth.org (Postfix) with ESMTP id 61F0D6DE01EA for ; Tue, 3 Nov 2015 09:52:58 -0800 (PST) Received: from localhost (unknown [192.168.200.7]) by max.feld.cvut.cz (Postfix) with ESMTP id 188B619F4379 for ; Tue, 3 Nov 2015 18:52:56 +0100 (CET) X-Virus-Scanned: IMAP STYX AMAVIS Received: from max.feld.cvut.cz ([192.168.200.1]) by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new, port 10044) with ESMTP id aM_tLtkP5RGe for ; Tue, 3 Nov 2015 18:52:54 +0100 (CET) Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34]) by max.feld.cvut.cz (Postfix) with ESMTP id 70FCE19F37CC for ; Tue, 3 Nov 2015 18:52:54 +0100 (CET) Received: from wsh by steelpick.2x.cz with local (Exim 4.86) (envelope-from ) id 1ZtflM-0007Jg-QM; Tue, 03 Nov 2015 18:52:52 +0100 From: Michal Sojka To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Fix regression in (notmuch-)message-mode initialization Date: Tue, 3 Nov 2015 18:52:41 +0100 Message-Id: <1446573161-28068-1-git-send-email-sojkam1@fel.cvut.cz> X-Mailer: git-send-email 2.5.3 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Nov 2015 17:53:01 -0000 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