1 ;;; file-detect.el --- Emacs Lisp file detection utility
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; $Id: file-detect.el,v 1.6 1996/08/21 11:43:09 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 get-latest-path (pat &optional all-paths)
69 "Return latest directory in default-load-path
70 which is matched to regexp PAT.
71 If optional argument ALL-PATHS is specified,
72 it is searched from all of load-path instead of default-load-path.
75 (let ((paths (if all-paths
79 (while (setq dir (car paths))
80 (let ((files (sort (directory-files dir t pat t)
81 (function file-newer-than-file-p)))
83 (while (setq file (car files))
84 (if (file-directory-p file)
87 (setq files (cdr files))
89 (setq paths (cdr paths))
92 (defun file-installed-p (file &optional paths)
93 "Return t if FILE exists in PATHS.
94 If PATHS is omitted, `load-path' is used. [file-detect.el]"
96 (setq paths load-path)
101 (setq path (expand-file-name file (car paths)))
102 (if (file-exists-p path)
105 (setq paths (cdr paths))
108 (defun module-installed-p (module &optional paths)
109 "Return t if module is provided or exists in PATHS.
110 If PATHS is omitted, `load-path' is used. [file-detect.el]"
111 (or (featurep module)
112 (let ((name (symbol-name module)))
114 (setq paths load-path)
118 (let ((file (expand-file-name name (car paths))))
119 (let ((elc-file (concat file ".elc")))
120 (if (file-exists-p elc-file)
121 (throw 'tag elc-file)
123 (let ((el-file (concat file ".el")))
124 (if (file-exists-p el-file)
127 (if (file-exists-p file)
131 (setq paths (cdr paths))
138 (provide 'file-detect)
140 ;;; file-detect.el ends here