Function: emerge-make-auto-save-file-name

emerge-make-auto-save-file-name is a byte-compiled function defined in emerge.el.gz.

Signature

(emerge-make-auto-save-file-name)

Documentation

Return file name to use for auto-saves of current buffer.

Does not consider auto-save-visited-file-name; that is checked before calling this function. You can redefine this for customization. See also auto-save-file-name-p.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/emerge.el.gz
;; Improved auto-save file names.
;; This function fixes many problems with the standard auto-save file names:
;; Auto-save files for non-file buffers get put in the default directory
;; for the buffer, whether that makes sense or not.
;; Auto-save files for file buffers get put in the directory of the file,
;; regardless of whether we can write into it or not.
;; Auto-save files for non-file buffers don't use the process id, so if a
;; user runs more than on Emacs, they can make auto-save files that overwrite
;; each other.
;; To use this function, do:
;;	(fset 'make-auto-save-file-name
;;	      (symbol-function 'emerge-make-auto-save-file-name))
(defun emerge-make-auto-save-file-name ()
  "Return file name to use for auto-saves of current buffer.
Does not consider `auto-save-visited-file-name';
that is checked before calling this function.
You can redefine this for customization.
See also `auto-save-file-name-p'."
  (if buffer-file-name
      ;; if buffer has a file, try the format <file directory>/#<file name>#
      (let ((f (concat (file-name-directory buffer-file-name)
		       "#"
		       (file-name-nondirectory buffer-file-name)
		       "#")))
	(if (file-writable-p f)
	    ;; the file is writable, so use it
	    f
	  ;; the file isn't writable, so use the format
	  ;; ~/#&<file name>&<hash of directory>#
	  (concat (getenv "HOME")
		  "/#&"
		  (file-name-nondirectory buffer-file-name)
		  "&"
		  (emerge-hash-string-into-string
		   (file-name-directory buffer-file-name))
		  "#")))
    ;; if buffer has no file, use the format ~/#%<buffer name>%<process id>#
    (expand-file-name (concat (getenv "HOME")
			      "/#%"
			      ;; quote / into \! and \ into \\
			      (emerge-unslashify-name (buffer-name))
			      "%"
			      (make-temp-name "")
			      "#"))))