Thread View: gnu.emacs.sources
1 messages
1 total messages
Started by Piercarlo Grandi
Mon, 04 Jan 1993 03:03
pathfind.el: Path finding functions
Author: Piercarlo Grandi
Date: Mon, 04 Jan 1993 03:03
Date: Mon, 04 Jan 1993 03:03
85 lines
3272 bytes
3272 bytes
Here is a simple set of path finding functions, with which I have
added path finding to the Info reader. Version 19 will have a similar
facility, but in the meantime here is mine.
Please note the unusual indentation style, and that I have provided
"executable" comments for exemplification and testing. This is a
smalltalky sort of thing, and should be more common.
;;; Piercarlo Grandi, Aberystwyth, 1992
;; This function will return a pathname if it exists with any of the
;; given suffixes. It does not check for existence of the pathname
;; without any suffix.
; EXAMPLES:
; (path-suffixed-p "/usr/include/types" '(".h"))
; (path-suffixed-p "/usr/include/tar" ".h")
(defun path-suffixed-p (pathname suffixes)
(if (null suffixes) nil
(if (atom suffixes) (setq suffixes (list suffixes)))
(let ((suffixed (concat pathname (car suffixes))))
(if (file-exists-p suffixed) suffixed
(path-suffixed-p pathname (cdr suffixes))
)
)
)
)
;; This function will return a complete pathname composed of the prefix
;; followed by the name, followed _optionally_ by one of the suffixes,
;; if such a pathname exist. Prefix and suffix lists are scanned strictly
;; left to right.
; EXAMPLES:
; (path-exists-p "/usr/include" "tar.h" ".h")
; (path-exists-p "/usr/include" "tar" ".h")
; (path-exists-p "/usr/include" "types" ".h")
(defun path-exists-p (prefix name &optional suffixes)
(let ((pathname (expand-file-name name prefix)))
(if (file-exists-p pathname) pathname
(if (null suffixes) nil (path-suffixed-p pathname suffixes))
)
)
)
;; This function will return a complete pathname built by concatenating
;; one of the suffixes with the name with one of the suffixes,
;; if it exists and the given test applied to it is satisfied.
; EXAMPLES:
; (path-find-file '("/usr/include" "/usr/include/sys") "tar.h" ".h" nil)
; (path-find-file '("/usr/include" "/usr/include/sys") "types" ".h" 'file-exists-p)
; (path-find-file load-path "debug" ".elc" nil)
; (path-find-file load-path "calc" '(".elc" ".el"))
(defun path-find-file (prefixes name &optional suffixes test)
(if (null prefixes) nil
(if (atom prefixes) (setq prefixes (list prefixes)))
(let
(
(pathname
(path-suffixed-p
(expand-file-name name (car prefixes))
(or suffixes '(""))
)
)
)
(if (and pathname (or (null test) (apply test (list pathname))))
pathname
(path-find-file (cdr prefixes) name suffixes test)
)
)
)
)
(provide 'pathfind)
--
Piercarlo Grandi, Dept of CS, PC/UW@Aberystwyth <pcg@aber.ac.uk>
E l'italiano cantava, cantava. E le sue disperate invocazioni giunsero
alle orecchie del suo divino protettore, il dio della barzelletta
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads