Subject: bug#19068: [PATCH] Mail file vars aren't derived from customized message-directory

From: Kelly Dean <[email-masked]>
Date: Wed, 28 Jan 2015 10:17:40 +0000

The attached patch fixes this bug.

This patch relies on the varhook feature. For details, see:
https://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00974.html

--- emacs-24.4/lisp/gnus/message.el
+++ emacs-24.4/lisp/gnus/message.el
@@ -120,6 +120,9 @@
   :group 'message-various
   :type 'directory)
 
+(defvar message-directory-varhook nil)
+(put 'message-directory 'varhook 'message-directory-varhook)
+
 (defcustom message-max-buffers 10
   "*How many buffers to keep before starting to kill them off."
   :group 'message-buffers
@@ -1326,6 +1329,16 @@
   :link '(custom-manual "(message)Various Message Variables")
   :type '(choice directory (const :tag "Don't auto-save" nil)))
 
+;; Update message-auto-save-directory when message-directory changes.
+;; Fixes bug #19068.
+(add-hook 'message-directory-varhook
+	  (lambda (_sym _env)
+	    (setq message-auto-save-directory
+		  (if (file-writable-p message-directory)
+		      (file-name-as-directory
+		       (expand-file-name "drafts" message-directory))
+		    "~/"))))
+
 (defcustom message-default-charset
   (and (not (mm-multibyte-p)) 'iso-8859-1)
   "Default charset used in non-MULE Emacsen.