Commit 3953c4be authored by Michael Albinus's avatar Michael Albinus
Browse files

Improve tramp-handle-make-auto-save-file-name

* tramp.el (tramp-auto-save-directory): Add :tags.
(tramp-handle-make-auto-save-file-name): Let native
`make-auto-save-file-name' use `auto-save-file-name-transforms',
if `tramp-auto-save-directory' is not set.
parent e70d8747
...@@ -147,9 +147,11 @@ policy for local files." ...@@ -147,9 +147,11 @@ policy for local files."
(defcustom tramp-auto-save-directory nil (defcustom tramp-auto-save-directory nil
"Put auto-save files in this directory, if set. "Put auto-save files in this directory, if set.
The idea is to use a local directory so that auto-saving is faster." The idea is to use a local directory so that auto-saving is faster.
This setting has precedence over `auto-save-file-name-transforms'."
:group 'tramp :group 'tramp
:type '(choice (const nil) string)) :type '(choice (const :tag "Use default" nil)
(directory :tag "Auto save directory name")))
(defcustom tramp-encoding-shell (defcustom tramp-encoding-shell
(if (memq system-type '(windows-nt)) (if (memq system-type '(windows-nt))
...@@ -4006,35 +4008,28 @@ Return the local name of the temporary file." ...@@ -4006,35 +4008,28 @@ Return the local name of the temporary file."
(defun tramp-handle-make-auto-save-file-name () (defun tramp-handle-make-auto-save-file-name ()
"Like `make-auto-save-file-name' for Tramp files. "Like `make-auto-save-file-name' for Tramp files.
Returns a file name in `tramp-auto-save-directory' for autosaving this file." Returns a file name in `tramp-auto-save-directory' for autosaving
(let ((tramp-auto-save-directory tramp-auto-save-directory) this file, if that variable is non-nil."
;; Create directory.
(unless (or (null tramp-auto-save-directory)
(file-exists-p tramp-auto-save-directory))
(make-directory tramp-auto-save-directory t))
(let ((auto-save-file-name-transforms
(if (null tramp-auto-save-directory) auto-save-file-name-transforms))
(buffer-file-name (buffer-file-name
(tramp-subst-strs-in-string (if (null tramp-auto-save-directory)
'(("_" . "|") buffer-file-name
("/" . "_a") (expand-file-name
(":" . "_b") (tramp-subst-strs-in-string
("|" . "__") '(("_" . "|")
("[" . "_l") ("/" . "_a")
("]" . "_r")) (":" . "_b")
(buffer-file-name)))) ("|" . "__")
;; File name must be unique. This is ensured with Emacs 22 (see ("[" . "_l")
;; UNIQUIFY element of `auto-save-file-name-transforms'); but for ("]" . "_r"))
;; all other cases we must do it ourselves. (buffer-file-name))
(when (boundp 'auto-save-file-name-transforms) tramp-auto-save-directory))))
(mapc
(lambda (x)
(when (and (string-match (car x) buffer-file-name)
(not (car (cddr x))))
(setq tramp-auto-save-directory
(or tramp-auto-save-directory
(tramp-compat-temporary-file-directory)))))
(symbol-value 'auto-save-file-name-transforms)))
;; Create directory.
(when tramp-auto-save-directory
(setq buffer-file-name
(expand-file-name buffer-file-name tramp-auto-save-directory))
(unless (file-exists-p tramp-auto-save-directory)
(make-directory tramp-auto-save-directory t)))
;; Run plain `make-auto-save-file-name'. There might be an advice when ;; Run plain `make-auto-save-file-name'. There might be an advice when
;; it is not a magic file name operation (since Emacs 22). ;; it is not a magic file name operation (since Emacs 22).
;; We must deactivate it temporarily. ;; We must deactivate it temporarily.
...@@ -4045,6 +4040,8 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file." ...@@ -4045,6 +4040,8 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file."
(prog1 (prog1
(tramp-run-real-handler 'make-auto-save-file-name nil) (tramp-run-real-handler 'make-auto-save-file-name nil)
(ad-activate 'make-auto-save-file-name))))) (ad-activate 'make-auto-save-file-name)))))
(tramp-run-real-handler 'make-auto-save-file-name nil)
(ad-activate 'make-auto-save-file-name)))))
(unless (tramp-exists-file-name-handler 'make-auto-save-file-name) (unless (tramp-exists-file-name-handler 'make-auto-save-file-name)
(defadvice make-auto-save-file-name (defadvice make-auto-save-file-name
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment