How can I enable auto-save based on filename? I use a naming convention (a prefix to the filename) for my notes and I'd like to enable auto-save for those files.

1 Answer 1


I don't know if there is a "correct" way to make this happen.

What comes to my mind is:

(defvar my-auto-save-regexp "/jdigit")

(defun my-auto-save-mode-fn ()
  (when (string-match my-auto-save-regexp buffer-file-name)
    (auto-save-mode 1)))

(add-hook 'find-file-hook 'my-auto-save-mode-fn)
  • it works, thank you.
    – jdigital
    Jan 13, 2020 at 0:24

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.