Search code examples
emacsorg-modeautosave

emacs auto save for org-mode only


I'm using auto save back to the original file for my org-mode but I only want it to work for this mode and nothing else. Is that easy to do?

Here are my org-mode options

;; Org-mode options
(add-hook 'org-mode-hook
          'turn-on-visual-line-mode
          'auto-save-mode)
(add-hook 'org-mode-hook '(lambda()
                (setq auto-save-visited-file-name t)
                (setq auto-save-interval 20)))

Note: For my full config please refer to https://github.com/map7/simple_emacs


Solution

  • This should provide you with the customization of the auto-save file name just in org-mode.

    (add-hook 'org-mode-hook 'my-org-mode-autosave-settings)
    (defun my-org-mode-autosave-settings ()
      ;; (auto-save-mode 1)   ; this is unnecessary as it is on by default
      (set (make-local-variable 'auto-save-visited-file-name) t)
      (setq auto-save-interval 20))
    

    Note: Your addition of 'auto-save-mode in the 'org-mode-hook would turn off auto save as it is on by default (unless you've turned it off globally).