[PATCH] emacs: Let the user choose where to compose new mails

Subject: [PATCH] emacs: Let the user choose where to compose new mails

Date: Tue, 25 Oct 2011 09:41:04 +0200

To: notmuch@notmuchmail.org

Cc:

From: Thomas Jost


---
 emacs/notmuch-mua.el |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 8824b08..ebc922f 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -31,6 +31,34 @@
   :group 'notmuch
   :type 'hook)
 
+(defvar notmuch-mua-switch-function nil
+  "Function used to switch and display the mail buffer. This is
+  normally set by `notmuch-mua-compose-in'.")
+(defvar notmuch-mua-dedicated-flag nil
+  "Flag to pass to `set-window-dedicated-p' in the mail buffer.
+  This is normally set by `notmuch-mua-compose-in'.")
+(defcustom notmuch-mua-compose-in 'current-window
+  "Where to create the mail buffer used to compose a new message.
+  Possible values are `current-window' (default), `new-window'
+  and `new-frame'. If set to `new-window' or `new-frame', the
+  mail buffer will be displayer in a new window/frame that will
+  be destroyed when the buffer is killed. You may want to
+  customize `message-kill-buffer-on-exit' accordingly."
+  :group 'notmuch
+  :type 'symbol
+  :set (lambda (sym val)
+	 (cond ((eq val 'current-window)
+		(setq notmuch-mua-switch-function nil
+		      notmuch-mua-dedicated-flag nil))
+	       ((eq val 'new-window)
+		(setq notmuch-mua-switch-function 'switch-to-buffer-other-window
+		      notmuch-mua-dedicated-flag 1))
+	       ((eq val 'new-frame)
+		(setq notmuch-mua-switch-function 'switch-to-buffer-other-frame
+		      notmuch-mua-dedicated-flag 1))
+	       (t (error (concat "Bad value for notmuch-mua-compose-in: "
+				 (symbol-value val)))))))
+
 (defcustom notmuch-mua-user-agent-function 'notmuch-mua-user-agent-full
   "Function used to generate a `User-Agent:' string. If this is
 `nil' then no `User-Agent:' will be generated."
@@ -99,7 +127,8 @@ list."
 	((same-window-regexps '("\\*mail .*")))
       (notmuch-mua-mail (mail-header 'to headers)
 			(mail-header 'subject headers)
-			(message-headers-to-generate headers t '(to subject))))
+			(message-headers-to-generate headers t '(to subject))
+			nil notmuch-mua-switch-function))
     ;; insert the message body - but put it in front of the signature
     ;; if one is present
     (goto-char (point-max))
@@ -112,6 +141,8 @@ list."
   (message-goto-body))
 
 (defun notmuch-mua-forward-message ()
+  (when notmuch-mua-switch-function
+    (funcall notmuch-mua-switch-function (current-buffer)))
   (message-forward)
 
   (when notmuch-mua-user-agent-function
@@ -121,6 +152,7 @@ list."
   (message-sort-headers)
   (message-hide-headers)
   (set-buffer-modified-p nil)
+  (set-window-dedicated-p (selected-window) notmuch-mua-dedicated-flag)
 
   (message-goto-to))
 
@@ -143,6 +175,7 @@ list."
   (message-sort-headers)
   (message-hide-headers)
   (set-buffer-modified-p nil)
+  (set-window-dedicated-p (selected-window) notmuch-mua-dedicated-flag)
 
   (message-goto-to))
 
@@ -199,7 +232,7 @@ the From: address first."
   (let ((other-headers
 	 (when (or prompt-for-sender notmuch-always-prompt-for-sender)
 	   (list (cons 'from (notmuch-mua-prompt-for-sender))))))
-    (notmuch-mua-mail nil nil other-headers)))
+    (notmuch-mua-mail nil nil other-headers nil notmuch-mua-switch-function)))
 
 (defun notmuch-mua-new-forward-message (&optional prompt-for-sender)
   "Invoke the notmuch message forwarding window.
-- 
1.7.7


Thread: