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

Austin Clements amdragon at mit.edu
Fri Nov 4 20:51:55 PDT 2011


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" <schnouki at schnouki.net> 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-forward-message (&optional prompt-for-sender)
>   "Invoke the notmuch message forwarding window.
> --
> 1.7.7
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list