6

This question is inspired by https://emacs.stackexchange.com/a/7831/ and the below settings borrowed from that answer :

(setq backup-directory-alist '(("." . "~/emacs-backups"))
      version-control 'numbered
      make-backup-files t
      delete-old-versions 'never)

I am wondering if it would be possible that emacs keeps an unlimited backups of a list of files defined by the user and for other files to behave like its usual backup system.

The motivation is that it would be desirable that Emacs keeps several backups of a list of some important files (defined by the user), like ~/.emacs /path/to/my_important_file.txt, (1) by creating a numbered version control of them, like the above code (2) never deletes the old versions and (3) for other files, Emacs keeps its standard backup system.

Added: Based on the answer provided by Drew (suggesting to use local variables and the version-control variable) we can add this at the end of the files that we would like to keep an unlimited number of backups of them (for making the changes permanent, after reopening the file we can answer the question about applying the values of the these variables by !):

;; Local Variables:
;; version-control: t
;; make-backup-files: t
;; delete-old-versions: never
;; End: 

For keeping the last N backups of a file we should add this at the end of that file (for example for N=50):

;; Local Variables:
;; version-control: t
;; make-backup-files: t
;; delete-old-versions: t
;; kept-new-versions: 50
;; kept-old-versions: 0
;; End: 
  • 2
    You don't need to eval: (setq ...) in your local variables comments. Just use, e.g., version-control: t. (And in fact with your setq approach you're probably going to end up not creating buffer-local bindings for those variables; so unless they were already buffer-local, you'd be setting the global values.) – phils Jul 15 '15 at 6:58
  • One more thing: remove the quote from 'never. Symbols are treated as quoted by default in the local variable syntax, so your current line is actually equivalent to (setq-local delete-old-versions (quote (quote never))) – phils Jul 15 '15 at 7:28
  • @phils I updated the post. – Name Jul 15 '15 at 7:34
7

Here are two alternative answers, which both come from reading the Emacs manual, node Backup Names:

  1. Set variable version-control to nil, and then create a numbered backup for each of your "important" files (only). Files that already have numbered backups will continue to get them. Other files will not get numbered backups.

  2. "[S]et version-control locally in an individual buffer to control the making of backups for that buffer's file (*note Locals). You can have Emacs set version-control locally whenever you visit a given file (*note File Variables)."

    This means that you use a file-local value of variable version-control for particular files.

How did I find node Backup Names in the first place? C-h r to visit the Emacs manual, then I hit i for the index and typed backup and hit TAB. I picked the first completion candidate, backup file, which put me in node Backup. And that node told me:

At your option, Emacs can keep either a single backup for each file, or make a series of numbered backup files for each file that you edit. *Note Backup Names.

Then I clicked that link. (Ask Emacs!)

  • 1
    Another way to find this node would be to M-x info-apropos backup RET. – wvxvw Jul 15 '15 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.