From 96493792a3e2a794381003730685bb28fef65c56 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 6 Aug 2018 08:25:56 +0200 Subject: [PATCH] =?UTF-8?q?Save=20backup=20files=20under=20Emacs=E2=80=99?= =?UTF-8?q?=20cache=20directory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configuration.org | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/configuration.org b/configuration.org index 6ca5799..784e340 100644 --- a/configuration.org +++ b/configuration.org @@ -97,6 +97,19 @@ I set it up early so I can use it in ~use-package~ calls immediately. mult))))) #+END_SRC +*** Make a backup filename under ~user-emacs-cache-directory~ + +Taken from [[http://ergoemacs.org/emacs/emacs_set_backup_into_a_directory.html][Xah’s 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 We need to do things differently, if so. @@ -1047,10 +1060,7 @@ Because I’m a sysadmin, too. (use-package files :ensure nil :config - (setq backup-directory-alist - `((".*" . ,temporary-file-directory))) - (setq auto-save-file-name-transforms - `((".*" ,temporary-file-directory t)))) + (setq make-backup-file-name-function 'xah/backup-file-name)) #+END_SRC ** ~whitespace~