Function: files--transform-file-name

files--transform-file-name is a byte-compiled function defined in files.el.gz.

Signature

(files--transform-file-name FILENAME TRANSFORMS PREFIX SUFFIX)

Documentation

Transform FILENAME according to TRANSFORMS.

See auto-save-file-name-transforms for the format of TRANSFORMS. PREFIX is prepended to the non-directory portion of the resulting file name, and SUFFIX is appended.

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun files--transform-file-name (filename transforms prefix suffix)
  "Transform FILENAME according to TRANSFORMS.
See `auto-save-file-name-transforms' for the format of
TRANSFORMS.  PREFIX is prepended to the non-directory portion of
the resulting file name, and SUFFIX is appended."
  (save-match-data
    (let (result uniq)
      ;; Apply user-specified translations to the file name.
      (while (and transforms (not result))
        (if (string-match (car (car transforms)) filename)
	    (setq result (replace-match (cadr (car transforms)) t nil
                                        filename)
		  uniq (car (cddr (car transforms)))))
        (setq transforms (cdr transforms)))
      (when result
        (setq filename
              (cond
               ((memq uniq (secure-hash-algorithms))
                (concat
                 (file-name-directory result)
                 (secure-hash uniq filename)))
               (uniq
                (concat
                 (file-name-directory result)
                 (subst-char-in-string
		  ?/ ?!
		  (string-replace
                   "!" "!!" filename))))
	       (t result))))
      (setq result
	    (if (and (eq system-type 'ms-dos)
		     (not (msdos-long-file-names)))
                ;; We truncate the file name to DOS 8+3 limits before
                ;; doing anything else, because the regexp passed to
                ;; string-match below cannot handle extensions longer
                ;; than 3 characters, multiple dots, and other
                ;; atrocities.
                (let ((fn (dos-8+3-filename
			   (file-name-nondirectory buffer-file-name))))
		  (string-match
		   "\\`\\([^.]+\\)\\(\\.\\(..?\\)?.?\\|\\)\\'"
		   fn)
		  (concat (file-name-directory buffer-file-name)
			  prefix (match-string 1 fn)
			  "." (match-string 3 fn) suffix))
	      (concat (file-name-directory filename)
		      prefix
		      (file-name-nondirectory filename)
		      suffix)))
      ;; Make sure auto-save file names don't contain characters
      ;; invalid for the underlying filesystem.
      (expand-file-name
       (if (and (memq system-type '(ms-dos windows-nt cygwin))
                ;; Don't modify remote filenames
                (not (file-remote-p result)))
	   (convert-standard-filename result)
         result)))))