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>
|
235
|
6 ;; Maintainer: Steven L Baur <steve@altair.xemacs.org>
|
209
|
7 ;; Keywords: internal, lisp, dumped
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
24 ;; 02111-1307, USA.
|
|
25
|
|
26 ;;; Synched up with: Not in FSF
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; This file is dumped with XEmacs.
|
|
31
|
|
32 ;; This file provides low level facilities for XEmacs startup --
|
|
33 ;; particularly regarding the package setup. This code has to run in
|
|
34 ;; what we call "bare temacs" -- i.e. XEmacs without the usual Lisp
|
|
35 ;; environment. Pay special attention:
|
|
36
|
|
37 ;; - not to use the `lambda' macro. Use #'(lambda ...) instead.
|
|
38 ;; (this goes for any package loaded before `subr.el'.)
|
|
39 ;;
|
|
40 ;; - not to use macros, because they are not yet available (and this
|
|
41 ;; file must be loadable uncompiled.) This rules out CL-style
|
|
42 ;; macros like `when', for instance.
|
|
43 ;;
|
|
44 ;; - not to use `defcustom'. If you must add user-customizable
|
|
45 ;; variables here, use `defvar', and add the variable to
|
|
46 ;; `cus-start.el'.
|
|
47
|
|
48 ;; Because of all this, make sure that the stuff you put here really
|
|
49 ;; belongs here.
|
|
50
|
|
51
|
|
52 ;;; Code:
|
|
53
|
227
|
54 ;;; Package versioning
|
|
55
|
|
56 (defvar packages-package-list nil
|
|
57 "database of loaded packages and version numbers")
|
|
58
|
235
|
59 (defun package-get-key-1 (info key)
|
|
60 "Locate keyword `key' in list."
|
|
61 (cond ((null info)
|
|
62 nil)
|
|
63 ((eq (car info) key)
|
|
64 (nth 1 info))
|
|
65 (t (package-get-key-1 (cddr info) key))))
|
|
66
|
|
67 (defun package-get-key (name key)
|
|
68 "Get info `key' from package `name'."
|
|
69 (let ((info (assq name packages-package-list)))
|
|
70 (when info
|
|
71 (package-get-key-1 (cdr info) key))))
|
|
72
|
|
73 (defun package-provide (name &rest attributes)
|
|
74 (let ((info (if (and attributes (floatp (car attributes)))
|
|
75 (list :version (car attributes))
|
|
76 attributes)))
|
|
77 (remassq name packages-package-list)
|
|
78 (setq packages-package-list
|
|
79 (cons (cons name info) packages-package-list))))
|
227
|
80
|
|
81 (defun package-require (name version)
|
|
82 (let ((pkg (assq name packages-package-list)))
|
|
83 (cond ((null pkg)
|
|
84 (error "Package %s has not been loaded into this XEmacsen"
|
|
85 name))
|
239
|
86 ((< (package-get-key name :version) version)
|
227
|
87 (error "Need version %g of package %s, got version %g"
|
|
88 version name (cdr pkg)))
|
|
89 (t t))))
|
|
90
|
|
91 ;;; Build time stuff
|
|
92
|
209
|
93 (defvar autoload-file-name "auto-autoloads.el"
|
|
94 "Filename that autoloads are expected to be found in.")
|
|
95
|
|
96 (defvar packages-hardcoded-lisp
|
|
97 '(
|
|
98 ;; "startup"
|
|
99 )
|
|
100 "Lisp packages that are always dumped with XEmacs")
|
|
101
|
|
102 (defvar packages-useful-lisp
|
|
103 '("bytecomp"
|
|
104 "byte-optimize"
|
|
105 "shadow"
|
|
106 "cl-macs")
|
|
107 "Lisp packages that need early byte compilation.")
|
|
108
|
|
109 (defvar packages-unbytecompiled-lisp
|
|
110 '("paths.el"
|
227
|
111 "dumped-lisp.el"
|
|
112 "dumped-pkg-lisp.el"
|
209
|
113 "version.el")
|
|
114 "Lisp packages that should not be byte compiled.")
|
|
115
|
|
116
|
|
117 ;; Copied from help.el, could possibly move it to here permanently.
|
|
118 ;; Unlike the FSF version, our `locate-library' uses the `locate-file'
|
|
119 ;; primitive, which should make it lightning-fast.
|
|
120
|
|
121 (defun locate-library (library &optional nosuffix path interactive-call)
|
|
122 "Show the precise file name of Emacs library LIBRARY.
|
|
123 This command searches the directories in `load-path' like `M-x load-library'
|
|
124 to find the file that `M-x load-library RET LIBRARY RET' would load.
|
|
125 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
|
|
126 to the specified name LIBRARY.
|
|
127
|
|
128 If the optional third arg PATH is specified, that list of directories
|
|
129 is used instead of `load-path'."
|
|
130 (interactive (list (read-string "Locate library: ")
|
|
131 nil nil
|
|
132 t))
|
|
133 (let ((result
|
|
134 (locate-file
|
|
135 library
|
|
136 (or path load-path)
|
|
137 (cond ((or (rassq 'jka-compr-handler file-name-handler-alist)
|
|
138 (and (boundp 'find-file-hooks)
|
|
139 (member 'crypt-find-file-hook find-file-hooks)))
|
|
140 ;; Compression involved.
|
|
141 (if nosuffix
|
|
142 ":.gz:.Z"
|
|
143 ".elc:.elc.gz:elc.Z:.el:.el.gz:.el.Z::.gz:.Z"))
|
|
144 (t
|
|
145 ;; No compression.
|
|
146 (if nosuffix
|
|
147 ""
|
|
148 ".elc:.el:")))
|
|
149 4)))
|
|
150 (and interactive-call
|
|
151 (if result
|
|
152 (message "Library is file %s" result)
|
|
153 (message "No library %s in search path" library)))
|
|
154 result))
|
|
155
|
|
156 (defun packages-add-suffix (str)
|
|
157 (if (null (string-match "\\.el\\'" str))
|
|
158 (concat str ".elc")
|
|
159 str))
|
|
160
|
235
|
161 (defun packages-list-autoloads-path ()
|
209
|
162 "List autoloads from precomputed load-path."
|
|
163 (let ((path load-path)
|
|
164 autoloads)
|
|
165 (while path
|
|
166 (if (file-exists-p (concat (car path)
|
|
167 autoload-file-name))
|
|
168 (setq autoloads (cons (concat (car path)
|
|
169 autoload-file-name)
|
|
170 autoloads)))
|
|
171 (setq path (cdr path)))
|
|
172 autoloads))
|
|
173
|
235
|
174 (defun packages-list-autoloads ()
|
209
|
175 "List autoload files in (what will be) the normal lisp search path.
|
|
176 This function is used during build to find where the global symbol files so
|
|
177 they can be perused for their useful information."
|
|
178 ;; Source directory may not be initialized yet.
|
|
179 ;; (print (prin1-to-string load-path))
|
|
180 (if (null source-directory)
|
215
|
181 (setq source-directory (concat (car load-path) "./")))
|
235
|
182 (let ((files (directory-files (file-name-as-directory source-directory)
|
|
183 t ".*"))
|
209
|
184 file autolist)
|
215
|
185 ;; (print (prin1-to-string source-directory))
|
|
186 ;; (print (prin1-to-string files))
|
209
|
187 (while (setq file (car-safe files))
|
|
188 (if (and (file-directory-p file)
|
|
189 (file-exists-p (concat file "/" autoload-file-name)))
|
|
190 (setq autolist (cons (concat file "/" autoload-file-name)
|
|
191 autolist)))
|
|
192 (setq files (cdr files)))
|
|
193 autolist))
|
|
194
|
235
|
195 ;; The following function cannot be called from a bare temacs
|
|
196 (defun packages-new-autoloads ()
|
|
197 "Return autoloads files that have been added or modified since XEmacs dump."
|
|
198 (require 'loadhist)
|
|
199 (let ((me (concat invocation-directory invocation-name))
|
|
200 (path load-path)
|
|
201 result dir)
|
|
202 (while path
|
|
203 (setq dir (file-truename (car path)))
|
|
204 (let ((autoload-file (file-name-sans-extension (concat
|
|
205 dir
|
|
206 autoload-file-name))))
|
|
207 ;; Check for:
|
|
208 ;; 1. An auto-autoload file that hasn't provided a feature (because
|
|
209 ;; it has been installed since XEmacs was dumped).
|
|
210 ;; 2. auto-autoload.el being newer than the executable
|
|
211 ;; 3. auto-autoload.elc being newer than the executable (the .el
|
|
212 ;; could be missing or compressed)
|
|
213 (when (or (and (null (file-provides autoload-file))
|
|
214 (or (file-exists-p (concat autoload-file ".elc"))
|
|
215 (file-exists-p (concat autoload-file ".el"))))
|
|
216 (and (file-newer-than-file-p (concat autoload-file ".el") me)
|
|
217 (setq autoload-file (concat autoload-file ".el")))
|
|
218 (and (file-newer-than-file-p (concat autoload-file
|
|
219 ".elc")
|
|
220 me)
|
|
221 (setq autoload-file (concat autoload-file ".elc"))))
|
|
222 (push autoload-file result)))
|
|
223 (setq path (cdr path)))
|
|
224 result))
|
|
225
|
|
226 ;; The following function cannot be called from a bare temacs
|
|
227 (defun packages-reload-autoloads ()
|
|
228 "Reload new or updated auto-autoloads files.
|
|
229 This is an extremely dangerous function to call after the user-init-files
|
|
230 is run. Don't call it or you'll be sorry."
|
|
231 (let ((autoload-list (packages-new-autoloads)))
|
|
232 (while autoload-list
|
|
233 (let* ((autoload-file (car autoload-list))
|
|
234 (feature (car-safe (file-provides autoload-file))))
|
|
235 (when feature
|
|
236 ;; (message "(unload-feature %S)" feature)
|
|
237 (unload-feature feature))
|
237
|
238 (condition-case nil
|
|
239 (load autoload-file)
|
|
240 (t nil)))
|
235
|
241 (setq autoload-list (cdr autoload-list)))))
|
|
242
|
|
243 ;; The following function cannot be called from a bare temacs
|
|
244 (defun packages-reload-dumped-lisp ()
|
|
245 "Reload new or updated dumped lisp files (with exceptions).
|
|
246 This is an extremely dangerous function to call at any time."
|
|
247 ;; Nothing for the moment
|
|
248 nil)
|
|
249
|
209
|
250 ;; The following function is called from temacs
|
215
|
251 (defun packages-find-packages-1 (package path-only append-p user-package)
|
209
|
252 "Search the supplied directory for associated directories.
|
|
253 The top level is assumed to look like:
|
|
254 info/ Contain texinfo files for lisp installed in this hierarchy
|
|
255 etc/ Contain data files for lisp installled in this hiearchy
|
|
256 lisp/ Contain directories which either have straight lisp code
|
|
257 or are self-contained packages of their own.
|
|
258
|
215
|
259 If the argument `append-p' is non-nil, the found directories will be
|
|
260 appended to the paths, otherwise, they will be prepended.
|
|
261
|
209
|
262 This is an internal function. Do not call it after startup."
|
|
263 ;; Info files
|
|
264 (if (and (null path-only) (file-directory-p (concat package "/info")))
|
|
265 (let ((dir (concat package "/info/")))
|
|
266 (if (not (member dir Info-default-directory-list))
|
|
267 (nconc Info-default-directory-list (list dir)))))
|
|
268 ;; Data files
|
|
269 (if (and (null path-only) (file-directory-p (concat package "/etc")))
|
|
270 (setq data-directory-list
|
215
|
271 (if append-p
|
|
272 (append data-directory-list (list (concat package "/etc/")))
|
|
273 (cons (concat package "/etc/") data-directory-list))))
|
209
|
274 ;; Lisp files
|
|
275 (if (file-directory-p (concat package "/lisp"))
|
|
276 (progn
|
|
277 ; (print (concat "DIR: "
|
|
278 ; (if user-package "[USER]" "")
|
|
279 ; package
|
|
280 ; "/lisp/"))
|
215
|
281 (setq load-path
|
|
282 (if append-p
|
|
283 (append load-path (list (concat package "/lisp/")))
|
|
284 (cons (concat package "/lisp/") load-path)))
|
227
|
285
|
|
286 ;; Locate and process a dumped-lisp.el file if it exists
|
|
287 (if (and (running-temacs-p)
|
|
288 (file-exists-p (concat package "/lisp/dumped-lisp.el")))
|
|
289 (let (package-lisp)
|
|
290 (load (concat package "/lisp/dumped-lisp.el"))
|
|
291 (if package-lisp
|
|
292 (progn
|
|
293 (if (boundp 'preloaded-file-list)
|
|
294 (setq preloaded-file-list
|
|
295 (append preloaded-file-list package-lisp)))
|
|
296 (if (fboundp 'load-gc)
|
|
297 (setq dumped-lisp-packages
|
|
298 (append dumped-lisp-packages package-lisp)))))))
|
|
299
|
209
|
300 (if user-package
|
233
|
301 (condition-case error
|
209
|
302 (load (concat package "/lisp/"
|
233
|
303 (file-name-sans-extension autoload-file-name))
|
|
304 t)
|
|
305 (error
|
|
306 (warn (format "Autoload error in: %s/lisp/:\n\t%s"
|
|
307 package
|
|
308 (with-output-to-string
|
|
309 (display-error error nil)))))))
|
209
|
310 (let ((dirs (directory-files (concat package "/lisp/")
|
|
311 t "^[^-.]" nil 'dirs-only))
|
|
312 dir)
|
|
313 (while dirs
|
|
314 (setq dir (car dirs))
|
|
315 ; (print (concat "DIR: " dir "/"))
|
215
|
316 (setq load-path
|
|
317 (if append-p
|
|
318 (append load-path (list (concat dir "/")))
|
|
319 (cons (concat dir "/") load-path)))
|
227
|
320
|
|
321 ;; Locate and process a dumped-lisp.el file if it exists
|
|
322 (if (and (running-temacs-p)
|
|
323 (file-exists-p (concat dir "/dumped-lisp.el")))
|
|
324 (let (package-lisp)
|
|
325 (load (concat dir "/dumped-lisp.el"))
|
|
326 (if package-lisp
|
|
327 (progn
|
|
328 (if (boundp 'preloaded-file-list)
|
|
329 (setq preloaded-file-list
|
|
330 (append preloaded-file-list package-lisp)))
|
|
331 (if (fboundp 'load-gc)
|
|
332 (setq dumped-lisp-packages
|
235
|
333 (append dumped-lisp-packages
|
|
334 package-lisp)))))))
|
227
|
335
|
209
|
336 (if user-package
|
233
|
337 (condition-case error
|
209
|
338 (progn
|
|
339 ; (print
|
|
340 ; (concat dir "/"
|
|
341 ; (file-name-sans-extension autoload-file-name)))
|
|
342 (load
|
|
343 (concat dir "/"
|
233
|
344 (file-name-sans-extension autoload-file-name))
|
|
345 t))
|
|
346 (error
|
|
347 (warn (format "Autoload error in: %s/:\n\t%s"
|
|
348 dir
|
|
349 (with-output-to-string
|
|
350 (display-error error nil)))))))
|
215
|
351 (packages-find-packages-1 dir path-only append-p user-package)
|
209
|
352 (setq dirs (cdr dirs)))))))
|
|
353
|
|
354 ;; The following function is called from temacs
|
215
|
355 (defun packages-find-packages-2 (path path-only append-p suppress-user)
|
|
356 "Search the supplied path for associated directories.
|
|
357 If the argument `append-p' is non-nil, the found directories will be
|
|
358 appended to the paths, otherwise, they will be prepended.
|
|
359
|
|
360 This is an internal function. Do not call it after startup."
|
|
361 (let (dir)
|
|
362 (while path
|
|
363 (setq dir (car path))
|
|
364 ;; (prin1 (concat "Find: " (expand-file-name dir) "\n"))
|
|
365 (if (null (and (or suppress-user inhibit-package-init)
|
|
366 (string-match "^~" dir)))
|
|
367 (progn
|
|
368 ;; (print dir)
|
|
369 (packages-find-packages-1 (expand-file-name dir)
|
|
370 path-only
|
|
371 append-p
|
|
372 (string-match "^~" dir))))
|
|
373 (setq path (cdr path)))))
|
|
374
|
|
375 ;; The following function is called from temacs
|
209
|
376 (defun packages-find-packages (pkg-path path-only &optional suppress-user)
|
|
377 "Search the supplied path for additional info/etc/lisp directories.
|
|
378 Lisp directories if configured prior to build time will have equivalent
|
|
379 status as bundled packages.
|
|
380 If the argument `path-only' is non-nil, only the `load-path' will be set,
|
|
381 otherwise data directories and info directories will be added.
|
|
382 If the optional argument `suppress-user' is non-nil, package directories
|
|
383 rooted in a user login directory (like ~/.xemacs) will not be searched.
|
|
384 This is used at dump time to suppress the builder's local environment."
|
215
|
385 (let ((prefix-path nil))
|
|
386 (while (and pkg-path (car pkg-path))
|
|
387 (setq prefix-path (cons (car pkg-path) prefix-path)
|
|
388 pkg-path (cdr pkg-path)))
|
|
389 (packages-find-packages-2 (cdr pkg-path) path-only t suppress-user)
|
|
390 (packages-find-packages-2 prefix-path path-only nil suppress-user)))
|
|
391
|
209
|
392
|
|
393 ;; Data-directory is really a list now. Provide something to search it for
|
|
394 ;; directories.
|
|
395
|
|
396 (defun locate-data-directory (name &optional dir-list)
|
|
397 "Locate a directory in a search path DIR-LIST (a list of directories).
|
|
398 If no DIR-LIST is supplied, it defaults to `data-directory-list'."
|
|
399 (unless dir-list
|
|
400 (setq dir-list data-directory-list))
|
|
401 (let (found found-dir)
|
|
402 (while (and (null found-dir) dir-list)
|
|
403 (setq found (concat (car dir-list) name "/")
|
|
404 found-dir (file-directory-p found))
|
|
405 (or found-dir
|
|
406 (setq found nil))
|
|
407 (setq dir-list (cdr dir-list)))
|
|
408 found))
|
|
409
|
215
|
410 ;; Data-directory is really a list now. Provide something to search it for
|
|
411 ;; files.
|
|
412
|
|
413 (defun locate-data-file (name &optional dir-list)
|
|
414 "Locate a file in a search path DIR-LIST (a list of directories).
|
239
|
415 If no DIR-LIST is supplied, it defaults to `data-directory-list'.
|
|
416 This function is basically a wrapper over `locate-file'."
|
215
|
417 (unless dir-list
|
|
418 (setq dir-list data-directory-list))
|
239
|
419 (locate-file name dir-list))
|
215
|
420
|
209
|
421 ;; If we are being loaded as part of being dumped, bootstrap the rest of the
|
|
422 ;; load-path for loaddefs.
|
|
423 (if (fboundp 'load-gc)
|
|
424 (packages-find-packages package-path t t))
|
|
425
|
|
426 (provide 'packages)
|
|
427
|
|
428 ;;; packages.el ends here
|