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