1 ;;; file-detect.el --- Emacs Lisp file detection utility
3 ;; Copyright (C) 1996,1997 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; $Id: file-detect.el,v 2.0 1997/01/11 17:19:50 morioka Exp $
8 ;; Keywords: install, module
10 ;; This file is part of tl (Tiny Library).
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with This program; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 (defvar default-load-path load-path)
31 (defun add-path (path &rest options)
32 "Add PATH to `load-path' if it exists under `default-load-path'
33 directories and it does not exist in `load-path'.
35 You can use following PATH styles:
36 load-path relative: \"PATH/\"
37 (it is searched from `defaul-load-path')
38 home directory relative: \"~/PATH/\" \"~USER/PATH/\"
39 absolute path: \"/HOO/BAR/BAZ/\"
41 You can specify following OPTIONS:
42 'all-paths search from `load-path'
43 instead of `default-load-path'
44 'append add PATH to the last of `load-path'
47 (let ((rest (if (memq 'all-paths options)
53 (setq p (expand-file-name path (car rest)))
54 (if (file-directory-p p)
57 (setq rest (cdr rest))
59 (not (member p load-path))
62 (if (memq 'append options)
63 (append load-path (list p))
68 (defun add-latest-path (pattern &optional all-paths)
69 "Add latest path matched by PATTERN to `load-path'
70 if it exists under `default-load-path' directories
71 and it does not exist in `load-path'.
73 If optional argument ALL-PATHS is specified, it is searched from all
74 of load-path instead of default-load-path. [file-detect.el]"
75 (let ((path (get-latest-path pattern all-paths)))
77 (add-to-list 'load-path path)
80 (defun get-latest-path (pat &optional all-paths)
81 "Return latest directory in default-load-path
82 which is matched to regexp PAT.
83 If optional argument ALL-PATHS is specified,
84 it is searched from all of load-path instead of default-load-path.
87 (let ((paths (if all-paths
91 (while (setq dir (car paths))
92 (let ((files (sort (directory-files dir t pat t)
93 (function file-newer-than-file-p)))
95 (while (setq file (car files))
96 (if (file-directory-p file)
99 (setq files (cdr files))
101 (setq paths (cdr paths))
104 (defun file-installed-p (file &optional paths)
105 "Return t if FILE exists in PATHS.
106 If PATHS is omitted, `load-path' is used. [file-detect.el]"
108 (setq paths load-path)
113 (setq path (expand-file-name file (car paths)))
114 (if (file-exists-p path)
117 (setq paths (cdr paths))
120 (defun module-installed-p (module &optional paths)
121 "Return t if module is provided or exists in PATHS.
122 If PATHS is omitted, `load-path' is used. [file-detect.el]"
123 (or (featurep module)
124 (let ((name (symbol-name module)))
126 (setq paths load-path)
130 (let ((file (expand-file-name name (car paths))))
131 (let ((elc-file (concat file ".elc")))
132 (if (file-exists-p elc-file)
133 (throw 'tag elc-file)
135 (let ((el-file (concat file ".el")))
136 (if (file-exists-p el-file)
139 (if (file-exists-p file)
143 (setq paths (cdr paths))
150 (provide 'file-detect)
152 ;;; file-detect.el ends here