209
|
1 ;;; packages.el --- Low level support for XEmacs packages
|
|
2
|
|
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Steven L Baur <steve@altair.xemacs.org>
|
|
6 ;; Keywords: internal, lisp, dumped
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
23 ;; 02111-1307, USA.
|
|
24
|
|
25 ;;; Synched up with: Not in FSF
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; This file is dumped with XEmacs.
|
|
30
|
|
31 ;; This file provides low level facilities for XEmacs startup --
|
|
32 ;; particularly regarding the package setup. This code has to run in
|
|
33 ;; what we call "bare temacs" -- i.e. XEmacs without the usual Lisp
|
|
34 ;; environment. Pay special attention:
|
|
35
|
|
36 ;; - not to use the `lambda' macro. Use #'(lambda ...) instead.
|
|
37 ;; (this goes for any package loaded before `subr.el'.)
|
|
38 ;;
|
|
39 ;; - not to use macros, because they are not yet available (and this
|
|
40 ;; file must be loadable uncompiled.) This rules out CL-style
|
|
41 ;; macros like `when', for instance.
|
|
42 ;;
|
|
43 ;; - not to use `defcustom'. If you must add user-customizable
|
|
44 ;; variables here, use `defvar', and add the variable to
|
|
45 ;; `cus-start.el'.
|
|
46
|
|
47 ;; Because of all this, make sure that the stuff you put here really
|
|
48 ;; belongs here.
|
|
49
|
|
50
|
|
51 ;;; Code:
|
|
52
|
|
53 (defvar autoload-file-name "auto-autoloads.el"
|
|
54 "Filename that autoloads are expected to be found in.")
|
|
55
|
|
56 (defvar packages-hardcoded-lisp
|
|
57 '(
|
|
58 ;; "startup"
|
|
59 )
|
|
60 "Lisp packages that are always dumped with XEmacs")
|
|
61
|
|
62 (defvar packages-useful-lisp
|
|
63 '("bytecomp"
|
|
64 "byte-optimize"
|
|
65 "advice"
|
|
66 "shadow"
|
|
67 "cl-macs")
|
|
68 "Lisp packages that need early byte compilation.")
|
|
69
|
|
70 (defvar packages-unbytecompiled-lisp
|
|
71 '("paths.el"
|
|
72 "version.el")
|
|
73 "Lisp packages that should not be byte compiled.")
|
|
74
|
|
75
|
|
76 ;; Copied from help.el, could possibly move it to here permanently.
|
|
77 ;; Unlike the FSF version, our `locate-library' uses the `locate-file'
|
|
78 ;; primitive, which should make it lightning-fast.
|
|
79
|
|
80 (defun locate-library (library &optional nosuffix path interactive-call)
|
|
81 "Show the precise file name of Emacs library LIBRARY.
|
|
82 This command searches the directories in `load-path' like `M-x load-library'
|
|
83 to find the file that `M-x load-library RET LIBRARY RET' would load.
|
|
84 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
|
|
85 to the specified name LIBRARY.
|
|
86
|
|
87 If the optional third arg PATH is specified, that list of directories
|
|
88 is used instead of `load-path'."
|
|
89 (interactive (list (read-string "Locate library: ")
|
|
90 nil nil
|
|
91 t))
|
|
92 (let ((result
|
|
93 (locate-file
|
|
94 library
|
|
95 (or path load-path)
|
|
96 (cond ((or (rassq 'jka-compr-handler file-name-handler-alist)
|
|
97 (and (boundp 'find-file-hooks)
|
|
98 (member 'crypt-find-file-hook find-file-hooks)))
|
|
99 ;; Compression involved.
|
|
100 (if nosuffix
|
|
101 ":.gz:.Z"
|
|
102 ".elc:.elc.gz:elc.Z:.el:.el.gz:.el.Z::.gz:.Z"))
|
|
103 (t
|
|
104 ;; No compression.
|
|
105 (if nosuffix
|
|
106 ""
|
|
107 ".elc:.el:")))
|
|
108 4)))
|
|
109 (and interactive-call
|
|
110 (if result
|
|
111 (message "Library is file %s" result)
|
|
112 (message "No library %s in search path" library)))
|
|
113 result))
|
|
114
|
|
115 (defun packages-add-suffix (str)
|
|
116 (if (null (string-match "\\.el\\'" str))
|
|
117 (concat str ".elc")
|
|
118 str))
|
|
119
|
|
120 (defun list-autoloads-path ()
|
|
121 "List autoloads from precomputed load-path."
|
|
122 (let ((path load-path)
|
|
123 autoloads)
|
|
124 (while path
|
|
125 (if (file-exists-p (concat (car path)
|
|
126 autoload-file-name))
|
|
127 (setq autoloads (cons (concat (car path)
|
|
128 autoload-file-name)
|
|
129 autoloads)))
|
|
130 (setq path (cdr path)))
|
|
131 autoloads))
|
|
132
|
|
133 (defun list-autoloads ()
|
|
134 "List autoload files in (what will be) the normal lisp search path.
|
|
135 This function is used during build to find where the global symbol files so
|
|
136 they can be perused for their useful information."
|
|
137 ;; Source directory may not be initialized yet.
|
|
138 ;; (print (prin1-to-string load-path))
|
|
139 (if (null source-directory)
|
215
|
140 (setq source-directory (concat (car load-path) "./")))
|
213
|
141 (let ((files (directory-files (file-name-as-directory source-directory) t ".*"))
|
209
|
142 file autolist)
|
215
|
143 ;; (print (prin1-to-string source-directory))
|
|
144 ;; (print (prin1-to-string files))
|
209
|
145 (while (setq file (car-safe files))
|
|
146 (if (and (file-directory-p file)
|
|
147 (file-exists-p (concat file "/" autoload-file-name)))
|
|
148 (setq autolist (cons (concat file "/" autoload-file-name)
|
|
149 autolist)))
|
|
150 (setq files (cdr files)))
|
|
151 autolist))
|
|
152
|
|
153 ;; The following function is called from temacs
|
215
|
154 (defun packages-find-packages-1 (package path-only append-p user-package)
|
209
|
155 "Search the supplied directory for associated directories.
|
|
156 The top level is assumed to look like:
|
|
157 info/ Contain texinfo files for lisp installed in this hierarchy
|
|
158 etc/ Contain data files for lisp installled in this hiearchy
|
|
159 lisp/ Contain directories which either have straight lisp code
|
|
160 or are self-contained packages of their own.
|
|
161
|
215
|
162 If the argument `append-p' is non-nil, the found directories will be
|
|
163 appended to the paths, otherwise, they will be prepended.
|
|
164
|
209
|
165 This is an internal function. Do not call it after startup."
|
|
166 ;; Info files
|
|
167 (if (and (null path-only) (file-directory-p (concat package "/info")))
|
|
168 (let ((dir (concat package "/info/")))
|
|
169 (if (not (member dir Info-default-directory-list))
|
|
170 (nconc Info-default-directory-list (list dir)))))
|
|
171 ;; Data files
|
|
172 (if (and (null path-only) (file-directory-p (concat package "/etc")))
|
|
173 (setq data-directory-list
|
215
|
174 (if append-p
|
|
175 (append data-directory-list (list (concat package "/etc/")))
|
|
176 (cons (concat package "/etc/") data-directory-list))))
|
209
|
177 ;; Lisp files
|
|
178 (if (file-directory-p (concat package "/lisp"))
|
|
179 (progn
|
|
180 ; (print (concat "DIR: "
|
|
181 ; (if user-package "[USER]" "")
|
|
182 ; package
|
|
183 ; "/lisp/"))
|
215
|
184 (setq load-path
|
|
185 (if append-p
|
|
186 (append load-path (list (concat package "/lisp/")))
|
|
187 (cons (concat package "/lisp/") load-path)))
|
209
|
188 (if user-package
|
|
189 (condition-case nil
|
|
190 (load (concat package "/lisp/"
|
|
191 (file-name-sans-extension autoload-file-name)))
|
|
192 (t nil)))
|
|
193 (let ((dirs (directory-files (concat package "/lisp/")
|
|
194 t "^[^-.]" nil 'dirs-only))
|
|
195 dir)
|
|
196 (while dirs
|
|
197 (setq dir (car dirs))
|
|
198 ; (print (concat "DIR: " dir "/"))
|
215
|
199 (setq load-path
|
|
200 (if append-p
|
|
201 (append load-path (list (concat dir "/")))
|
|
202 (cons (concat dir "/") load-path)))
|
209
|
203 (if user-package
|
|
204 (condition-case nil
|
|
205 (progn
|
|
206 ; (print
|
|
207 ; (concat dir "/"
|
|
208 ; (file-name-sans-extension autoload-file-name)))
|
|
209 (load
|
|
210 (concat dir "/"
|
|
211 (file-name-sans-extension autoload-file-name))))
|
|
212 (t nil)))
|
215
|
213 (packages-find-packages-1 dir path-only append-p user-package)
|
209
|
214 (setq dirs (cdr dirs)))))))
|
|
215
|
|
216 ;; The following function is called from temacs
|
215
|
217 (defun packages-find-packages-2 (path path-only append-p suppress-user)
|
|
218 "Search the supplied path for associated directories.
|
|
219 If the argument `append-p' is non-nil, the found directories will be
|
|
220 appended to the paths, otherwise, they will be prepended.
|
|
221
|
|
222 This is an internal function. Do not call it after startup."
|
|
223 (let (dir)
|
|
224 (while path
|
|
225 (setq dir (car path))
|
|
226 ;; (prin1 (concat "Find: " (expand-file-name dir) "\n"))
|
|
227 (if (null (and (or suppress-user inhibit-package-init)
|
|
228 (string-match "^~" dir)))
|
|
229 (progn
|
|
230 ;; (print dir)
|
|
231 (packages-find-packages-1 (expand-file-name dir)
|
|
232 path-only
|
|
233 append-p
|
|
234 (string-match "^~" dir))))
|
|
235 (setq path (cdr path)))))
|
|
236
|
|
237 ;; The following function is called from temacs
|
209
|
238 (defun packages-find-packages (pkg-path path-only &optional suppress-user)
|
|
239 "Search the supplied path for additional info/etc/lisp directories.
|
|
240 Lisp directories if configured prior to build time will have equivalent
|
|
241 status as bundled packages.
|
|
242 If the argument `path-only' is non-nil, only the `load-path' will be set,
|
|
243 otherwise data directories and info directories will be added.
|
|
244 If the optional argument `suppress-user' is non-nil, package directories
|
|
245 rooted in a user login directory (like ~/.xemacs) will not be searched.
|
|
246 This is used at dump time to suppress the builder's local environment."
|
215
|
247 (let ((prefix-path nil))
|
|
248 (while (and pkg-path (car pkg-path))
|
|
249 (setq prefix-path (cons (car pkg-path) prefix-path)
|
|
250 pkg-path (cdr pkg-path)))
|
|
251 (packages-find-packages-2 (cdr pkg-path) path-only t suppress-user)
|
|
252 (packages-find-packages-2 prefix-path path-only nil suppress-user)))
|
|
253
|
209
|
254
|
|
255 ;; Data-directory is really a list now. Provide something to search it for
|
|
256 ;; directories.
|
|
257
|
|
258 (defun locate-data-directory (name &optional dir-list)
|
|
259 "Locate a directory in a search path DIR-LIST (a list of directories).
|
|
260 If no DIR-LIST is supplied, it defaults to `data-directory-list'."
|
|
261 (unless dir-list
|
|
262 (setq dir-list data-directory-list))
|
|
263 (let (found found-dir)
|
|
264 (while (and (null found-dir) dir-list)
|
|
265 (setq found (concat (car dir-list) name "/")
|
|
266 found-dir (file-directory-p found))
|
|
267 (or found-dir
|
|
268 (setq found nil))
|
|
269 (setq dir-list (cdr dir-list)))
|
|
270 found))
|
|
271
|
215
|
272 ;; Data-directory is really a list now. Provide something to search it for
|
|
273 ;; files.
|
|
274
|
|
275 (defun locate-data-file (name &optional dir-list)
|
|
276 "Locate a file in a search path DIR-LIST (a list of directories).
|
|
277 If no DIR-LIST is supplied, it defaults to `data-directory-list'."
|
|
278 (unless dir-list
|
|
279 (setq dir-list data-directory-list))
|
|
280 (let (found found-file)
|
|
281 (while (and (null found-file) dir-list)
|
|
282 (setq found (concat (car dir-list) name)
|
|
283 found-file (and (file-exists-p found)
|
|
284 (not (file-directory-p found))))
|
|
285 (or found-file
|
|
286 (setq found nil))
|
|
287 (setq dir-list (cdr dir-list)))
|
|
288 found))
|
|
289
|
209
|
290 ;; If we are being loaded as part of being dumped, bootstrap the rest of the
|
|
291 ;; load-path for loaddefs.
|
|
292 (if (fboundp 'load-gc)
|
|
293 (packages-find-packages package-path t t))
|
|
294
|
|
295 (provide 'packages)
|
|
296
|
|
297 ;;; packages.el ends here
|