Article View: gnu.emacs.bug
Article #99019Hack to find-file-noselect for Suns running Automounter
From: Skip Montanaro
Date: Thu, 03 Jan 1991 03:49
Date: Thu, 03 Jan 1991 03:49
80 lines
4276 bytes
4276 bytes
(This isn't really a bug, just a workaround for some weirdness in Sun's
automounter.)
Sun's automounter sticks all its mounts in /tmp_mnt and symlinks to them.
For instance, /net/whiteface on my machine is really a symlink to
/tmp_mnt/net/whiteface.
Normally this poses no problems, but occasionally you wind up with two
buffers that reference the same file, through two different file names.
That can be disastrous if you're not careful. One place this arises
frequently is in *compilation* buffers. The path used to visit files when
parsing errors from compile is the true path, not the symlink, although you
probably visit most files using the symlink. (Normally, users' home
directories on Suns are /home/machine/..., not /tmp_mnt/home/machine/..., so
~/whatever or ~user/something accesses the files whatever and something
through symlinks.)
The following short modification to find-file-noselect fixes this problem.
If the variable automounter-regexp is non-nil, it is presumed to be a regexp
for a path prefix that describes the mount point the Sun automounter uses.
That prefix is mercilessly ripped from the filename argument just after
expand-file-name is called. To use the following piece of code, just toss it
in a file somewhere and load it early in your .emacs file. If you so desire,
find-file-noselect in lisp/files.el can be modified for system-wide
application.
(The version of find-file-noselect that appears below is from Emacs 18.55.
The only change to the function is the three-line addition after the call to
expand-file-name. Simple cut-and-paste.)
----------cut here----------
(defvar automounter-regexp "^/tmp_mnt"
"Prefix tacked on by Sun's automounter. Used to hack it back off.")
(defun find-file-noselect (filename &optional nowarn)
"Read file FILENAME into a buffer and return the buffer.
If a buffer exists visiting FILENAME, return that one,
but verify that the file has not changed since visited or saved.
The buffer is not selected, just returned to the caller."
(setq filename (expand-file-name filename))
(if (and automounter-regexp
(string-match automounter-regexp filename))
(setq filename (substring filename (match-end 0))))
(if (file-directory-p filename)
(if find-file-run-dired
(dired-noselect filename)
(error "%s is a directory." filename))
(let ((buf (get-file-buffer filename))
error)
(if buf
(or nowarn
(verify-visited-file-modtime buf)
(cond ((not (file-exists-p filename))
(error "File %s no longer exists!" filename))
((yes-or-no-p
(if (buffer-modified-p buf)
"File has changed since last visited or saved. Flush your changes? "
"File has changed since last visited or saved. Read from disk? "))
(save-excursion
(set-buffer buf)
(revert-buffer t t)))))
(save-excursion
(setq buf (create-file-buffer filename))
(set-buffer buf)
(erase-buffer)
(condition-case ()
(insert-file-contents filename t)
(file-error
(setq error t)
;; Run find-file-not-found-hooks until one returns non-nil.
(let ((hooks find-file-not-found-hooks))
(while (and hooks
(not (funcall (car hooks))))
(setq hooks (cdr hooks))))))
(setq default-directory (file-name-directory filename))
(after-find-file error (not nowarn))))
buf)))
--
Skip (montanaro@crdgw1.ge.com)
Technical Details
Message-ID:
<MONTNARO.91Jan2224907@spyder.crd.ge.com>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!shelby!apple!usc!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!spyder.crd.ge.com!montnaroShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fb2f1,2dc056bf3a015253,start X-Google-Attributes: gidfb2f1,public X-Google-ArrivalTime: 1991-01-02 19:49:07 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!shelby!apple!usc!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!spyder.crd.ge.com!montnaro From: montnaro@spyder.crd.ge.com (Skip Montanaro) Newsgroups: gnu.emacs.bug Subject: Hack to find-file-noselect for Suns running Automounter Message-ID: <MONTNARO.91Jan2224907@spyder.crd.ge.com> Date: 3 Jan 91 03:49:07 GMT Sender: daemon@tut.cis.ohio-state.edu Reply-To: montanaro@crdgw1.ge.com (Skip Montanaro) Followup-To: gnu.emacs.help Distribution: gnu Organization: GE Corporate Research & Development, Schenectady, NY Lines: 80 Approved: bug-gnu-emacs@prep.ai.mit.edu