[RFC PATCH] emacs: add notmuch-show-resend-message

Subject: [RFC PATCH] emacs: add notmuch-show-resend-message

Date: Fri, 6 Feb 2015 15:38:31 +0200

To: notmuch@notmuchmail.org

Cc: tomi.ollila@iki.fi

From: Tomi Ollila


From: Tomi Ollila <tomi.ollila@iki.fi>

Resend message to new recipients using #'message-resend.

Recipients are read from minibuffer as a comma-separated
string (with some keyboard support including tab completion)

Final confirmation before sending is asked.

The function is bound to 'b' in notmuch-show buffer.
---

RFC, largely due to the implementation of notmuch-address-from-minibuffer
(I like how it works! -- I use it with selection-menu so I have not tested
much how the default completion works (some smokes only))

Also, I don't remember what I was planning in XXX.

 emacs/notmuch-address.el | 24 +++++++++++++++++++++++-
 emacs/notmuch-show.el    |  9 +++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index fa65cd52a318..0cbeed70acc8 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -54,8 +54,11 @@ (defvar notmuch-address-message-alist-member
 
 (defvar notmuch-address-history nil)
 
+(defsubst notmuch--address-message-insinuated ()
+  (memq notmuch-address-message-alist-member message-completion-alist))
+
 (defun notmuch-address-message-insinuate ()
-  (unless (memq notmuch-address-message-alist-member message-completion-alist)
+  (unless (notmuch--address-message-insinuated)
     (setq message-completion-alist
 	  (push notmuch-address-message-alist-member message-completion-alist))))
 
@@ -115,4 +118,23 @@ (defun notmuch-address-locate-command (command)
 
 ;;
 
+(defun notmuch-address-from-minibuffer (prompt)
+  (if (not (notmuch--address-message-insinuated))
+      (read-string prompt)
+    (let ((cmap (copy-keymap minibuffer-local-completion-map))
+	  (rmap (copy-keymap minibuffer-local-map))
+	  (omap minibuffer-local-map))
+      (define-key cmap "," (lambda ()
+			     (interactive) (insert ", ") (exit-minibuffer)))
+      (define-key rmap "\C-i" (lambda () ;; TAB
+			       (interactive)
+			       (let ((enable-recursive-minibuffers t)
+				     (minibuffer-local-map omap))
+				 (notmuch-address-expand-name))))
+      (let ((minibuffer-local-map rmap)
+	    (minibuffer-local-completion-map cmap))
+	(read-string prompt)))))
+
+;;
+
 (provide 'notmuch-address)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7549fbb2d326..1edda5df48f6 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1299,6 +1299,7 @@ (defvar notmuch-show-mode-map
     (define-key map (kbd "<backtab>") 'notmuch-show-previous-button)
     (define-key map (kbd "TAB") 'notmuch-show-next-button)
     (define-key map "f" 'notmuch-show-forward-message)
+    (define-key map "b" 'notmuch-show-resend-message)
     (define-key map "r" 'notmuch-show-reply-sender)
     (define-key map "R" 'notmuch-show-reply)
     (define-key map "|" 'notmuch-show-pipe-message)
@@ -1715,6 +1716,14 @@ (defun notmuch-show-forward-message (&optional prompt-for-sender)
   (with-current-notmuch-show-message
    (notmuch-mua-new-forward-message prompt-for-sender)))
 
+(defun notmuch-show-resend-message (addresses)
+  "Resend the current message."
+  (interactive (list (notmuch-address-from-minibuffer "Resend to: ")))
+  (when (yes-or-no-p (concat "Confirm resend to " addresses " "))
+    (notmuch-show-view-raw-message)
+    (message-resend addresses)
+    (bury-buffer))) ;; XXX see possibility to do in message buffer.
+
 (defun notmuch-show-next-message (&optional pop-at-end)
   "Show the next message.
 
-- 
2.0.0


Thread: