]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: make modifications to message Fcc vars buffer-local
authorDavid Bremner <david@tethera.net>
Sat, 1 Aug 2015 09:44:56 +0000 (11:44 +0200)
committerDavid Bremner <david@tethera.net>
Fri, 7 Aug 2015 19:18:59 +0000 (21:18 +0200)
Previously we globally modified these variables, which tended to cause
problems for people using message-mode, but not notmuch-mua-mail, to
send mail.

User visible changes:

- Calling notmuch-fcc-header-setup is no longer optional. OTOH, it
  seems to do the right thing if notmuch-fcc-dirs is set to nil.

- The Fcc header is visible during message composition

- The name in the mode line is changed, and no longer matches exactly
  the menu label.

- Previously notmuch-mua-send-and-exit was never called.  Either we
  misunderstood define-mail-user-agent, or it had a bug.  So there was
  no difference if the user called message-send-and-exit directly. Now
  there will be.

- User bindings to C-c C-c and C-c C-s in message-mode-map are
  overridden. The user can override them in notmuch-message-mode-map,
  but then they're on their own for Fcc handling.

emacs/notmuch-maildir-fcc.el
emacs/notmuch-mua.el
test/test-lib.sh

index 07eedba22a33a28ae802f260781c3fbfdeeca582..c2f2f4cb127db3d9f2c786b8c8236cffe558193e 100644 (file)
@@ -59,23 +59,19 @@ yet when sending a mail."
  :require 'notmuch-fcc-initialization
  :group 'notmuch-send)
 
  :require 'notmuch-fcc-initialization
  :group 'notmuch-send)
 
-(defun notmuch-fcc-initialization ()
-  "If notmuch-fcc-directories is set,
-   hook them into the message-fcc-handler-function"
-    ;; Set up the message-fcc-handler to move mails to the maildir in Fcc
-    ;; The parameter is set to mark messages as "seen"
-    (setq message-fcc-handler-function
-          (lambda (destdir)
-           (notmuch-maildir-fcc-write-buffer-to-maildir destdir t)))
-    ;; add a hook to actually insert the Fcc header when sending
-    (add-hook 'message-header-setup-hook 'notmuch-fcc-header-setup))
+(defun notmuch-fcc-handler (destdir)
+  "Write buffer to `destdir', marking it as sent
+
+Intended to be dynamically bound to `message-fcc-handler-function'"
+    (notmuch-maildir-fcc-write-buffer-to-maildir destdir t))
 
 (defun notmuch-fcc-header-setup ()
   "Add an Fcc header to the current message buffer.
 
 
 (defun notmuch-fcc-header-setup ()
   "Add an Fcc header to the current message buffer.
 
-Can be added to `message-send-hook' and will set the Fcc header
-based on the values of `notmuch-fcc-dirs'. An existing Fcc header
-will NOT be removed or replaced."
+Sets the Fcc header based on the values of `notmuch-fcc-dirs'.
+
+Originally intended to be use a hook function, but now called directly
+by notmuch-mua-mail"
 
   (let ((subdir
         (cond
 
   (let ((subdir
         (cond
@@ -213,6 +209,5 @@ return t if successful, and nil otherwise."
          (delete-file (concat destdir "/tmp/" msg-id))))
       t)))
 
          (delete-file (concat destdir "/tmp/" msg-id))))
       t)))
 
-(notmuch-fcc-initialization)
 (provide 'notmuch-maildir-fcc)
 
 (provide 'notmuch-maildir-fcc)
 
index 101832157ccb281ae05ad4b97db5d5d9cf7aa2a3..803459a7a7752a948cc42350c716068c07a93b44 100644 (file)
@@ -268,9 +268,13 @@ Note that these functions use `mail-citation-hook' if that is non-nil."
   (message-goto-body)
   (set-buffer-modified-p nil))
 
   (message-goto-body)
   (set-buffer-modified-p nil))
 
-(define-derived-mode notmuch-message-mode message-mode "Notmuch Message"
+(define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"
   "Notmuch message composition mode. Mostly like `message-mode'")
 
   "Notmuch message composition mode. Mostly like `message-mode'")
 
+(define-key notmuch-message-mode-map (kbd "C-c C-c") #'notmuch-mua-send-and-exit)
+(define-key notmuch-message-mode-map (kbd "C-c C-s") #'notmuch-mua-send)
+
+
 (defun notmuch-mua-mail (&optional to subject other-headers &rest other-args)
   "Invoke the notmuch mail composition window.
 
 (defun notmuch-mua-mail (&optional to subject other-headers &rest other-args)
   "Invoke the notmuch mail composition window.
 
@@ -288,6 +292,7 @@ OTHER-ARGS are passed through to `message-mail'."
 
   (apply #'message-mail to subject other-headers other-args)
   (notmuch-message-mode)
 
   (apply #'message-mail to subject other-headers other-args)
   (notmuch-message-mode)
+  (notmuch-fcc-header-setup)
   (message-sort-headers)
   (message-hide-headers)
   (set-buffer-modified-p nil)
   (message-sort-headers)
   (message-hide-headers)
   (set-buffer-modified-p nil)
@@ -401,7 +406,13 @@ will be addressed to all recipients of the source message."
 
 (defun notmuch-mua-send-and-exit (&optional arg)
   (interactive "P")
 
 (defun notmuch-mua-send-and-exit (&optional arg)
   (interactive "P")
-  (message-send-and-exit arg))
+  (let ((message-fcc-handler-function #'notmuch-fcc-handler))
+    (message-send-and-exit arg)))
+
+(defun notmuch-mua-send (&optional arg)
+  (interactive "P")
+  (let ((message-fcc-handler-function #'notmuch-fcc-handler))
+    (message-send arg)))
 
 (defun notmuch-mua-kill-buffer ()
   (interactive)
 
 (defun notmuch-mua-kill-buffer ()
   (interactive)
index db3b6aa198c7319bafb13d7b319f768169877d33..eeb5487bd6a31c29acedc597932b924d4638ffed 100644 (file)
@@ -487,7 +487,7 @@ emacs_deliver_message ()
           (message-goto-body)
           (insert \"${body}\")
           $@
           (message-goto-body)
           (insert \"${body}\")
           $@
-          (message-send-and-exit))"
+          (notmuch-mua-send-and-exit))"
 
     # In case message was sent properly, client waits for confirmation
     # before exiting and resuming control here; therefore making sure
 
     # In case message was sent properly, client waits for confirmation
     # before exiting and resuming control here; therefore making sure
@@ -522,7 +522,7 @@ emacs_fcc_message ()
           (message-goto-body)
           (insert \"${body}\")
           $@
           (message-goto-body)
           (insert \"${body}\")
           $@
-          (message-send-and-exit))" || return 1
+          (notmuch-mua-send-and-exit))" || return 1
     notmuch new >/dev/null
 }
 
     notmuch new >/dev/null
 }