Article View: gnu.emacs.help
Article #189594Patch to find-file-noselect for Suns running automounter
From: Skip Montanaro
Date: Thu, 03 Jan 1991 13:19
Date: Thu, 03 Jan 1991 13:19
70 lines
3416 bytes
3416 bytes
(Sorry if this is a repeat. I posted last night, but haven't seen it in the
local newsgroup, so I assume there was a problem.)
The following modified version of find-file-noselect (found in
~emacs/lisp/files.el) trims the prefix Sun's automounter adds to paths, if
it exists.
This prevents some potential nastiness (two writable buffers referencing the
same file) if you happen to visit the same automounted file using both the
symbolic link (often through your home directory using ~ expansion) and the
true path atreturned by getwd(3) (as when files are visited by next-error
when parsing the results of a compile).
I load the file from my .emacs but site administrators may want to replace
find-file-noselect and rebuild Emacs to give all their users this
protection.
To preserve the original behavior, simply set automounter-regexp to nil.
----------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)))
----------cut here----------
--
Skip (montanaro@crdgw1.ge.com)
Technical Details
Message-ID:
<MONTNARO.91Jan3081958@spyder.crd.ge.com>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!zaphod.mps.ohio-state.edu!rpi!crdgw1!montnaroShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,24a8f7188c8673b,start X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1991-01-03 07:08:21 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!zaphod.mps.ohio-state.edu!rpi!crdgw1!montnaro From: montnaro@spyder.crd.ge.com (Skip Montanaro) Newsgroups: gnu.emacs.help Subject: Patch to find-file-noselect for Suns running automounter Message-ID: <MONTNARO.91Jan3081958@spyder.crd.ge.com> Date: 3 Jan 91 13:19:58 GMT Sender: news@crdgw1.crd.ge.com Reply-To: montanaro@crdgw1.ge.com (Skip Montanaro) Distribution: gnu Organization: GE Corporate Research & Development, Schenectady, NY Lines: 70