; $Header: /usr/build/vile/vile/macros/RCS/search.rc,v 1.3 2001/08/26 19:20:15 tom Exp $
store-procedure SearchForFile
	~local %path %word %test %find %n
	setv %find &trim $pathname
	~if &equal 0 &length %find
		write-message "No filename at the current position"
		~return
	~endif
	~if &seq $majormode ''
		setv %path '.'
	~elseif &seq $majormode 'make'
		setv %path '.:/usr/share/mk'
	~elseif &seq $majormode 'c'
		setv %path '.:/usr/local/include:/usr/include'
	~else
		setv %path &env 'VILE_SEARCH_PATH'
		~if &seq %path ''
			setv %path &env 'CDPATH'
			~if &seq %path ''
				setv %path '.'
			~endif
		~endif
	~endif
	setv %n 0
	~while &not 0
		setv %test ''
		setv %word &token %n $pathlist-separator %path
		~if &seq %word ''
			~break
		~endif
		setv %test &cat %word &cat '/' %find
		~if &rd %test
			~break
		~endif
		setv %n &add %n 1
	~endwhile
	~if &seq %test ''
		setv %test=%find
	~else
		edit-file %test
	~endif
	~if &rd %test
		edit-file %test
	~else
		write-message &cat 'File not found: ' %test
	~endif
~endm
bind-key SearchForFile ^X-e
