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

2012-04-28 Thread Tomi Ollila
On Sat, Apr 14 2012, Jameson Graef Rollins  
wrote:

> From: Thomas Jost 
>
> Introduce a new defcustom notmuch-mua-compose-in that allows users to
> specify where new mails are composed., either in the current window or
> in a new window or frame.
>
> Signed-off-by: Jameson Rollins 
> ---
> This is a rebase of this original patch against the current master,
> with an expanded commit message.

+1

Tomi

>
>  emacs/notmuch-mua.el |   42 +++---
>  1 file changed, 39 insertions(+), 3 deletions(-)
>
> diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
> index 87bd88d..a96ac3d 100644
> --- a/emacs/notmuch-mua.el
> +++ b/emacs/notmuch-mua.el
> @@ -36,6 +36,21 @@
>:group 'notmuch-send
>:group 'notmuch-hooks)
>  
> +(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 `current-window', the mail buffer
> +  will be displayed in the current window, so the old buffer will
> +  be restored when the mail buffer is killed. If set to
> +  `new-window' or `new-frame', the mail buffer will be displayed
> +  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 '(choice (const :tag "Compose in the current window" current-window)
> +  (const :tag "Compose mail in a new window"  new-window)
> +  (const :tag "Compose mail in a new frame"   new-frame)))
> +
>  (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."
> @@ -55,6 +70,23 @@ list."
>  
>  ;;
>  
> +(defun notmuch-mua-get-switch-function ()
> +  "Get a switch function according to `notmuch-mua-compose-in'."
> +  (cond ((eq notmuch-mua-compose-in 'current-window)
> +  'switch-to-buffer)
> + ((eq notmuch-mua-compose-in 'new-window)
> +  'switch-to-buffer-other-window)
> + ((eq notmuch-mua-compose-in 'new-frame)
> +  'switch-to-buffer-other-frame)
> + (t (error "Invalid value for `notmuch-mua-compose-in'"
> +
> +(defun notmuch-mua-maybe-set-window-dedicated ()
> +  "Set the selected window as dedicated according to
> +`notmuch-mua-compose-in'."
> +  (when (or (eq notmuch-mua-compose-in 'new-frame)
> + (eq notmuch-mua-compose-in 'new-window))
> +(set-window-dedicated-p (selected-window) t)))
> +
>  (defun notmuch-mua-user-agent-full ()
>"Generate a `User-Agent:' string suitable for notmuch."
>(concat (notmuch-mua-user-agent-notmuch)
> @@ -148,7 +180,8 @@ list."
>collect pair)))
> (notmuch-mua-mail (plist-get reply-headers :To)
>   (plist-get reply-headers :Subject)
> - (notmuch-headers-plist-to-alist reply-headers
> + (notmuch-headers-plist-to-alist reply-headers)
> + nil (notmuch-mua-get-switch-function
>  
>;; Insert the message body - but put it in front of the signature
>;; if one is present
> @@ -186,6 +219,7 @@ list."
>(set-buffer-modified-p nil))
>  
>  (defun notmuch-mua-forward-message ()
> +  (funcall (notmuch-mua-get-switch-function) (current-buffer))
>(message-forward)
>  
>(when notmuch-mua-user-agent-function
> @@ -195,6 +229,7 @@ list."
>(message-sort-headers)
>(message-hide-headers)
>(set-buffer-modified-p nil)
> +  (notmuch-mua-maybe-set-window-dedicated)
>  
>(message-goto-to))
>  
> @@ -217,6 +252,7 @@ OTHER-ARGS are passed through to `message-mail'."
>(message-sort-headers)
>(message-hide-headers)
>(set-buffer-modified-p nil)
> +  (notmuch-mua-maybe-set-window-dedicated)
>  
>(message-goto-to))
>  
> @@ -272,8 +308,8 @@ the From: address first."
>(interactive "P")
>(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)))
> +(list (cons "From" (notmuch-mua-prompt-for-sender))
> +(notmuch-mua-mail nil nil other-headers nil 
> (notmuch-mua-get-switch-function
>  
>  (defun notmuch-mua-new-forward-message (&optional prompt-for-sender)
>"Invoke the notmuch message forwarding window.
> -- 
> 1.7.9.5
>
> ___
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


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

2012-04-28 Thread Tomi Ollila
On Sat, Apr 14 2012, Jameson Graef Rollins  wrote:

> From: Thomas Jost 
>
> Introduce a new defcustom notmuch-mua-compose-in that allows users to
> specify where new mails are composed., either in the current window or
> in a new window or frame.
>
> Signed-off-by: Jameson Rollins 
> ---
> This is a rebase of this original patch against the current master,
> with an expanded commit message.

+1

Tomi

>
>  emacs/notmuch-mua.el |   42 +++---
>  1 file changed, 39 insertions(+), 3 deletions(-)
>
> diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
> index 87bd88d..a96ac3d 100644
> --- a/emacs/notmuch-mua.el
> +++ b/emacs/notmuch-mua.el
> @@ -36,6 +36,21 @@
>:group 'notmuch-send
>:group 'notmuch-hooks)
>  
> +(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 `current-window', the mail buffer
> +  will be displayed in the current window, so the old buffer will
> +  be restored when the mail buffer is killed. If set to
> +  `new-window' or `new-frame', the mail buffer will be displayed
> +  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 '(choice (const :tag "Compose in the current window" current-window)
> +  (const :tag "Compose mail in a new window"  new-window)
> +  (const :tag "Compose mail in a new frame"   new-frame)))
> +
>  (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."
> @@ -55,6 +70,23 @@ list."
>  
>  ;;
>  
> +(defun notmuch-mua-get-switch-function ()
> +  "Get a switch function according to `notmuch-mua-compose-in'."
> +  (cond ((eq notmuch-mua-compose-in 'current-window)
> +  'switch-to-buffer)
> + ((eq notmuch-mua-compose-in 'new-window)
> +  'switch-to-buffer-other-window)
> + ((eq notmuch-mua-compose-in 'new-frame)
> +  'switch-to-buffer-other-frame)
> + (t (error "Invalid value for `notmuch-mua-compose-in'"
> +
> +(defun notmuch-mua-maybe-set-window-dedicated ()
> +  "Set the selected window as dedicated according to
> +`notmuch-mua-compose-in'."
> +  (when (or (eq notmuch-mua-compose-in 'new-frame)
> + (eq notmuch-mua-compose-in 'new-window))
> +(set-window-dedicated-p (selected-window) t)))
> +
>  (defun notmuch-mua-user-agent-full ()
>"Generate a `User-Agent:' string suitable for notmuch."
>(concat (notmuch-mua-user-agent-notmuch)
> @@ -148,7 +180,8 @@ list."
>collect pair)))
> (notmuch-mua-mail (plist-get reply-headers :To)
>   (plist-get reply-headers :Subject)
> - (notmuch-headers-plist-to-alist reply-headers
> + (notmuch-headers-plist-to-alist reply-headers)
> + nil (notmuch-mua-get-switch-function
>  
>;; Insert the message body - but put it in front of the signature
>;; if one is present
> @@ -186,6 +219,7 @@ list."
>(set-buffer-modified-p nil))
>  
>  (defun notmuch-mua-forward-message ()
> +  (funcall (notmuch-mua-get-switch-function) (current-buffer))
>(message-forward)
>  
>(when notmuch-mua-user-agent-function
> @@ -195,6 +229,7 @@ list."
>(message-sort-headers)
>(message-hide-headers)
>(set-buffer-modified-p nil)
> +  (notmuch-mua-maybe-set-window-dedicated)
>  
>(message-goto-to))
>  
> @@ -217,6 +252,7 @@ OTHER-ARGS are passed through to `message-mail'."
>(message-sort-headers)
>(message-hide-headers)
>(set-buffer-modified-p nil)
> +  (notmuch-mua-maybe-set-window-dedicated)
>  
>(message-goto-to))
>  
> @@ -272,8 +308,8 @@ the From: address first."
>(interactive "P")
>(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)))
> +(list (cons "From" (notmuch-mua-prompt-for-sender))
> +(notmuch-mua-mail nil nil other-headers nil 
> (notmuch-mua-get-switch-function
>  
>  (defun notmuch-mua-new-forward-message (&optional prompt-for-sender)
>"Invoke the notmuch message forwarding window.
> -- 
> 1.7.9.5
>
> ___
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2012-04-14 Thread Jameson Graef Rollins
From: Thomas Jost 

Introduce a new defcustom notmuch-mua-compose-in that allows users to
specify where new mails are composed., either in the current window or
in a new window or frame.

Signed-off-by: Jameson Rollins 
---
This is a rebase of this original patch against the current master,
with an expanded commit message.

 emacs/notmuch-mua.el |   42 +++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 87bd88d..a96ac3d 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -36,6 +36,21 @@
   :group 'notmuch-send
   :group 'notmuch-hooks)
 
+(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 `current-window', the mail buffer
+  will be displayed in the current window, so the old buffer will
+  be restored when the mail buffer is killed. If set to
+  `new-window' or `new-frame', the mail buffer will be displayed
+  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 '(choice (const :tag "Compose in the current window" current-window)
+(const :tag "Compose mail in a new window"  new-window)
+(const :tag "Compose mail in a new frame"   new-frame)))
+
 (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."
@@ -55,6 +70,23 @@ list."
 
 ;;
 
+(defun notmuch-mua-get-switch-function ()
+  "Get a switch function according to `notmuch-mua-compose-in'."
+  (cond ((eq notmuch-mua-compose-in 'current-window)
+'switch-to-buffer)
+   ((eq notmuch-mua-compose-in 'new-window)
+'switch-to-buffer-other-window)
+   ((eq notmuch-mua-compose-in 'new-frame)
+'switch-to-buffer-other-frame)
+   (t (error "Invalid value for `notmuch-mua-compose-in'"
+
+(defun notmuch-mua-maybe-set-window-dedicated ()
+  "Set the selected window as dedicated according to
+`notmuch-mua-compose-in'."
+  (when (or (eq notmuch-mua-compose-in 'new-frame)
+   (eq notmuch-mua-compose-in 'new-window))
+(set-window-dedicated-p (selected-window) t)))
+
 (defun notmuch-mua-user-agent-full ()
   "Generate a `User-Agent:' string suitable for notmuch."
   (concat (notmuch-mua-user-agent-notmuch)
@@ -148,7 +180,8 @@ list."
 collect pair)))
  (notmuch-mua-mail (plist-get reply-headers :To)
(plist-get reply-headers :Subject)
-   (notmuch-headers-plist-to-alist reply-headers
+   (notmuch-headers-plist-to-alist reply-headers)
+   nil (notmuch-mua-get-switch-function
 
   ;; Insert the message body - but put it in front of the signature
   ;; if one is present
@@ -186,6 +219,7 @@ list."
   (set-buffer-modified-p nil))
 
 (defun notmuch-mua-forward-message ()
+  (funcall (notmuch-mua-get-switch-function) (current-buffer))
   (message-forward)
 
   (when notmuch-mua-user-agent-function
@@ -195,6 +229,7 @@ list."
   (message-sort-headers)
   (message-hide-headers)
   (set-buffer-modified-p nil)
+  (notmuch-mua-maybe-set-window-dedicated)
 
   (message-goto-to))
 
@@ -217,6 +252,7 @@ OTHER-ARGS are passed through to `message-mail'."
   (message-sort-headers)
   (message-hide-headers)
   (set-buffer-modified-p nil)
+  (notmuch-mua-maybe-set-window-dedicated)
 
   (message-goto-to))
 
@@ -272,8 +308,8 @@ the From: address first."
   (interactive "P")
   (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)))
+  (list (cons "From" (notmuch-mua-prompt-for-sender))
+(notmuch-mua-mail nil nil other-headers nil 
(notmuch-mua-get-switch-function
 
 (defun notmuch-mua-new-forward-message (&optional prompt-for-sender)
   "Invoke the notmuch message forwarding window.
-- 
1.7.9.5

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2012-04-14 Thread Jameson Graef Rollins
From: Thomas Jost 

Introduce a new defcustom notmuch-mua-compose-in that allows users to
specify where new mails are composed., either in the current window or
in a new window or frame.

Signed-off-by: Jameson Rollins 
---
This is a rebase of this original patch against the current master,
with an expanded commit message.

 emacs/notmuch-mua.el |   42 +++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 87bd88d..a96ac3d 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -36,6 +36,21 @@
   :group 'notmuch-send
   :group 'notmuch-hooks)

+(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 `current-window', the mail buffer
+  will be displayed in the current window, so the old buffer will
+  be restored when the mail buffer is killed. If set to
+  `new-window' or `new-frame', the mail buffer will be displayed
+  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 '(choice (const :tag "Compose in the current window" current-window)
+(const :tag "Compose mail in a new window"  new-window)
+(const :tag "Compose mail in a new frame"   new-frame)))
+
 (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."
@@ -55,6 +70,23 @@ list."

 ;;

+(defun notmuch-mua-get-switch-function ()
+  "Get a switch function according to `notmuch-mua-compose-in'."
+  (cond ((eq notmuch-mua-compose-in 'current-window)
+'switch-to-buffer)
+   ((eq notmuch-mua-compose-in 'new-window)
+'switch-to-buffer-other-window)
+   ((eq notmuch-mua-compose-in 'new-frame)
+'switch-to-buffer-other-frame)
+   (t (error "Invalid value for `notmuch-mua-compose-in'"
+
+(defun notmuch-mua-maybe-set-window-dedicated ()
+  "Set the selected window as dedicated according to
+`notmuch-mua-compose-in'."
+  (when (or (eq notmuch-mua-compose-in 'new-frame)
+   (eq notmuch-mua-compose-in 'new-window))
+(set-window-dedicated-p (selected-window) t)))
+
 (defun notmuch-mua-user-agent-full ()
   "Generate a `User-Agent:' string suitable for notmuch."
   (concat (notmuch-mua-user-agent-notmuch)
@@ -148,7 +180,8 @@ list."
 collect pair)))
  (notmuch-mua-mail (plist-get reply-headers :To)
(plist-get reply-headers :Subject)
-   (notmuch-headers-plist-to-alist reply-headers
+   (notmuch-headers-plist-to-alist reply-headers)
+   nil (notmuch-mua-get-switch-function

   ;; Insert the message body - but put it in front of the signature
   ;; if one is present
@@ -186,6 +219,7 @@ list."
   (set-buffer-modified-p nil))

 (defun notmuch-mua-forward-message ()
+  (funcall (notmuch-mua-get-switch-function) (current-buffer))
   (message-forward)

   (when notmuch-mua-user-agent-function
@@ -195,6 +229,7 @@ list."
   (message-sort-headers)
   (message-hide-headers)
   (set-buffer-modified-p nil)
+  (notmuch-mua-maybe-set-window-dedicated)

   (message-goto-to))

@@ -217,6 +252,7 @@ OTHER-ARGS are passed through to `message-mail'."
   (message-sort-headers)
   (message-hide-headers)
   (set-buffer-modified-p nil)
+  (notmuch-mua-maybe-set-window-dedicated)

   (message-goto-to))

@@ -272,8 +308,8 @@ the From: address first."
   (interactive "P")
   (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)))
+  (list (cons "From" (notmuch-mua-prompt-for-sender))
+(notmuch-mua-mail nil nil other-headers nil 
(notmuch-mua-get-switch-function

 (defun notmuch-mua-new-forward-message (&optional prompt-for-sender)
   "Invoke the notmuch message forwarding window.
-- 
1.7.9.5



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

2011-11-09 Thread Thomas Jost
On Fri, 4 Nov 2011 23:51:55 -0400, Austin Clements  wrote:
> This seems like a good option to have, but your approach seems
> unnecessarily complicated. I'm always wary of defcustom's :set because
> it means you can't just setq the variable, which defeats the
> underlying beauty of the customize system.

Actually I use it with setq without any problem. But yes, it's too
complicated...

> You could eliminate the other two variables and compute them on the
> fly, or, if you really feel they may need to be controlled
> independently, make the custom variable a pair or alist (which you can
> hide behind a few const choices).

Computing them on the fly is probably cleaner. But I'm not sure if the
switch-function and dedicated flag must be independent or not. From what
I've tested it's *much* more pleasant to use with the dedicated flag,
but I don't know how other people feel about this...

> Alternatively, it seems like the variable could instead
> take a single function (basically what notmuch-mua-switch-function is
> now) and you could provide two new functions that simply combine
> switch-to-buffer-other-x and set-window-dedicated-p.

I've tried that, but for some reason it doesn't work when forwarding a
message: the dedicated flag is reset somewhere inside message-forward,
but I don't know where nor why. (I haven't investigated much though.)

> The defcustom would be more user-friendly if it gave a choice between
> const values, rather than requiring the user to enter a symbol value
> (and then possibly rejecting it on validation).  Something like
>   :type '(choice (const :tag "Compose in the current window" current-window)
>  (const :tag "Compose mail in a new window"  new-window)
>  (const :tag "Compose mail in a new frame"   new-frame))

Yep, that's much better. I'll try to rewrite this patch using this and
on-the-fly computations of the switch-function and dedicated flag.

Thank you for the review!

Regards,

-- 
Thomas/Schnouki
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: 



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

2011-11-09 Thread Thomas Jost
On Fri, 4 Nov 2011 23:51:55 -0400, Austin Clements  wrote:
> This seems like a good option to have, but your approach seems
> unnecessarily complicated. I'm always wary of defcustom's :set because
> it means you can't just setq the variable, which defeats the
> underlying beauty of the customize system.

Actually I use it with setq without any problem. But yes, it's too
complicated...

> You could eliminate the other two variables and compute them on the
> fly, or, if you really feel they may need to be controlled
> independently, make the custom variable a pair or alist (which you can
> hide behind a few const choices).

Computing them on the fly is probably cleaner. But I'm not sure if the
switch-function and dedicated flag must be independent or not. From what
I've tested it's *much* more pleasant to use with the dedicated flag,
but I don't know how other people feel about this...

> Alternatively, it seems like the variable could instead
> take a single function (basically what notmuch-mua-switch-function is
> now) and you could provide two new functions that simply combine
> switch-to-buffer-other-x and set-window-dedicated-p.

I've tried that, but for some reason it doesn't work when forwarding a
message: the dedicated flag is reset somewhere inside message-forward,
but I don't know where nor why. (I haven't investigated much though.)

> The defcustom would be more user-friendly if it gave a choice between
> const values, rather than requiring the user to enter a symbol value
> (and then possibly rejecting it on validation).  Something like
>   :type '(choice (const :tag "Compose in the current window" current-window)
>  (const :tag "Compose mail in a new window"  new-window)
>  (const :tag "Compose mail in a new frame"   new-frame))

Yep, that's much better. I'll try to rewrite this patch using this and
on-the-fly computations of the switch-function and dedicated flag.

Thank you for the review!

Regards,

-- 
Thomas/Schnouki


pgpMnKvcJHEBa.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2011-11-04 Thread Austin Clements
This seems like a good option to have, but your approach seems
unnecessarily complicated. I'm always wary of defcustom's :set because
it means you can't just setq the variable, which defeats the
underlying beauty of the customize system.? You could eliminate the
other two variables and compute them on the fly, or, if you really
feel they may need to be controlled independently, make the custom
variable a pair or alist (which you can hide behind a few const
choices).  Alternatively, it seems like the variable could instead
take a single function (basically what notmuch-mua-switch-function is
now) and you could provide two new functions that simply combine
switch-to-buffer-other-x and set-window-dedicated-p.

On Oct 25, 2011 3:41 AM, "Thomas Jost"  wrote:
>
> ---
> ?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

s/displayer/displayed/

> + ?be destroyed when the buffer is killed. You may want to
> + ?customize `message-kill-buffer-on-exit' accordingly."

You should also describe 'current-window' in the defcustom docstring.
(Currently you describe the effect of the other two, but not
current-window.)

> + ?: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)))
> +

The defcustom would be more user-friendly if it gave a choice between
const values, rather than requiring the user to enter a symbol value
(and then possibly rejecting it on validation).  Something like
  :type '(choice (const :tag "Compose in the current window" current-window)
 (const :tag "Compose mail in a new window"  new-window)
 (const :tag "Compose mail in a new frame"   new-frame))

> ?(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

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

2011-11-04 Thread Austin Clements
This seems like a good option to have, but your approach seems
unnecessarily complicated. I'm always wary of defcustom's :set because
it means you can't just setq the variable, which defeats the
underlying beauty of the customize system.  You could eliminate the
other two variables and compute them on the fly, or, if you really
feel they may need to be controlled independently, make the custom
variable a pair or alist (which you can hide behind a few const
choices).  Alternatively, it seems like the variable could instead
take a single function (basically what notmuch-mua-switch-function is
now) and you could provide two new functions that simply combine
switch-to-buffer-other-x and set-window-dedicated-p.

On Oct 25, 2011 3:41 AM, "Thomas Jost"  wrote:
>
> ---
>  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

s/displayer/displayed/

> +  be destroyed when the buffer is killed. You may want to
> +  customize `message-kill-buffer-on-exit' accordingly."

You should also describe 'current-window' in the defcustom docstring.
(Currently you describe the effect of the other two, but not
current-window.)

> +  :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)))
> +

The defcustom would be more user-friendly if it gave a choice between
const values, rather than requiring the user to enter a symbol value
(and then possibly rejecting it on validation).  Something like
  :type '(choice (const :tag "Compose in the current window" current-window)
 (const :tag "Compose mail in a new window"  new-window)
 (const :tag "Compose mail in a new frame"   new-frame))

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

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

2011-10-25 Thread 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



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

2011-10-25 Thread 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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch