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
|
227
|
53 ;;; Package versioning
|
|
54
|
|
55 (defvar packages-package-list nil
|
|
56 "database of loaded packages and version numbers")
|
|
57
|
|
58 (defun package-provide (name version)
|
|
59 (if (not (assq name packages-package-list))
|
|
60 (setq packages-package-list
|
|
61 (cons (cons name version) packages-package-list))))
|
|
62
|
|
63 (defun package-require (name version)
|
|
64 (let ((pkg (assq name packages-package-list)))
|
|
65 (cond ((null pkg)
|
|
66 (error "Package %s has not been loaded into this XEmacsen"
|
|
67 name))
|
|
68 ((< (cdr pkg) version)
|
|
69 (error "Need version %g of package %s, got version %g"
|
|
70 version name (cdr pkg)))
|
|
71 (t t))))
|
|
72
|
|
73 ;;; Build time stuff
|
|
74
|
209
|
75 (defvar autoload-file-name "auto-autoloads.el"
|
|
76 "Filename that autoloads are expected to be found in.")
|
|
77
|
|
78 (defvar packages-hardcoded-lisp
|
|
79 '(
|
|
80 ;; "startup"
|
|
81 )
|
|
82 "Lisp packages that are always dumped with XEmacs")
|
|
83
|
|
84 (defvar packages-useful-lisp
|
|
85 '("bytecomp"
|
|
86 "byte-optimize"
|
|
87 "shadow"
|
|
88 "cl-macs")
|
|
89 "Lisp packages that need early byte compilation.")
|
|
90
|
|
91 (defvar packages-unbytecompiled-lisp
|
|
92 '("paths.el"
|
227
|
93 "dumped-lisp.el"
|
|
94 "dumped-pkg-lisp.el"
|
209
|
95 "version.el")
|
|
96 "Lisp packages that should not be byte compiled.")
|
|
97
|
|
98
|
|
99 ;; Copied from help.el, could possibly move it to here permanently.
|
|
100 ;; Unlike the FSF version, our `locate-library' uses the `locate-file'
|
|
101 ;; primitive, which should make it lightning-fast.
|
|
102
|
|
103 (defun locate-library (library &optional nosuffix path interactive-call)
|
|
104 "Show the precise file name of Emacs library LIBRARY.
|
|
105 This command searches the directories in `load-path' like `M-x load-library'
|
|
106 to find the file that `M-x load-library RET LIBRARY RET' would load.
|
|
107 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
|
|
108 to the specified name LIBRARY.
|
|
109
|
|
110 If the optional third arg PATH is specified, that list of directories
|
|
111 is used instead of `load-path'."
|
|
112 (interactive (list (read-string "Locate library: ")
|
|
113 nil nil
|
|
114 t))
|
|
115 (let ((result
|
|
116 (locate-file
|
|
117 library
|
|
118 (or path load-path)
|
|
119 (cond ((or (rassq 'jka-compr-handler file-name-handler-alist)
|
|
120 (and (boundp 'find-file-hooks)
|
|
121 (member 'crypt-find-file-hook find-file-hooks)))
|
|
122 ;; Compression involved.
|
|
123 (if nosuffix
|
|
124 ":.gz:.Z"
|
|
125 ".elc:.elc.gz:elc.Z:.el:.el.gz:.el.Z::.gz:.Z"))
|
|
126 (t
|
|
127 ;; No compression.
|
|
128 (if nosuffix
|
|
129 ""
|
|
130 ".elc:.el:")))
|
|
131 4)))
|
|
132 (and interactive-call
|
|
133 (if result
|
|
134 (message "Library is file %s" result)
|
|
135 (message "No library %s in search path" library)))
|
|
136 result))
|
|
137
|
|
138 (defun packages-add-suffix (str)
|
|
139 (if (null (string-match "\\.el\\'" str))
|
|
140 (concat str ".elc")
|
|
141 str))
|
|
142
|
|
143 (defun list-autoloads-path ()
|
|
144 "List autoloads from precomputed load-path."
|
|
145 (let ((path load-path)
|
|
146 autoloads)
|
|
147 (while path
|
|
148 (if (file-exists-p (concat (car path)
|
|
149 autoload-file-name))
|
|
150 (setq autoloads (cons (concat (car path)
|
|
151 autoload-file-name)
|
|
152 autoloads)))
|
|
153 (setq path (cdr path)))
|
|
154 autoloads))
|
|
155
|
|
156 (defun list-autoloads ()
|
|
157 "List autoload files in (what will be) the normal lisp search path.
|
|
158 This function is used during build to find where the global symbol files so
|
|
159 they can be perused for their useful information."
|
|
160 ;; Source directory may not be initialized yet.
|
|
161 ;; (print (prin1-to-string load-path))
|
|
162 (if (null source-directory)
|
215
|
163 (setq source-directory (concat (car load-path) "./")))
|
213
|
164 (let ((files (directory-files (file-name-as-directory source-directory) t ".*"))
|
209
|
165 file autolist)
|
215
|
166 ;; (print (prin1-to-string source-directory))
|
|
167 ;; (print (prin1-to-string files))
|
209
|
168 (while (setq file (car-safe files))
|
|
169 (if (and (file-directory-p file)
|
|
170 (file-exists-p (concat file "/" autoload-file-name)))
|
|
171 (setq autolist (cons (concat file "/" autoload-file-name)
|
|
172 autolist)))
|
|
173 (setq files (cdr files)))
|
|
174 autolist))
|
|
175
|
|
176 ;; The following function is called from temacs
|
215
|
177 (defun packages-find-packages-1 (package path-only append-p user-package)
|
209
|
178 "Search the supplied directory for associated directories.
|
|
179 The top level is assumed to look like:
|
|
180 info/ Contain texinfo files for lisp installed in this hierarchy
|
|
181 etc/ Contain data files for lisp installled in this hiearchy
|
|
182 lisp/ Contain directories which either have straight lisp code
|
|
183 or are self-contained packages of their own.
|
|
184
|
215
|
185 If the argument `append-p' is non-nil, the found directories will be
|
|
186 appended to the paths, otherwise, they will be prepended.
|
|
187
|
209
|
188 This is an internal function. Do not call it after startup."
|
|
189 ;; Info files
|
|
190 (if (and (null path-only) (file-directory-p (concat package "/info")))
|
|
191 (let ((dir (concat package "/info/")))
|
|
192 (if (not (member dir Info-default-directory-list))
|
|
193 (nconc Info-default-directory-list (list dir)))))
|
|
194 ;; Data files
|
|
195 (if (and (null path-only) (file-directory-p (concat package "/etc")))
|
|
196 (setq data-directory-list
|
215
|
197 (if append-p
|
|
198 (append data-directory-list (list (concat package "/etc/")))
|
|
199 (cons (concat package "/etc/") data-directory-list))))
|
209
|
200 ;; Lisp files
|
|
201 (if (file-directory-p (concat package "/lisp"))
|
|
202 (progn
|
|
203 ; (print (concat "DIR: "
|
|
204 ; (if user-package "[USER]" "")
|
|
205 ; package
|
|
206 ; "/lisp/"))
|
215
|
207 (setq load-path
|
|
208 (if append-p
|
|
209 (append load-path (list (concat package "/lisp/")))
|
|
210 (cons (concat package "/lisp/") load-path)))
|
227
|
211
|
|
212 ;; Locate and process a dumped-lisp.el file if it exists
|
|
213 (if (and (running-temacs-p)
|
|
214 (file-exists-p (concat package "/lisp/dumped-lisp.el")))
|
|
215 (let (package-lisp)
|
|
216 (load (concat package "/lisp/dumped-lisp.el"))
|
|
217 (if package-lisp
|
|
218 (progn
|
|
219 (if (boundp 'preloaded-file-list)
|
|
220 (setq preloaded-file-list
|
|
221 (append preloaded-file-list package-lisp)))
|
|
222 (if (fboundp 'load-gc)
|
|
223 (setq dumped-lisp-packages
|
|
224 (append dumped-lisp-packages package-lisp)))))))
|
|
225
|
209
|
226 (if user-package
|
233
|
227 (condition-case error
|
209
|
228 (load (concat package "/lisp/"
|
233
|
229 (file-name-sans-extension autoload-file-name))
|
|
230 t)
|
|
231 (error
|
|
232 (warn (format "Autoload error in: %s/lisp/:\n\t%s"
|
|
233 package
|
|
234 (with-output-to-string
|
|
235 (display-error error nil)))))))
|
209
|
236 (let ((dirs (directory-files (concat package "/lisp/")
|
|
237 t "^[^-.]" nil 'dirs-only))
|
|
238 dir)
|
|
239 (while dirs
|
|
240 (setq dir (car dirs))
|
|
241 ; (print (concat "DIR: " dir "/"))
|
215
|
242 (setq load-path
|
|
243 (if append-p
|
|
244 (append load-path (list (concat dir "/")))
|
|
245 (cons (concat dir "/") load-path)))
|
227
|
246
|
|
247 ;; Locate and process a dumped-lisp.el file if it exists
|
|
248 (if (and (running-temacs-p)
|
|
249 (file-exists-p (concat dir "/dumped-lisp.el")))
|
|
250 (let (package-lisp)
|
|
251 (load (concat dir "/dumped-lisp.el"))
|
|
252 (if package-lisp
|
|
253 (progn
|
|
254 (if (boundp 'preloaded-file-list)
|
|
255 (setq preloaded-file-list
|
|
256 (append preloaded-file-list package-lisp)))
|
|
257 (if (fboundp 'load-gc)
|
|
258 (setq dumped-lisp-packages
|
|
259 (append dumped-lisp-packages package-lisp)))))))
|
|
260
|
209
|
261 (if user-package
|
233
|
262 (condition-case error
|
209
|
263 (progn
|
|
264 ; (print
|
|
265 ; (concat dir "/"
|
|
266 ; (file-name-sans-extension autoload-file-name)))
|
|
267 (load
|
|
268 (concat dir "/"
|
233
|
269 (file-name-sans-extension autoload-file-name))
|
|
270 t))
|
|
271 (error
|
|
272 (warn (format "Autoload error in: %s/:\n\t%s"
|
|
273 dir
|
|
274 (with-output-to-string
|
|
275 (display-error error nil)))))))
|
215
|
276 (packages-find-packages-1 dir path-only append-p user-package)
|
209
|
277 (setq dirs (cdr dirs)))))))
|
|
278
|
|
279 ;; The following function is called from temacs
|
215
|
280 (defun packages-find-packages-2 (path path-only append-p suppress-user)
|
|
281 "Search the supplied path for associated directories.
|
|
282 If the argument `append-p' is non-nil, the found directories will be
|
|
283 appended to the paths, otherwise, they will be prepended.
|
|
284
|
|
285 This is an internal function. Do not call it after startup."
|
|
286 (let (dir)
|
|
287 (while path
|
|
288 (setq dir (car path))
|
|
289 ;; (prin1 (concat "Find: " (expand-file-name dir) "\n"))
|
|
290 (if (null (and (or suppress-user inhibit-package-init)
|
|
291 (string-match "^~" dir)))
|
|
292 (progn
|
|
293 ;; (print dir)
|
|
294 (packages-find-packages-1 (expand-file-name dir)
|
|
295 path-only
|
|
296 append-p
|
|
297 (string-match "^~" dir))))
|
|
298 (setq path (cdr path)))))
|
|
299
|
|
300 ;; The following function is called from temacs
|
209
|
301 (defun packages-find-packages (pkg-path path-only &optional suppress-user)
|
|
302 "Search the supplied path for additional info/etc/lisp directories.
|
|
303 Lisp directories if configured prior to build time will have equivalent
|
|
304 status as bundled packages.
|
|
305 If the argument `path-only' is non-nil, only the `load-path' will be set,
|
|
306 otherwise data directories and info directories will be added.
|
|
307 If the optional argument `suppress-user' is non-nil, package directories
|
|
308 rooted in a user login directory (like ~/.xemacs) will not be searched.
|
|
309 This is used at dump time to suppress the builder's local environment."
|
215
|
310 (let ((prefix-path nil))
|
|
311 (while (and pkg-path (car pkg-path))
|
|
312 (setq prefix-path (cons (car pkg-path) prefix-path)
|
|
313 pkg-path (cdr pkg-path)))
|
|
314 (packages-find-packages-2 (cdr pkg-path) path-only t suppress-user)
|
|
315 (packages-find-packages-2 prefix-path path-only nil suppress-user)))
|
|
316
|
209
|
317
|
|
318 ;; Data-directory is really a list now. Provide something to search it for
|
|
319 ;; directories.
|
|
320
|
|
321 (defun locate-data-directory (name &optional dir-list)
|
|
322 "Locate a directory in a search path DIR-LIST (a list of directories).
|
|
323 If no DIR-LIST is supplied, it defaults to `data-directory-list'."
|
|
324 (unless dir-list
|
|
325 (setq dir-list data-directory-list))
|
|
326 (let (found found-dir)
|
|
327 (while (and (null found-dir) dir-list)
|
|
328 (setq found (concat (car dir-list) name "/")
|
|
329 found-dir (file-directory-p found))
|
|
330 (or found-dir
|
|
331 (setq found nil))
|
|
332 (setq dir-list (cdr dir-list)))
|
|
333 found))
|
|
334
|
215
|
335 ;; Data-directory is really a list now. Provide something to search it for
|
|
336 ;; files.
|
|
337
|
|
338 (defun locate-data-file (name &optional dir-list)
|
|
339 "Locate a file in a search path DIR-LIST (a list of directories).
|
|
340 If no DIR-LIST is supplied, it defaults to `data-directory-list'."
|
|
341 (unless dir-list
|
|
342 (setq dir-list data-directory-list))
|
|
343 (let (found found-file)
|
|
344 (while (and (null found-file) dir-list)
|
|
345 (setq found (concat (car dir-list) name)
|
|
346 found-file (and (file-exists-p found)
|
|
347 (not (file-directory-p found))))
|
|
348 (or found-file
|
|
349 (setq found nil))
|
|
350 (setq dir-list (cdr dir-list)))
|
|
351 found))
|
|
352
|
209
|
353 ;; If we are being loaded as part of being dumped, bootstrap the rest of the
|
|
354 ;; load-path for loaddefs.
|
|
355 (if (fboundp 'load-gc)
|
|
356 (packages-find-packages package-path t t))
|
|
357
|
|
358 (provide 'packages)
|
|
359
|
|
360 ;;; packages.el ends here
|