Next: , Previous: , Up: Configuration   [Contents][Index]

4.18 Auto-save and Backup configuration

Normally, Emacs writes backup files to the same directory as the original files, but this behavior can be changed via the variable backup-directory-alist. In connection with TRAMP, this can have unexpected side effects. Suppose that you specify that all backups should go to the directory ~/.emacs.d/backups/, and then you edit the file /su:root@localhost:/etc/secretfile. The effect is that the backup file will be owned by you and not by root, thus possibly enabling others to see it even if they were not intended to see it.

When backup-directory-alist is nil (the default), such problems do not occur.

Therefore, it is useful to set special values for TRAMP files. For example, the following statement effectively ‘turns off’ the effect of backup-directory-alist for TRAMP files:

(add-to-list 'backup-directory-alist
             (cons tramp-file-name-regexp nil))

It is also possible to disable backups depending on the used method. The following code disables backups for the su and sudo methods:

(setq backup-enable-predicate
      (lambda (name)
        (and (normal-backup-enable-predicate name)
             (not
              (let ((method (file-remote-p name 'method)))
                (when (stringp method)
                  (member method '("su" "sudo"))))))))

Another possibility is to use the TRAMP variable tramp-backup-directory-alist. This variable has the same meaning like backup-directory-alist. If a TRAMP file is backed up, and DIRECTORY is an absolute local file name, DIRECTORY is prepended with the TRAMP file name prefix of the file to be backed up.

Example:

(add-to-list 'backup-directory-alist
             (cons "." "~/.emacs.d/backups/"))
(setq tramp-backup-directory-alist backup-directory-alist)

The backup file name of /su:root@localhost:/etc/secretfile would be /su:root@localhost:~/.emacs.d/backups/!su:root@localhost:!etc!secretfile~

The same problem can happen with auto-saving files. The variable auto-save-file-name-transforms keeps information, on which directory an auto-saved file should go. By default, it is initialized for TRAMP files to the local temporary directory.

On some versions of Emacs, namely the version built for Debian GNU/Linux, the variable auto-save-file-name-transforms contains the directory where Emacs was built. A workaround is to manually set the variable to a sane value.

If auto-saved files should go into the same directory as the original files, auto-save-file-name-transforms should be set to nil.

Another possibility is to set the variable tramp-auto-save-directory to a proper value.

Next: , Previous: , Up: Configuration   [Contents][Index]