all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: emacs-devel@gnu.org
Subject: Write a file with backups?
Date: Sun, 28 Jan 2018 22:42:42 +0100	[thread overview]
Message-ID: <m3vaflu0bx.fsf@gnus.org> (raw)

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	other threads:[~2018-01-28 21:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-28 21:42 Lars Ingebrigtsen [this message]
2018-01-29  6:57 ` Write a file with backups? John Wiegley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3vaflu0bx.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.