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
|
267
|
51 ;; This file requires find-paths.el.
|
209
|
52
|
|
53 ;;; Code:
|
|
54
|
227
|
55 ;;; Package versioning
|
|
56
|
|
57 (defvar packages-package-list nil
|
|
58 "database of loaded packages and version numbers")
|
|
59
|
276
|
60 (defvar packages-hierarchy-depth 1
|
|
61 "Depth of package hierarchies.")
|
|
62
|
|
63 (defvar packages-load-path-depth 1
|
|
64 "Depth of load-path search in package hierarchies.")
|
|
65
|
267
|
66 (defvar early-packages nil
|
|
67 "Packages early in the load path.")
|
|
68
|
|
69 (defvar early-package-load-path nil
|
|
70 "Load path for packages early in the load path.")
|
|
71
|
272
|
72 (defvar late-packages nil
|
267
|
73 "Packages late in the load path.")
|
|
74
|
|
75 (defvar late-package-load-path nil
|
|
76 "Load path for packages late in the load path.")
|
|
77
|
272
|
78 (defvar last-packages nil
|
|
79 "Packages last in the load path.")
|
|
80
|
|
81 (defvar last-package-load-path nil
|
|
82 "Load path for packages last in the load path.")
|
|
83
|
274
|
84 (defvar package-locations
|
|
85 (list
|
276
|
86 (list (paths-construct-path '("~" ".xemacs"))
|
|
87 'early #'(lambda () t))
|
|
88 (list "site-packages" 'late #'(lambda () t))
|
278
|
89 (list "infodock-packages" 'late #'(lambda () (featurep 'infodock)))
|
274
|
90 (list "mule-packages" 'late #'(lambda () (featurep 'mule)))
|
280
|
91 (list "xemacs-packages" 'late #'(lambda () t))
|
278
|
92 (list "packages" 'late #'(lambda () t)))
|
274
|
93 "Locations of the various package directories.
|
|
94 This is a list each of whose elements describes one directory.
|
|
95 A directory description is a three-element list.
|
|
96 The first element is either an absolute path or a subdirectory
|
|
97 in the XEmacs hierarchy.
|
|
98 The second component is one of the symbols EARLY, LATE, LAST,
|
|
99 depending on the load-path segment the hierarchy is supposed to
|
|
100 show up in.
|
|
101 The third component is a thunk which, if it returns NIL, causes
|
|
102 the directory to be ignored.")
|
|
103
|
235
|
104 (defun package-get-key-1 (info key)
|
|
105 "Locate keyword `key' in list."
|
|
106 (cond ((null info)
|
|
107 nil)
|
|
108 ((eq (car info) key)
|
|
109 (nth 1 info))
|
|
110 (t (package-get-key-1 (cddr info) key))))
|
|
111
|
|
112 (defun package-get-key (name key)
|
|
113 "Get info `key' from package `name'."
|
|
114 (let ((info (assq name packages-package-list)))
|
|
115 (when info
|
|
116 (package-get-key-1 (cdr info) key))))
|
|
117
|
|
118 (defun package-provide (name &rest attributes)
|
|
119 (let ((info (if (and attributes (floatp (car attributes)))
|
|
120 (list :version (car attributes))
|
|
121 attributes)))
|
|
122 (remassq name packages-package-list)
|
|
123 (setq packages-package-list
|
|
124 (cons (cons name info) packages-package-list))))
|
227
|
125
|
|
126 (defun package-require (name version)
|
|
127 (let ((pkg (assq name packages-package-list)))
|
|
128 (cond ((null pkg)
|
|
129 (error "Package %s has not been loaded into this XEmacsen"
|
|
130 name))
|
239
|
131 ((< (package-get-key name :version) version)
|
227
|
132 (error "Need version %g of package %s, got version %g"
|
|
133 version name (cdr pkg)))
|
|
134 (t t))))
|
|
135
|
|
136 ;;; Build time stuff
|
|
137
|
209
|
138 (defvar autoload-file-name "auto-autoloads.el"
|
|
139 "Filename that autoloads are expected to be found in.")
|
|
140
|
|
141 (defvar packages-hardcoded-lisp
|
|
142 '(
|
288
|
143 ;; Nothing at this time
|
209
|
144 )
|
288
|
145 "Lisp packages that are always dumped with XEmacs.
|
|
146 This includes every package that is loaded directly by a package listed
|
|
147 in dumped-lisp.el and is not itself listed.")
|
209
|
148
|
|
149 (defvar packages-useful-lisp
|
|
150 '("bytecomp"
|
|
151 "byte-optimize"
|
|
152 "shadow"
|
|
153 "cl-macs")
|
|
154 "Lisp packages that need early byte compilation.")
|
|
155
|
|
156 (defvar packages-unbytecompiled-lisp
|
|
157 '("paths.el"
|
227
|
158 "dumped-lisp.el"
|
|
159 "dumped-pkg-lisp.el"
|
261
|
160 "version.el"
|
|
161 "Installation.el")
|
209
|
162 "Lisp packages that should not be byte compiled.")
|
|
163
|
|
164
|
|
165 ;; Copied from help.el, could possibly move it to here permanently.
|
|
166 ;; Unlike the FSF version, our `locate-library' uses the `locate-file'
|
|
167 ;; primitive, which should make it lightning-fast.
|
|
168
|
|
169 (defun locate-library (library &optional nosuffix path interactive-call)
|
|
170 "Show the precise file name of Emacs library LIBRARY.
|
|
171 This command searches the directories in `load-path' like `M-x load-library'
|
|
172 to find the file that `M-x load-library RET LIBRARY RET' would load.
|
|
173 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
|
|
174 to the specified name LIBRARY.
|
|
175
|
|
176 If the optional third arg PATH is specified, that list of directories
|
|
177 is used instead of `load-path'."
|
|
178 (interactive (list (read-string "Locate library: ")
|
|
179 nil nil
|
|
180 t))
|
|
181 (let ((result
|
|
182 (locate-file
|
|
183 library
|
|
184 (or path load-path)
|
|
185 (cond ((or (rassq 'jka-compr-handler file-name-handler-alist)
|
|
186 (and (boundp 'find-file-hooks)
|
|
187 (member 'crypt-find-file-hook find-file-hooks)))
|
|
188 ;; Compression involved.
|
|
189 (if nosuffix
|
|
190 ":.gz:.Z"
|
|
191 ".elc:.elc.gz:elc.Z:.el:.el.gz:.el.Z::.gz:.Z"))
|
|
192 (t
|
|
193 ;; No compression.
|
|
194 (if nosuffix
|
|
195 ""
|
|
196 ".elc:.el:")))
|
|
197 4)))
|
|
198 (and interactive-call
|
|
199 (if result
|
|
200 (message "Library is file %s" result)
|
|
201 (message "No library %s in search path" library)))
|
|
202 result))
|
|
203
|
|
204 (defun packages-add-suffix (str)
|
|
205 (if (null (string-match "\\.el\\'" str))
|
|
206 (concat str ".elc")
|
|
207 str))
|
|
208
|
235
|
209 (defun packages-list-autoloads-path ()
|
209
|
210 "List autoloads from precomputed load-path."
|
|
211 (let ((path load-path)
|
|
212 autoloads)
|
|
213 (while path
|
|
214 (if (file-exists-p (concat (car path)
|
|
215 autoload-file-name))
|
|
216 (setq autoloads (cons (concat (car path)
|
|
217 autoload-file-name)
|
|
218 autoloads)))
|
|
219 (setq path (cdr path)))
|
|
220 autoloads))
|
|
221
|
235
|
222 (defun packages-list-autoloads ()
|
209
|
223 "List autoload files in (what will be) the normal lisp search path.
|
|
224 This function is used during build to find where the global symbol files so
|
|
225 they can be perused for their useful information."
|
|
226 ;; Source directory may not be initialized yet.
|
|
227 ;; (print (prin1-to-string load-path))
|
|
228 (if (null source-directory)
|
276
|
229 (setq source-directory (car load-path)))
|
235
|
230 (let ((files (directory-files (file-name-as-directory source-directory)
|
|
231 t ".*"))
|
209
|
232 file autolist)
|
215
|
233 ;; (print (prin1-to-string source-directory))
|
|
234 ;; (print (prin1-to-string files))
|
209
|
235 (while (setq file (car-safe files))
|
|
236 (if (and (file-directory-p file)
|
276
|
237 (file-exists-p (concat (file-name-as-directory file)
|
|
238 autoload-file-name)))
|
|
239 (setq autolist (cons (concat (file-name-as-directory file)
|
|
240 autoload-file-name)
|
209
|
241 autolist)))
|
|
242 (setq files (cdr files)))
|
|
243 autolist))
|
|
244
|
235
|
245 ;; The following function cannot be called from a bare temacs
|
|
246 (defun packages-new-autoloads ()
|
|
247 "Return autoloads files that have been added or modified since XEmacs dump."
|
|
248 (require 'loadhist)
|
|
249 (let ((me (concat invocation-directory invocation-name))
|
|
250 (path load-path)
|
|
251 result dir)
|
|
252 (while path
|
|
253 (setq dir (file-truename (car path)))
|
|
254 (let ((autoload-file (file-name-sans-extension (concat
|
|
255 dir
|
|
256 autoload-file-name))))
|
|
257 ;; Check for:
|
|
258 ;; 1. An auto-autoload file that hasn't provided a feature (because
|
|
259 ;; it has been installed since XEmacs was dumped).
|
|
260 ;; 2. auto-autoload.el being newer than the executable
|
|
261 ;; 3. auto-autoload.elc being newer than the executable (the .el
|
|
262 ;; could be missing or compressed)
|
|
263 (when (or (and (null (file-provides autoload-file))
|
|
264 (or (file-exists-p (concat autoload-file ".elc"))
|
|
265 (file-exists-p (concat autoload-file ".el"))))
|
|
266 (and (file-newer-than-file-p (concat autoload-file ".el") me)
|
|
267 (setq autoload-file (concat autoload-file ".el")))
|
|
268 (and (file-newer-than-file-p (concat autoload-file
|
|
269 ".elc")
|
|
270 me)
|
|
271 (setq autoload-file (concat autoload-file ".elc"))))
|
|
272 (push autoload-file result)))
|
|
273 (setq path (cdr path)))
|
|
274 result))
|
|
275
|
|
276 ;; The following function cannot be called from a bare temacs
|
|
277 (defun packages-reload-autoloads ()
|
|
278 "Reload new or updated auto-autoloads files.
|
|
279 This is an extremely dangerous function to call after the user-init-files
|
|
280 is run. Don't call it or you'll be sorry."
|
|
281 (let ((autoload-list (packages-new-autoloads)))
|
|
282 (while autoload-list
|
|
283 (let* ((autoload-file (car autoload-list))
|
|
284 (feature (car-safe (file-provides autoload-file))))
|
|
285 (when feature
|
|
286 ;; (message "(unload-feature %S)" feature)
|
|
287 (unload-feature feature))
|
237
|
288 (condition-case nil
|
|
289 (load autoload-file)
|
|
290 (t nil)))
|
235
|
291 (setq autoload-list (cdr autoload-list)))))
|
|
292
|
209
|
293 ;; Data-directory is really a list now. Provide something to search it for
|
|
294 ;; directories.
|
|
295
|
|
296 (defun locate-data-directory (name &optional dir-list)
|
|
297 "Locate a directory in a search path DIR-LIST (a list of directories).
|
|
298 If no DIR-LIST is supplied, it defaults to `data-directory-list'."
|
|
299 (unless dir-list
|
|
300 (setq dir-list data-directory-list))
|
|
301 (let (found found-dir)
|
|
302 (while (and (null found-dir) dir-list)
|
276
|
303 (setq found (file-name-as-directory (concat (car dir-list) name))
|
209
|
304 found-dir (file-directory-p found))
|
|
305 (or found-dir
|
|
306 (setq found nil))
|
|
307 (setq dir-list (cdr dir-list)))
|
|
308 found))
|
|
309
|
215
|
310 ;; Data-directory is really a list now. Provide something to search it for
|
|
311 ;; files.
|
|
312
|
|
313 (defun locate-data-file (name &optional dir-list)
|
|
314 "Locate a file in a search path DIR-LIST (a list of directories).
|
239
|
315 If no DIR-LIST is supplied, it defaults to `data-directory-list'.
|
|
316 This function is basically a wrapper over `locate-file'."
|
215
|
317 (unless dir-list
|
|
318 (setq dir-list data-directory-list))
|
239
|
319 (locate-file name dir-list))
|
215
|
320
|
267
|
321 ;; Path setup
|
|
322
|
274
|
323 (defun packages-find-package-directories (roots base)
|
|
324 "Find a set of package directories."
|
280
|
325 ;; make sure paths-find-version-directory and paths-find-site-directory
|
|
326 ;; don't both pick up version-independent directories ...
|
|
327 (let ((version-directory (paths-find-version-directory roots base nil nil t))
|
274
|
328 (site-directory (paths-find-site-directory roots base)))
|
|
329 (paths-uniq-append
|
|
330 (and version-directory (list version-directory))
|
|
331 (and site-directory (list site-directory)))))
|
267
|
332
|
286
|
333 (defvar packages-special-base-regexp "^\\(etc\\|info\\|lisp\\|lib-src\\|bin\\)$"
|
267
|
334 "Special subdirectories of packages.")
|
|
335
|
286
|
336 (defvar packages-no-package-hierarchy-regexp
|
|
337 (concat "\\(" paths-version-control-filename-regexp "\\)"
|
|
338 "\\|"
|
|
339 "\\(" packages-special-base-regexp "\\)")
|
|
340 "Directories which can't be the roots of package hierarchies.")
|
|
341
|
267
|
342 (defun packages-find-packages-in-directories (directories)
|
|
343 "Find all packages underneath directories in DIRECTORIES."
|
|
344 (paths-find-recursive-path directories
|
276
|
345 packages-hierarchy-depth
|
286
|
346 packages-no-package-hierarchy-regexp))
|
267
|
347
|
|
348 (defun packages-split-path (path)
|
276
|
349 "Split PATH at \"\", return pair with two components.
|
267
|
350 The second component is shared with PATH."
|
272
|
351 (let ((reverse-tail '())
|
|
352 (rest path))
|
276
|
353 (while (and rest (null (string-equal "" (car rest))))
|
272
|
354 (setq reverse-tail (cons (car rest) reverse-tail))
|
|
355 (setq rest (cdr rest)))
|
|
356 (if (null rest)
|
|
357 (cons path nil)
|
|
358 (cons (nreverse reverse-tail) (cdr rest)))))
|
267
|
359
|
274
|
360 (defun packages-split-package-path (package-path)
|
|
361 "Split up PACKAGE-PATH into early, late and last components.
|
276
|
362 The separation is by \"\" components.
|
272
|
363 This returns (LIST EARLY-PACKAGES LATE-PACKAGES LAST-PACKAGES)."
|
274
|
364 ;; When in doubt, it's late
|
|
365 (let* ((stuff (packages-split-path package-path))
|
|
366 (early (and (cdr stuff) (car stuff)))
|
|
367 (late+last (or (cdr stuff) (car stuff)))
|
|
368 (stuff (packages-split-path late+last))
|
|
369 (late (car stuff))
|
|
370 (last (cdr stuff)))
|
|
371 (list (packages-find-packages-in-directories early)
|
|
372 (packages-find-packages-in-directories late)
|
|
373 (packages-find-packages-in-directories last))))
|
|
374
|
|
375 (defun packages-deconstruct (list consumer)
|
|
376 "Deconstruct LIST and feed it to CONSUMER."
|
|
377 (apply consumer list))
|
|
378
|
|
379 (defun packages-find-packages-by-name (roots name)
|
|
380 "Find a package hierarchy by its name."
|
|
381 (packages-find-packages-in-directories
|
|
382 (if (and (file-name-absolute-p name)
|
|
383 (file-name-directory (expand-file-name name)))
|
|
384 (list (file-name-as-directory (expand-file-name name)))
|
|
385 (packages-find-package-directories roots name))))
|
|
386
|
|
387 (defun packages-find-packages-at-time
|
|
388 (roots package-locations time &optional default)
|
|
389 "Find packages at given time.
|
|
390 For the format of PACKAGE-LOCATIONS, see the global variable of the same name.
|
|
391 TIME is either 'EARLY, 'LATE, or 'LAST.
|
|
392 DEFAULT is a default list of packages."
|
276
|
393 (or default
|
|
394 (let ((packages '()))
|
|
395 (while package-locations
|
|
396 (packages-deconstruct
|
|
397 (car package-locations)
|
|
398 #'(lambda (name a-time thunk)
|
|
399 (if (and (eq time a-time)
|
|
400 (funcall thunk))
|
|
401 (setq packages
|
|
402 (nconc packages
|
|
403 (packages-find-packages-by-name roots name))))))
|
|
404 (setq package-locations (cdr package-locations)))
|
|
405 packages)))
|
274
|
406
|
276
|
407 (defun packages-find-packages (roots)
|
274
|
408 "Find the packages."
|
276
|
409 (let ((envvar-value (getenv "EMACSPACKAGEPATH")))
|
|
410 (if envvar-value
|
|
411 (packages-split-package-path (paths-decode-directory-path envvar-value))
|
|
412 (packages-deconstruct
|
|
413 (packages-split-package-path configure-package-path)
|
|
414 #'(lambda (configure-early-packages
|
|
415 configure-late-packages
|
|
416 configure-last-packages)
|
|
417 (list (packages-find-packages-at-time roots package-locations 'early
|
|
418 configure-early-packages)
|
|
419 (packages-find-packages-at-time roots package-locations 'late
|
|
420 configure-late-packages)
|
|
421 (packages-find-packages-at-time roots package-locations 'last
|
|
422 configure-last-packages)))))))
|
267
|
423
|
|
424 (defun packages-find-package-library-path (packages suffixes)
|
|
425 "Construct a path into a component of the packages hierarchy.
|
|
426 PACKAGES is a list of package directories.
|
|
427 SUFFIXES is a list of names of package subdirectories to look for."
|
|
428 (let ((directories
|
|
429 (apply
|
|
430 #'append
|
|
431 (mapcar #'(lambda (package)
|
|
432 (mapcar #'(lambda (suffix)
|
276
|
433 (file-name-as-directory (concat package suffix)))
|
267
|
434 suffixes))
|
|
435 packages))))
|
|
436 (paths-directories-which-exist directories)))
|
|
437
|
|
438 (defun packages-find-package-load-path (packages)
|
|
439 "Construct the load-path component for packages.
|
|
440 PACKAGES is a list of package directories."
|
|
441 (paths-find-recursive-load-path
|
276
|
442 (packages-find-package-library-path packages
|
|
443 '("lisp"))
|
|
444 packages-load-path-depth))
|
267
|
445
|
|
446 (defun packages-find-package-exec-path (packages)
|
|
447 (packages-find-package-library-path packages
|
276
|
448 (list (paths-construct-path
|
|
449 (list "bin" system-configuration))
|
|
450 "lib-src")))
|
267
|
451
|
|
452 (defun packages-find-package-info-path (packages)
|
276
|
453 (packages-find-package-library-path packages '("info")))
|
267
|
454
|
|
455 (defun packages-find-package-data-path (packages)
|
276
|
456 (packages-find-package-library-path packages '("etc")))
|
267
|
457
|
|
458 ;; Loading package initialization files
|
|
459
|
|
460 (defun packages-load-package-lisps (package-load-path base)
|
|
461 "Load all Lisp files of a certain name along a load path.
|
|
462 BASE is the base name of the files."
|
|
463 (mapc #'(lambda (dir)
|
|
464 (let ((file-name (expand-file-name base dir)))
|
276
|
465 (condition-case error
|
|
466 (load file-name t t)
|
|
467 (error
|
|
468 (warn (format "Autoload error in: %s:\n\t%s"
|
|
469 file-name
|
|
470 (with-output-to-string
|
|
471 (display-error error nil))))))))
|
267
|
472 package-load-path))
|
|
473
|
|
474 (defun packages-load-package-auto-autoloads (package-load-path)
|
|
475 "Load auto-autoload files along a load path."
|
|
476 (packages-load-package-lisps package-load-path
|
|
477 (file-name-sans-extension autoload-file-name)))
|
|
478
|
|
479 (defun packages-handle-package-dumped-lisps (handle package-load-path)
|
|
480 "Load dumped-lisp.el files along a load path.
|
|
481 Call HANDLE on each file off definitions of PACKAGE-LISP there."
|
|
482 (mapc #'(lambda (dir)
|
|
483 (let ((file-name (expand-file-name "dumped-lisp.el" dir)))
|
|
484 (if (file-exists-p file-name)
|
|
485 (let (package-lisp
|
|
486 ;; 20.4 packages could set this
|
|
487 preloaded-file-list)
|
|
488 (load file-name)
|
|
489 ;; dumped-lisp.el could have set this ...
|
|
490 (if package-lisp
|
|
491 (mapc #'(lambda (base)
|
272
|
492 (funcall handle base))
|
267
|
493 package-lisp))))))
|
276
|
494 package-load-path))
|
267
|
495
|
|
496 (defun packages-load-package-dumped-lisps (package-load-path)
|
|
497 "Load dumped-lisp.el files along a load path.
|
|
498 Also load files off PACKAGE-LISP definitions there"
|
|
499 (packages-handle-package-dumped-lisps #'load package-load-path))
|
|
500
|
|
501 (defun packages-collect-package-dumped-lisps (package-load-path)
|
|
502 "Load dumped-lisp.el files along a load path.
|
|
503 Return list of files off PACKAGE-LISP definitions there"
|
|
504 (let ((*files* '()))
|
|
505 (packages-handle-package-dumped-lisps
|
|
506 #'(lambda (file)
|
272
|
507 (setq *files* (cons file *files*)))
|
267
|
508 package-load-path)
|
|
509 (reverse *files*)))
|
209
|
510
|
|
511 (provide 'packages)
|
|
512
|
|
513 ;;; packages.el ends here
|