Fanael / persistent-scratch

Preserve the scratch buffer across Emacs sessions
132 stars 14 forks source link

Protection against backing up after accidentally closing the *scratch* buffer #39

Open MarcvdSluys opened 2 months ago

MarcvdSluys commented 2 months ago

As exposed in Issue #23, I also sometimes accidentally kill my *scratch* buffer, resulting in the content of persistent-scratch-save-file and the latest backup being overwritten by "nil". The solution by the OP of that Issue helps to make a backup when killing the buffer and updating the file name for future updates. However, one still needs to manually persistent-scratch-restore-from-file the contents from the old file.

I was wondering whether a(n additional) solution would be to check whether the *scractch* buffer actually exists before writing anything to file (main file or backup). If I understand correctly, (get-buffer "*scratch*") will return nil if the buffer does not exist, and perhaps this could be used to decide whether to write anything at all.

I apologise for my poor knowledge of elisp; I didn't succeed in making a version/patch to actually test this and create a pull request.