all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Write a file with backups?
@ 2018-01-28 21:42 Lars Ingebrigtsen
  2018-01-29  6:57 ` John Wiegley
  0 siblings, 1 reply; 2+ messages in thread
From: Lars Ingebrigtsen @ 2018-01-28 21:42 UTC (permalink / raw)
  To: emacs-devel

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Write a file with backups?
  2018-01-28 21:42 Write a file with backups? Lars Ingebrigtsen
@ 2018-01-29  6:57 ` John Wiegley
  0 siblings, 0 replies; 2+ messages in thread
From: John Wiegley @ 2018-01-29  6:57 UTC (permalink / raw)
  To: emacs-devel

>>>>> "LI" == Lars Ingebrigtsen <larsi@gnus.org> writes:

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

If the file is under Git, I wrote this to do just what you've described:

    https://hackage.haskell.org/package/git-monitor

I have this hooked up so that if I ever run Magit, it starts one of these
processes for that whole project tree.

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-29  6:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-28 21:42 Write a file with backups? Lars Ingebrigtsen
2018-01-29  6:57 ` John Wiegley

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.