daryl@ihlpe.UUCP (10/31/87)
The project I work on deals with many different types of machines. Since
we attempt to share source where ever possible, we use the VPATH
mechanism found in AT&T UNIXes. I wrote this MLISP function to find a
file anywhere along the VPATH. Typically our VPATHes look something like:
VPATH=~/mymods:/othermachine/me/mymods.src:~testbed/obj:~testbed/src
This MLISP function replaces the visit-file function. It was written on an
SVR3 3B2/400 running UNIPRESS emacs. It also works correctly on the sun 3
workstations also running UNIPRESS emacs. Since UNIPRESS emacs is the
commercial follow on to Gmacs, it should work on those emacses with little
or no change.
This was a quick 1AM hack, so please be tolerant if you come across any
errors.
Enjoy.
Daryl Monge UUCP: ...!ihnp4!ihcae!daryl
AT&T CIS: 72717,65
Bell Labs, Naperville, Ill AT&T 312-979-3603
------------------------------ Cut Here ------------------------------
; vpath-visit-file - Attempt to find the requested file along the VPATH
;
(defun (vpath-visit-file $still-looking vpath ind path $file devnode
; Make sure we have a file name either as an argument, or interactively
(setq $file
(if (interactive)
(get-tty-file "VPATH visit file: ")
(arg 1)
)
)
; If the file exists as written, access it. This retains simple
; operation of the old file-exists function so you can bind vpath
; visit-file to ^X^V
(setq $still-looking 1)
(if (!= (file-exists $file) 0)
(progn (visit-file $file) ( setq $still-looking 0))
(progn
(error-occurred (setq vpath (getenv "VPATH")))
; We must calculate the relative devnode directory of the current
; working directory and the first node in the vpath list. If that
; cannot be done, we fail to find the file.
(setq path (substr vpath 1 (- (index vpath ":") 1)))
(if (= (substr (working-directory) 0 (length path)) path) (progn
(setq devnode
(substr (working-directory) (+ (length path) 2) 10000))
(setq ind 1)
(while (& $still-looking (!= vpath ""))
(progn
(setq ind (index vpath ":"))
(if (= ind 0) (setq ind 10000))
(setq path (substr vpath 1 (- ind 1)))
(if (!= (file-exists (concat path "/" devnode "/" $file)) 0)
(progn (visit-file (concat path "/" devnode "/" $file))
(setq $still-looking 0))
)
; Strip off the directory we just tried.
(setq vpath (substr vpath (+ ind 1) (length vpath)))
))
))
))
(if $still-looking
(progn
(message "Still looking")
(if (=
(substr (get-tty-string
(concat "There is no such file: " $file " Create? ")
) 0 1)
"y"
) (visit-file $file)
)
)
)
(novalue)
))
(bind-to-key "visit-file" "\^xV")
(bind-to-key "vpath-visit-file" "\^x\^v")