From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 5BED3431FD0 for ; Tue, 24 May 2011 15:02:10 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.01 X-Spam-Level: X-Spam-Status: No, score=0.01 tagged_above=-999 required=5 tests=[T_MIME_NO_TEXT=0.01] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4xskCaMDtIqb for ; Tue, 24 May 2011 15:02:09 -0700 (PDT) Received: from arlo.cworth.org (arlo.cworth.org [50.43.72.2]) by olra.theworths.org (Postfix) with ESMTP id 62256431FB6 for ; Tue, 24 May 2011 15:02:09 -0700 (PDT) Received: from yoom.home.cworth.org (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 1A92329A058; Tue, 24 May 2011 15:02:08 -0700 (PDT) Received: by yoom.home.cworth.org (Postfix, from userid 1000) id 197E925417E; Tue, 24 May 2011 15:02:08 -0700 (PDT) From: Carl Worth To: Stewart Smith , notmuch Subject: [PATCH] emacs: Allow user to choose "From" address when composing a new message. In-Reply-To: <87wrhfvk6a.fsf@yoom.home.cworth.org> References: <87vcxb0za4.fsf@flamingspork.com> <87wrhfvk6a.fsf@yoom.home.cworth.org> User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu) Date: Tue, 24 May 2011 15:02:01 -0700 Message-ID: <87lixvvjty.fsf@yoom.home.cworth.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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, 24 May 2011 22:02:10 -0000 --=-=-= Content-Transfer-Encoding: quoted-printable In order to select a From address, the user simply presses M instead of m to begin composing a message. By default the list of names/addresses to be used during completion will be automatically generated by the settings in the notmuch configuration file. The user can customize the notmuch-identities variable to provide an alternate list. =2D-- emacs/notmuch-hello.el | 3 ++- emacs/notmuch-mua.el | 40 ++++++++++++++++++++++++++++++++++++++-- emacs/notmuch.el | 3 ++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index e58dd24..5f3bcc8 100644 =2D-- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -298,7 +298,8 @@ should be. Returns a cons cell `(tags-per-line width)'." (define-key map "=3D" 'notmuch-hello-update) (define-key map "G" 'notmuch-hello-poll-and-update) (define-key map (kbd "") 'widget-backward) =2D (define-key map "m" 'notmuch-mua-mail) + (define-key map "m" 'notmuch-mua-new-mail) + (define-key map "M" 'notmuch-mua-new-mail-prompt-for-sender) (define-key map "s" 'notmuch-hello-goto-search) map) "Keymap for \"notmuch hello\" buffers.") diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el index dc7b386..76bcba4 100644 =2D-- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -118,8 +118,7 @@ list." =20 (defun notmuch-mua-mail (&optional to subject other-headers continue switch-function yank-action send-actions) =2D "Invoke the notmuch mail composition window." =2D (interactive) + "Invoke the notmuch mail composition window with optional headers." =20 (when notmuch-mua-user-agent-function (let ((user-agent (funcall notmuch-mua-user-agent-function))) @@ -138,6 +137,43 @@ list." =20 (message-goto-to)) =20 +(defcustom notmuch-identities nil + "Identities that can be used as the From: address when composing a new m= essage. + +If this variable is left unset, then a list will be constructed from the +name and addresses configured in the notmuch configuration file." + :group 'notmuch + :type '(repeat string)) + +(defun notmuch-mua-sender-collection () + (if notmuch-identities + notmuch-identities + (mapcar (lambda (address) + (concat (notmuch-user-name) " <" address ">")) + (cons (notmuch-user-primary-email) (notmuch-user-other-email))))) + +(defun notmuch-mua-new-mail-from (&optional sender) + (if sender + (notmuch-mua-mail nil nil (list (cons 'from sender))) + (notmuch-mua-mail))) + +(defvar notmuch-mua-sender-history nil) + +(defun notmuch-mua-new-mail (&optional prompt-for-sender) + "Begin composing a new email with notmuch." + (interactive "P") + (if prompt-for-sender + (let* ((collection (notmuch-mua-sender-collection)) + (sender (ido-completing-read "Send mail From: " collection + nil 'confirm nil 'notmuch-mua-sender-history (car collection)))) + (notmuch-mua-new-mail-from sender)) + (notmuch-mua-mail))) + +(defun notmuch-mua-new-mail-prompt-for-sender () + "Begin composing a new email with notmuch, and prompt for the From: addr= ess." + (interactive) + (notmuch-mua-new-mail t)) + (defun notmuch-mua-send-and-exit (&optional arg) (interactive "P") (message-send-and-exit arg)) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 64f72a0..0c1c8d0 100644 =2D-- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -204,7 +204,8 @@ For a mouse binding, return nil." (define-key map "p" 'notmuch-search-previous-thread) (define-key map "n" 'notmuch-search-next-thread) (define-key map "r" 'notmuch-search-reply-to-thread) =2D (define-key map "m" 'notmuch-mua-mail) + (define-key map "m" 'notmuch-mua-new-mail) + (define-key map "M" 'notmuch-mua-new-mail-prompt-for-sender) (define-key map "s" 'notmuch-search) (define-key map "o" 'notmuch-search-toggle-order) (define-key map "c" 'notmuch-search-stash-map) =2D-=20 1.7.5.1 --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk3cKtkACgkQ6JDdNq8qSWj4wQCff9dg7GDRYtPCdayNVHe+KaYm sOoAn2YyqYJcnm1tD6FwQ1FsE5zgtUE7 =AJzE -----END PGP SIGNATURE----- --=-=-=--