I want to tell Emacs to never auto-save files bigger than ~1MB. I know how to turn off auto-save-mode
when the file size is above a certain limit, but not how to make that function run automatically in every buffer. I don't want to add a mode hook for every major mode.
This was my naive attempt to use auto-save-mode-hook
to solve the problem:
(add-hook 'auto-save-mode-hook
(lambda ()
(if (buffer-file-name)
(if (> (file-attribute-size
(file-attributes
(buffer-file-name)))
1000000)
(auto-save-mode 0))
(auto-save-mode 0))))
I get an error about excessively deep nesting; presumably, running (auto-save-mode 0)
is executing auto-save-mode-hook
again. I'm not quite sure why this would happen, given that it is turning off the mode, not turning it on, but clearly this approach is not going to work as I wrote it. Does anyone have either an alternate strategy or a fix to mine?