Emacs says,
Buffer foo.txt has shrunk a lot; auto save disabled in that buffer until next real save
when it detects that a lot of text is gone upon auto save time, and disables auto save, unless auto-save-include-big-deletions
is non-nil.
How can I hook into this event of Emacs detecting that the buffer has shrunk a lot? I want to hook into that because I want to set a buffer-local flag whenever buffer gets shrunk a lot so that when I do save-some-buffers
, one of its advices would detect the flag and say to me "hey, this buffer has shrunk a lot. don't forget to see diff to make sure you didn't delete some big chunk by mistake". This would be nice in addition to backups. Simply comparing the size of buffer before save and the saved file would fail to detect the case of adding a lot then deleting a lot by mistake then saving.
The auto-save-hook
gets run before the check that generates that message, so you can replicate the logic in the C code to do what you want. So you can add a function to that hook.
This is (AFAIK) the logic that is used in the C code.
(when (and auto-save-include-big-deletions
buffer-file-name
(> (* 10 (nth 7 (file-attributes buffer-file-name)))
(* 13 (buffer-size)))
(> (nth 7 (file-attributes buffer-file-name)) 5000))
;; do something
)
Note: it looks like the hook gets run even when the auto-save has been disabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With