Reputation: 534
I am successfully using the code below to cause emacs to save many versions of each file. But I cannot figure out what commands you use in emacs to actually load those files into a buffer.
I am expecting some kind of a history viewer command!!! I can find nothing.
(setq backup-directory-alist '(("." . "~/auto-saves")))
(setq version-control t
kept-old-versions 2 kept-new-versions 200
delete-old-versions t backup-by-copying t)
Upvotes: 2
Views: 1419
Reputation: 9437
You can just open the files in which ever directory you're saving them in (~/autosaves
). But the backup-walker package is way better.
Update: I highly recommend using the no-littering
package to keep your ~/.emacs.d
(and $HOME
) clean. Here's my backup config (assuming you have use-package
and melpa set up):
(use-package no-littering)
(setq make-backup-files t
vc-make-backup-files t
version-control t
kept-new-versions 128
kept-old-versions 0
delete-old-versions t
backup-by-copying t)
(defun force-backup-of-buffer ()
(setq buffer-backed-up nil))
(add-hook 'before-save-hook #'force-backup-of-buffer)
(use-package backup-walker)
(let ((dir (no-littering-expand-var-file-name "auto-save/")))
(make-directory dir t)
(add-to-list 'auto-save-file-name-transforms `(".*" ,dir t) 'append))
If you don't want to use no-littering
, set backup-directory-alist
, tramp-persistency-file-name
, tramp-backup-directory-alist
, and tramp-auto-save-directory
.
(setq emacs-persistence-directory
(expand-file-name "var" user-emacs-directory))
(let ((dir (expand-file-name "backup" emacs-persistence-directory)))
(unless (file-directory-p dir)
(make-directory dir t))
(setq backup-directory-alist `(("." . ,dir))))
(let ((backup-dir (concat emacs-persistence-directory "tramp-backup/")))
(setq tramp-persistency-file-name (concat emacs-persistence-directory
"tramp")
tramp-backup-directory-alist `(("." . ,backup-dir))
tramp-auto-save-directory (concat emacs-persistence-directory
"tramp-auto-save/"))
(dolist (d (list tramp-auto-save-directory backup-dir))
(unless (file-exists-p d)
(make-directory d t))))
Side note: auto-save is a different feature than backups. Backups save a copy the first time you save a buffer (C-x C-s
). Above, I have the function force-backup-of-buffer
on before-save-hook
to backup on every save. Autosave saves a copy every time you make a certain number of edits. For a given file, there can be many backups, but there's only one autosave.
Upvotes: 3
Reputation: 534
I am leaving jpkotta's answer as the selected one, since backup-walker seems to work for others. For my OSX box, I could not get Backup-Modes to work, and backup walker is more focused on DIFFS rather than just providing access to backup files.
Here is my hacked solution it is a kinda gross, but it works for me. You will need to edit path names for your environment. (see https://www.emacswiki.org/emacs/ForceBackups for the original) I tried, Backup-Modes, and Backup-Directory https://www.emacswiki.org/emacs/BackupDirectory, but this is the first things that kinda worked.)
What this does: - It fixes emacs so it always does an auto-save (surprisingly this is NOT the default) - it adds the command ``M-x history'' to open the backups directory.
Crude, but it works. So sad to see Emacs die!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; FORCE-BACKUP-OF-BUFFER
;;; (See https://www.emacswiki.org/emacs/ForceBackups)
(defun dao-setup-force-backup-of-buffer()
(setq vc-make-backup-files t) ; Do backups even for version controlled files!
(setq version-control t ; Use version numbers for backups.
kept-new-versions 10 ; Number of newest versions to keep.
kept-old-versions 0 ; Number of oldest versions to keep.
delete-old-versions t ; Don't ask to delete excess backup versions.
backup-by-copying t) ; Copy all files, don't rename them.
(add-hook 'before-save-hook 'force-backup-of-buffer)
)
(defun force-backup-of-buffer ()
;; Make a special "per session" backup at the first save of each
;; emacs session.
(when (not buffer-backed-up)
;; Override the default parameters for per-session backups.
'(let ((backup-directory-alist '(("." . "~/emacs-backups")))
(kept-new-versions 3))
(backup-buffer)))
(backup-buffer)
;; Make a "per save" backup on each save. The first save results in
;; both a per-session and a per-save backup, to keep the numbering
;; of per-save backups consistent.
(let ((buffer-backed-up nil))
(backup-buffer)))
(defun history ()
(interactive)
(dired-find-file "/User/oblinger/emacs-backups")
)
Upvotes: 0