Newbie. How would I add this org-mode-hook? (Saving select org files automatically with real-auto-save-mode.) reddit / emacs ---------------------------------------------------------------------- Status-Detective-783 · 2022-03-29 02:13 From [this discussion](https://www.reddit.com/r/emacs/comments/cthui8/ saving_files_automatically_every_few_seconds/exrizpu/), /u/github- alphapapa suggests the possibility of adding the following to the org- mode-hook: (when (s-prefix? (expand-file-name "~/org/") (buffer-file-name (current-buffer)) ) (real-auto-save-mode) ) The provides the feature of limiting the real-auto-save-mode to his ~/org/ directory. I'd like to do this (or something similar), but my current cut-and-paste level of elisp knowledge certainly wouldn't work: (add-hook 'org-mode-hook (when (s-prefix? (expand-file-name "~/org/") (buffer-file-name (current-buffer))) (real-auto-save-mode)) ) How would I add that functionality to my org-mode-hook? Also, what if I might want to extend that to also include some additional arbitrary file or dir? In particular, I *might* want to add my ~/.emacs.d/init.el, but maybe something else as well! ---------------------------------------------------------------------- franburstall · 2022-03-29 06:24 You need supply *functions* to hooks so wrap the form in an anonymous function like so: (add-hook 'org-mode-hook (lambda () (when (s-prefix? (expand-file-name "~/org/") (buffer-file-name (current-buffer))) (real-auto-save-mode)))) ---------------------------------------------------------------------- organic-bookworm · 2022-03-29 07:27 >what if I might want to extend that to also include my some additional arbitrary file or dir? You could use `find-file-hook` instead of `org-mode-hook`. List of functions to be called after a buffer is loaded from a file. Note, that a buffer doesn't have to be associated with a file. E.g. you could enable `org-mode` in the "\*scratch\*" buffer. ---------------------------------------------------------------------- organic-bookworm · 2022-03-29 07:41 Non-essential side notes * There's built-in `string-prefix-p` function. * There's built-in `auto-save-visited-mode`. * to disable `auto-save-visited-mode` in specific buffers, put `(setq-local auto-save-visited-mode nil)` in hooks mentioned. ---------------------------------------------------------------------- Status-Detective-783 · 2022-03-29 12:45 Thanks! That makes sense. ---------------------------------------------------------------------- rguy84 · 2022-03-29 14:34 > (s-prefix? (expand-file-name "~/org/") assuming you have `org-directory` defined, can't you do (when (s-prefix? (org-directory) ...