Function: tramp-handle-substitute-in-file-name

tramp-handle-substitute-in-file-name is a byte-compiled function defined in tramp.el.gz.

Signature

(tramp-handle-substitute-in-file-name FILENAME)

Documentation

Like substitute-in-file-name for Tramp files.

"//" and "/~" substitute only in the local filename part.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
(defun tramp-handle-substitute-in-file-name (filename)
  "Like `substitute-in-file-name' for Tramp files.
\"//\" and \"/~\" substitute only in the local filename part."
  ;; Check, whether the local part is a quoted file name.
  (if (file-name-quoted-p filename)
      filename
    ;; First, we must replace environment variables.
    (setq filename (tramp-replace-environment-variables filename))
    (with-parsed-tramp-file-name filename nil
      ;; We do not want to replace environment variables, again.  "//"
      ;; has a special meaning at the beginning of a file name on
      ;; Cygwin and MS-Windows, we must remove it.
      (let (process-environment)
	;; Ignore in LOCALNAME everything before "//" or "/~".
	(when (stringp localname)
	  (if (string-match-p (rx "//" (| "/" "~")) localname)
	      (setq filename
                    (replace-regexp-in-string
                     (rx bos (+ "/")) "/" (substitute-in-file-name localname)))
	    (setq filename
		  (concat (file-remote-p filename)
			  (replace-regexp-in-string
                           (rx bos (+ "/")) "/"
			   ;; We must disable cygwin-mount file name
			   ;; handlers and alike.
			   (tramp-run-real-handler
			    #'substitute-in-file-name (list localname)))))))
	filename))))