[gnu.emacs.help] Hack to find-file-noselect for Suns running Automounter

montnaro@moose.crd.ge.com (Skip Montanaro) (01/13/91)

Larry Masinter suggested a better solution to removing the Sun automounter
prefix. Rather than modify find-file-noselect, he suggested replacing
expand-file-name with a front-end Lisp function. Since expand-file-name is
lower-level than find-file-noselect, more potentially troublesome filenames
are corrected. In addition to solving the problem for more cases, Larry's
solution is much shorter.

Larry, thanks for the idea. Here's the code.

----------
(require 'cl)

(defvar automounter-regexp "^/tmp_mnt"
  "Prefix tacked on by Sun's automounter. Used to hack it back off.")

(or (fboundp 'unhacked-expand-file-name)
    (setf (symbol-function 'unhacked-expand-file-name)
	  (symbol-function 'expand-file-name)))

(defun expand-file-name (file &optional default)
  "Convert FILENAME to absolute, and canonicalize it.
Second arg DEFAULT is directory to start with if FILENAME is relative (does
not start with slash); if DEFAULT is nil or missing, the current buffer's
value of default-directory is used.  Filenames containing . or .. as
components are simplified; initial ~ is expanded. If the variable
automounter-regexp is non-nil that prefix is stripped from the filename.
See also the function  substitute-in-file-name."
  (let ((filename (unhacked-expand-file-name file default)))
    (if (and automounter-regexp
	     (string-match automounter-regexp filename))
	(setq filename (substring filename (match-end 0))))
    filename))
----------

Skip (montanaro@crdgw1.ge.com)