When I create an email message in Emacs (C-x m) I generally save the file before sending it. Emacs generates an automatic filename usually with this format:


How can I customise this file name? I would like to remove the asterisks from the word "message".

  • 2
    I would suggest typing M-x find-function RET message-set-auto-save-file-name RET. Copy that function over to a *scratch* buffer and tinker with it to see if that is what causes the behavior you wish to change. E.g., change "*message*" to *message-foo* and evaluate the modified function; and, then do some mail related stuff. This function doesn't look like it's meant to be customized by the user, so you may need to modify the function and stick the modified function in your .emacs / init.el file. You may also wish to consider wrapping it in a with-eval-after-load 'message ...
    – lawlist
    Commented Jan 27, 2021 at 5:26
  • If I copy the function and modify it in *scratch* and then run my mail program, it works as I expect. If I add the code to my init.el it defaults back to the unmodified code in message.el, a file which, as you have correctly observed cannot be directly modified.
    – Edman
    Commented Jan 27, 2021 at 9:45
  • 1
    Did you wrap the modified function in a with-eval-after-load statement so that the modified function is evaluated after the message.el library gets loaded? If not, when the message.el library loads, it will replace your modified function with the stock/built-in version. (with-eval-after-load 'message (defun message-set-auto-save-file-name ...))
    – lawlist
    Commented Jan 27, 2021 at 14:38
  • Thank you so much. It is working perfectly now. Can we turn your comments into an answer?
    – Edman
    Commented Jan 27, 2021 at 15:16

1 Answer 1


Based upon the current question posed by the O.P., and based upon a prior question by the same O.P. about a week prior thereto wherein he stated that he had recently switched to GNUS mail Opening Gnus messages to the full height of the screen , it seemed appropriate to grep the Emacs source code looking for likely suspects that would generate the stated buffer-name of *message*-20210127-065515. I expected to find a variable with a default value containing the string *message* that is concatenated with the date ..., which could hopefully be customized. Instead, I found that message-set-auto-save-file-name hard-codes the buffer-name with a slight programmatic variation depending upon whether the system-type is a memq of '(ms-dos windows-nt cygwin). As such, modifying the function directly appears to be the most viable method to achieve the desired change.

Because the question was a little unclear as to what the O.P. wants to achieve (i.e., the question title states "Changing file names automatically generated by save-buffer"), I chose not to take the chance of guessing incorrectly as to the proposed modification. As such, this answer is generic in that the O.P. can change the buffer name within the function at issue as he sees fit. We wrap the modified function in a with-eval-after-load statement so that the modified function gets loaded after the stock/built-in version loads -- otherwise, the stock/built-in version would replace the modified version if it loads subsequent to its attempted redefinition. The .emacs / init.el could contain the following form with the modified function at issue: (with-eval-after-load 'message (defun message-set-auto-save-file-name ...))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.