emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Write a file with backups?


From: Lars Ingebrigtsen
Subject: Write a file with backups?
Date: Sun, 28 Jan 2018 22:42:42 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

tl;dr: I find myself often writing code that saves data to a file
without visiting that file.  In those cases, Emacs doesn't seem to offer
any mechanism to create backup files easily.  It would be nice if that
existed.

Longer version: When Emacs normally handles files, the user gets
presented with a buffer that visits a file, and when the user saves the
buffer (for the first time in the session), a backup file is created
according to the user's preference (~ files or ~2~ files or whatever).

If, however, you have a mode that maintains data in a structure on a
file (or a lot of files), the user is usually presented with a buffer
that visits no files, and when data is saved (using `write-region'
normally), you get no backup files.

Some special modes create backup files "manually" if they deem that
helpful, and have special variables to customise the names and backup
schemes etc.  That's both wasteful (to have each mode reimplement
backuping (usually badly)) and confusing to the user.

So I think it would be really nice to have a function like
`write-region-with-backups' (or yet another parameter to `write-region')
that would make Emacs go through most of the normal file-backey-upness
stuff.

You'd need to tweak the code, though, to keep the necessary data to
avoid excessive backup file creation: Perhaps some kind of file name
assoc that says when we last backed up the file to emulate how visited
files are backed up (i.e., once per "session").

I think this would be very handy.  If this already exists somewhere,
that would be even better.  :-)

The other way for these modes to get proper backup action is to just
visit the data file in question, but that can get rather unwieldy if you
have a lot of them.  You don't want to pollute the buffer list with
useless data files...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





reply via email to

[Prev in Thread] Current Thread [Next in Thread]