Re: Numbered backups

"Pascal Bourguignon (as informatimago at gmail dot com)" <[email protected]>
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>

> On 12 Feb 2026, at 13:17, Tim Bradshaw (as tfb at tfeb dot org) <[email protected]> wrote:
> 
> Emacs can keep numbered backups for files.  Does anyone have anything which would let the LW editor do the same thing?
> 
> The reason for asking is that sometimes I find myself working on things where I change my mind frequently about what I want it to do and I don't want to make a commit each time: just having a bunch of files which I could go back to would be really useful.


Yes, emacs can create numbered backup files. However it is quite peculiar and specific when creating those backup files.
Often there are not enough snapshots to revert to the wanted point in the editing history.
In my opinion, you’d want to create backups at more specific points while editing, and one problem is that you won’t always remember  to explicit save a file to take a snapshot while editing. 
My advice would be to do it inside the editor, saving all the stages of the editing session, and being able to replay it to go back to any stage.

In emacs we could have a command loop hook to do it, keep the editing history, and index it by time or changes (adds/kills), etc, to browse back to any point in history.

In LispWorks, I guess you could do something with an editor-pane change callback.
https://www.lispworks.com/documentation/lw80/capi-m/capi-common-elements-ug-5.htm#CAPI)common-elements-ug-92513


Here’s the detail of when emacs saves a backup:

Emacs creates a backup file only when you save a buffer, and only under specific conditions.

Here is the exact behavior.

1. Backups are created on the first save of a buffer session

When you:

C-x C-s
Emacs will:

Rename the existing file to a backup (file.txt.~N~)

Write the new contents to file.txt

Important:
Emacs creates at most one backup per buffer visit, by default.

That means:

First save after opening → creates backup

Subsequent saves in the same session → do NOT create additional backups

2. When does it create another numbered backup?

A new numbered backup is created when:

You kill the buffer and reopen the file

Or restart Emacs and open the file again

Then save it again

Example timeline:

Open file.txt
Save → file.txt.~1~

Modify
Save → no new backup

Kill buffer
Reopen file.txt
Save → file.txt.~2~
So backups are per visit, not per save.

3. Exception: backup-each-save

If you want a backup on every save, you must use:

(setq backup-each-save t)
⚠ Note: this is rarely used because it generates many versions quickly.

4. Backups are NOT created when

The file does not already exist (first creation)

make-backup-files is nil

The file is in a directory matching backup-inhibited

You save a buffer that hasn’t changed

5. Interaction with numbered backups

With:

(setq version-control t)
Emacs will increment the number each time a backup is created:

file.txt.~1~
file.txt.~2~
file.txt.~3~
But again: only one per buffer visit unless backup-each-save is enabled.

6. Internal trigger logic (simplified)

A backup is made if:

(and make-backup-files
     (not buffer-backed-up)
     (file-exists-p filename))
After the first save, buffer-backed-up becomes t, preventing further backups during that visit.

Summary

Event	Backup created?
First save after opening file	Yes
Subsequent saves in same visit	No
Reopen file and save	Yes
New file creation	No
With backup-each-save = t	Every save
If you want deterministic versioning behavior closer to lightweight VCS semantics, we can configure Emacs accordingly.




-- 
__Pascal Bourguignon__
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.