Mercurial > hg > xemacs-beta
comparison lisp/tl/file-detect.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | e04119814345 |
children | c0c698873ce1 |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
1 ;;; file-detect.el --- Emacs Lisp file detection utility | 1 ;;; file-detect.el --- Emacs Lisp file detection utility |
2 | 2 |
3 ;; Copyright (C) 1996,1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1996 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> | 5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> |
6 ;; Version: | 6 ;; Version: |
7 ;; $Id: file-detect.el,v 1.6 1997/03/16 05:55:39 steve Exp $ | 7 ;; $Id: file-detect.el,v 1.1.1.1 1996/12/18 22:43:38 steve Exp $ |
8 ;; Keywords: install, module | 8 ;; Keywords: install, module |
9 | 9 |
10 ;; This file is part of tl (Tiny Library). | 10 ;; This file is part of tl (Tiny Library). |
11 | 11 |
12 ;; This program is free software; you can redistribute it and/or | 12 ;; This program is free software; you can redistribute it and/or |
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | 18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 ;; General Public License for more details. | 20 ;; General Public License for more details. |
21 | 21 |
22 ;; You should have received a copy of the GNU General Public License | 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 | 23 ;; along with This program; see the file COPYING. If not, write to |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
25 ;; Boston, MA 02111-1307, USA. | 25 ;; Boston, MA 02111-1307, USA. |
26 | 26 |
27 ;;; Code: | 27 ;;; Code: |
28 | 28 |
29 (defvar default-load-path load-path) | 29 (defvar default-load-path load-path) |
63 (append load-path (list p)) | 63 (append load-path (list p)) |
64 (cons p load-path) | 64 (cons p load-path) |
65 )) | 65 )) |
66 ))) | 66 ))) |
67 | 67 |
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'. | |
72 | |
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))) | |
76 (if path | |
77 (add-to-list 'load-path path) | |
78 ))) | |
79 | |
80 (defun get-latest-path (pat &optional all-paths) | 68 (defun get-latest-path (pat &optional all-paths) |
81 "Return latest directory in default-load-path | 69 "Return latest directory in default-load-path |
82 which is matched to regexp PAT. | 70 which is matched to regexp PAT. |
83 If optional argument ALL-PATHS is specified, | 71 If optional argument ALL-PATHS is specified, |
84 it is searched from all of load-path instead of default-load-path. | 72 it is searched from all of load-path instead of default-load-path. |
100 )) | 88 )) |
101 (setq paths (cdr paths)) | 89 (setq paths (cdr paths)) |
102 )))) | 90 )))) |
103 | 91 |
104 (defun file-installed-p (file &optional paths) | 92 (defun file-installed-p (file &optional paths) |
105 "Return absolute-path of FILE if FILE exists in PATHS. | 93 "Return t if FILE exists in PATHS. |
106 If PATHS is omitted, `load-path' is used. [file-detect.el]" | 94 If PATHS is omitted, `load-path' is used. [file-detect.el]" |
107 (if (null paths) | 95 (if (null paths) |
108 (setq paths load-path) | 96 (setq paths load-path) |
109 ) | 97 ) |
110 (catch 'tag | 98 (catch 'tag |
115 (throw 'tag path) | 103 (throw 'tag path) |
116 ) | 104 ) |
117 (setq paths (cdr paths)) | 105 (setq paths (cdr paths)) |
118 )))) | 106 )))) |
119 | 107 |
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. [file-detect.el]" | |
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) | 108 (defun module-installed-p (module &optional paths) |
149 "Return t if module is provided or exists in PATHS. | 109 "Return t if module is provided or exists in PATHS. |
150 If PATHS is omitted, `load-path' is used. [file-detect.el]" | 110 If PATHS is omitted, `load-path' is used. [file-detect.el]" |
151 (or (featurep module) | 111 (or (featurep module) |
152 (exec-installed-p (symbol-name module) load-path '(".elc" ".el")) | 112 (let ((name (symbol-name module))) |
153 )) | 113 (if (null paths) |
114 (setq paths load-path) | |
115 ) | |
116 (catch 'tag | |
117 (while paths | |
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) | |
122 )) | |
123 (let ((el-file (concat file ".el"))) | |
124 (if (file-exists-p el-file) | |
125 (throw 'tag el-file) | |
126 )) | |
127 (if (file-exists-p file) | |
128 (throw 'tag file) | |
129 ) | |
130 ) | |
131 (setq paths (cdr paths)) | |
132 ))))) | |
154 | 133 |
155 | 134 |
156 ;;; @ end | 135 ;;; @ end |
157 ;;; | 136 ;;; |
158 | 137 |