Save backup files under Emacs’ cache directory

This commit is contained in:
Gergely Polonkai 2018-08-06 08:25:56 +02:00
parent fa6d517fe0
commit 96493792a3

View File

@ -97,6 +97,19 @@ I set it up early so I can use it in ~use-package~ calls immediately.
mult))))) mult)))))
#+END_SRC #+END_SRC
*** Make a backup filename under ~user-emacs-cache-directory~
Taken from [[http://ergoemacs.org/emacs/emacs_set_backup_into_a_directory.html][Xahs site]].
#+BEGIN_SRC emacs-lisp
(defun xah/backup-file-name (fpath)
"Return a new file path for FPATH under `user-emacs-cache-directory'"
(let* ((backup-root-dir (concat user-emacs-cache-directory "/backup"))
(file-path (replace-regexp-in-string "[A-Za-z]:" ""))
(backup-file-path (replace-regexp-in-string "//" "/" (concat backup-root-dir file-path "~"))))
(make-directory (file-name-directory backup-file-path) (file-name-directory backup-file-path))
backup-file-path))
#+END_SRC
** Check if we are running under Termux ** Check if we are running under Termux
We need to do things differently, if so. We need to do things differently, if so.
@ -1047,10 +1060,7 @@ Because Im a sysadmin, too.
(use-package files (use-package files
:ensure nil :ensure nil
:config :config
(setq backup-directory-alist (setq make-backup-file-name-function 'xah/backup-file-name))
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t))))
#+END_SRC #+END_SRC
** ~whitespace~ ** ~whitespace~