-If optional argument ALL-PATHS is specified, it is searched from all
-of load-path instead of default-load-path. [file-detect.el]"
- (let ((path (get-latest-path pattern all-paths)))
- (if path
- (add-to-list 'load-path path)
- )))
-
-(defun get-latest-path (pat &optional all-paths)
- "Return latest directory in default-load-path
-which is matched to regexp PAT.
-If optional argument ALL-PATHS is specified,
-it is searched from all of load-path instead of default-load-path.
-\[file-detect.el]"
- (catch 'tag
- (let ((paths (if all-paths
- load-path
- default-load-path))
- dir)
- (while (setq dir (car paths))
- (let ((files (sort (directory-files dir t pat t)
- (function file-newer-than-file-p)))
- file)
- (while (setq file (car files))
- (if (file-directory-p file)
- (throw 'tag file)
- )
- (setq files (cdr files))
- ))
- (setq paths (cdr paths))
- ))))
-
-(defun file-installed-p (file &optional paths)
- "Return absolute-path of FILE if FILE exists in PATHS.
-If PATHS is omitted, `load-path' is used. [file-detect.el]"
- (if (null paths)
- (setq paths load-path)
- )
- (catch 'tag
- (let (path)
- (while paths
- (setq path (expand-file-name file (car paths)))
- (if (file-exists-p path)
- (throw 'tag path)
- )
- (setq paths (cdr paths))
- ))))
-
-(defvar exec-suffix-list '("")
- "*List of suffixes for executable.")
-
-(defun exec-installed-p (file &optional paths suffixes)
- "Return absolute-path of FILE if FILE exists in PATHS.
-If PATHS is omitted, `exec-path' is used.
-If suffixes is omitted, `exec-suffix-list' is used. [file-detect.el]"
- (or paths
- (setq paths exec-path)
- )
- (or suffixes
- (setq suffixes exec-suffix-list)
- )
- (catch 'tag
- (while paths
- (let ((stem (expand-file-name file (car paths)))
- (sufs suffixes)
- )
- (while sufs
- (let ((file (concat stem (car sufs))))
- (if (file-exists-p file)
- (throw 'tag file)
- ))
- (setq sufs (cdr sufs))
- ))
- (setq paths (cdr paths))
- )))
-
-(defun module-installed-p (module &optional paths)
- "Return t if module is provided or exists in PATHS.
-If PATHS is omitted, `load-path' is used. [file-detect.el]"
- (or (featurep module)
- (exec-installed-p (symbol-name module) load-path '(".elc" ".el"))
- ))