Mercurial > hg > xemacs-beta
comparison lisp/apel/file-detect.el @ 155:43dd3413c7c7 r20-3b4
Import from CVS: tag r20-3b4
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:39:39 +0200 |
parents | |
children | 85ec50267440 |
comparison
equal
deleted
inserted
replaced
154:94141801dd7e | 155:43dd3413c7c7 |
---|---|
1 ;;; file-detect.el --- Emacs Lisp file detection utility | |
2 | |
3 ;; Copyright (C) 1996,1997 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> | |
6 ;; Version: | |
7 ;; $Id: file-detect.el,v 1.1 1997/06/03 04:18:35 steve Exp $ | |
8 ;; Keywords: install, module | |
9 | |
10 ;; This file is part of APEL (A Portable Emacs Library). | |
11 | |
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. | |
16 | |
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. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Code: | |
28 | |
29 (defvar default-load-path load-path) | |
30 | |
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'. | |
34 | |
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/\" | |
40 | |
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'" | |
45 (let ((rest (if (memq 'all-paths options) | |
46 load-path | |
47 default-load-path)) | |
48 p) | |
49 (if (and (catch 'tag | |
50 (while rest | |
51 (setq p (expand-file-name path (car rest))) | |
52 (if (file-directory-p p) | |
53 (throw 'tag p) | |
54 ) | |
55 (setq rest (cdr rest)) | |
56 )) | |
57 (not (member p load-path)) | |
58 ) | |
59 (setq load-path | |
60 (if (memq 'append options) | |
61 (append load-path (list p)) | |
62 (cons p load-path) | |
63 )) | |
64 ))) | |
65 | |
66 (defun add-latest-path (pattern &optional all-paths) | |
67 "Add latest path matched by PATTERN to `load-path' | |
68 if it exists under `default-load-path' directories | |
69 and it does not exist in `load-path'. | |
70 | |
71 If optional argument ALL-PATHS is specified, it is searched from all | |
72 of load-path instead of default-load-path. [file-detect.el]" | |
73 (let ((path (get-latest-path pattern all-paths))) | |
74 (if path | |
75 (add-to-list 'load-path path) | |
76 ))) | |
77 | |
78 (defun get-latest-path (pattern &optional all-paths) | |
79 "Return latest directory in default-load-path | |
80 which is matched to regexp PATTERN. | |
81 If optional argument ALL-PATHS is specified, | |
82 it is searched from all of load-path instead of default-load-path." | |
83 (catch 'tag | |
84 (let ((paths (if all-paths | |
85 load-path | |
86 default-load-path)) | |
87 dir) | |
88 (while (setq dir (car paths)) | |
89 (if (and (file-exists-p dir) | |
90 (file-directory-p dir) | |
91 ) | |
92 (let ((files (sort (directory-files dir t pattern t) | |
93 (function file-newer-than-file-p))) | |
94 file) | |
95 (while (setq file (car files)) | |
96 (if (file-directory-p file) | |
97 (throw 'tag file) | |
98 ) | |
99 (setq files (cdr files)) | |
100 ))) | |
101 (setq paths (cdr paths)) | |
102 )))) | |
103 | |
104 (defun file-installed-p (file &optional paths) | |
105 "Return absolute-path of FILE if FILE exists in PATHS. | |
106 If PATHS is omitted, `load-path' is used." | |
107 (if (null paths) | |
108 (setq paths load-path) | |
109 ) | |
110 (catch 'tag | |
111 (let (path) | |
112 (while paths | |
113 (setq path (expand-file-name file (car paths))) | |
114 (if (file-exists-p path) | |
115 (throw 'tag path) | |
116 ) | |
117 (setq paths (cdr paths)) | |
118 )))) | |
119 | |
120 (defvar exec-suffix-list '("") | |
121 "*List of suffixes for executable.") | |
122 | |
123 (defun exec-installed-p (file &optional paths suffixes) | |
124 "Return absolute-path of FILE if FILE exists in PATHS. | |
125 If PATHS is omitted, `exec-path' is used. | |
126 If suffixes is omitted, `exec-suffix-list' is used." | |
127 (or paths | |
128 (setq paths exec-path) | |
129 ) | |
130 (or suffixes | |
131 (setq suffixes exec-suffix-list) | |
132 ) | |
133 (catch 'tag | |
134 (while paths | |
135 (let ((stem (expand-file-name file (car paths))) | |
136 (sufs suffixes) | |
137 ) | |
138 (while sufs | |
139 (let ((file (concat stem (car sufs)))) | |
140 (if (file-exists-p file) | |
141 (throw 'tag file) | |
142 )) | |
143 (setq sufs (cdr sufs)) | |
144 )) | |
145 (setq paths (cdr paths)) | |
146 ))) | |
147 | |
148 (defun module-installed-p (module &optional paths) | |
149 "Return t if module is provided or exists in PATHS. | |
150 If PATHS is omitted, `load-path' is used." | |
151 (or (featurep module) | |
152 (exec-installed-p (symbol-name module) load-path '(".elc" ".el")) | |
153 )) | |
154 | |
155 | |
156 ;;; @ end | |
157 ;;; | |
158 | |
159 (provide 'file-detect) | |
160 | |
161 ;;; file-detect.el ends here |