help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Change backup system


From: Xah
Subject: Re: Change backup system
Date: Tue, 29 Jul 2008 02:29:07 -0700 (PDT)
User-agent: G2/1.0

On Jul 28, 12:00 pm, Florian Lindner <Florian.Lind...@xgm.de> wrote:
> Hello,
>
> can I (I suppose I can, it's Emacs) and how can I change the way Emacs
> backup files. The default is to create a filename~ in the same folder.
>
> My idea is to copy the file to another folder. When I edit and save ~/
> text/file.txt the backup is saved in ~/.emacs.d/backup/home/florian/
> text/file.txt.n with n being a number incremted form 1 to x each save.
>
> Can I configure Emacs like that?


Yes. I have the code that does exactly what you want.

----------------------------------

Q: How to set emacs so that all backups are directed into one folder?
(such as at a directory "~/myBackups")

Use the following lisp code in init file:

; return a backup file path of a give file path
; with full directory mirroring from a root dir
; non-existant dir will be created
(defun my-backup-file-name (fpath)
  "Return a new file path of a given file path.
If the new path's directories does not exist, create them."
  (let (backup-root bpath)
    (setq backup-root "~/.emacs.d/emacs-backup")
    (setq bpath (concat backup-root fpath "~"))
    (make-directory (file-name-directory bpath) bpath)
    bpath
  )
)
(setq make-backup-file-name-function 'my-backup-file-name)

The above will mirror all directories at the given backup dir. For
example, if you are editing a file “/Users/jane/web/xyz/myfile.txt”,
and your backup root is “/Users/jane/.emacs.d/emacs-backup”, then the
backup will be at “/Users/jane/.emacs.d/emacs-backup/Users/jane/web/
xyz/myfile.txt~”.

If you want all backup to be flat in a dir, use the following:

(setq backup-directory-alist '(("" . "~/.emacs.d/emacs-backup")))

This will create backup files flat in the given dir, and the backup
file names will have “!” characters in place of the directory
separator. For example, if you are editing a file at “/Users/jane/web/
xyz/myfile.txt”, and your backup dir is set at “/Users/jane/.emacs.d/
emacs-backup”, then the backup file will be at: “/Users/jane/.emacs.d/
emacs-backup/Users!jane!web!emacs!myfile.txt~”. If you use long file
names or many nested dirs, this scheme will reach file name length
limit quickly.

------------------

The above is a excerpt from:

http://xahlee.org/emacs/emacs_adv_tips.html

The page is part of my emacs and elisp tutorial at

http://xahlee.org/emacs/emacs.html

  Xah
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]