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 '(
|
253
|
98 #+infodock "id-vers"
|
|
99 #+infodock "easymenu-id-xemacs"
|
209
|
100 )
|
|
101 "Lisp packages that are always dumped with XEmacs")
|
|
102
|
|
103 (defvar packages-useful-lisp
|
|
104 '("bytecomp"
|
|
105 "byte-optimize"
|
|
106 "shadow"
|
|
107 "cl-macs")
|
|
108 "Lisp packages that need early byte compilation.")
|
|
109
|
|
110 (defvar packages-unbytecompiled-lisp
|
|
111 '("paths.el"
|
227
|
112 "dumped-lisp.el"
|
|
113 "dumped-pkg-lisp.el"
|
209
|
114 "version.el")
|
|
115 "Lisp packages that should not be byte compiled.")
|
|
116
|
|
117
|
|
118 ;; Copied from help.el, could possibly move it to here permanently.
|
|
119 ;; Unlike the FSF version, our `locate-library' uses the `locate-file'
|
|
120 ;; primitive, which should make it lightning-fast.
|
|
121
|
|
122 (defun locate-library (library &optional nosuffix path interactive-call)
|
|
123 "Show the precise file name of Emacs library LIBRARY.
|
|
124 This command searches the directories in `load-path' like `M-x load-library'
|
|
125 to find the file that `M-x load-library RET LIBRARY RET' would load.
|
|
126 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
|
|
127 to the specified name LIBRARY.
|
|
128
|
|
129 If the optional third arg PATH is specified, that list of directories
|
|
130 is used instead of `load-path'."
|
|
131 (interactive (list (read-string "Locate library: ")
|
|
132 nil nil
|
|
133 t))
|
|
134 (let ((result
|
|
135 (locate-file
|
|
136 library
|
|
137 (or path load-path)
|
|
138 (cond ((or (rassq 'jka-compr-handler file-name-handler-alist)
|
|
139 (and (boundp 'find-file-hooks)
|
|
140 (member 'crypt-find-file-hook find-file-hooks)))
|
|
141 ;; Compression involved.
|
|
142 (if nosuffix
|
|
143 ":.gz:.Z"
|
|
144 ".elc:.elc.gz:elc.Z:.el:.el.gz:.el.Z::.gz:.Z"))
|
|
145 (t
|
|
146 ;; No compression.
|
|
147 (if nosuffix
|
|
148 ""
|
|
149 ".elc:.el:")))
|
|
150 4)))
|
|
151 (and interactive-call
|
|
152 (if result
|
|
153 (message "Library is file %s" result)
|
|
154 (message "No library %s in search path" library)))
|
|
155 result))
|
|
156
|
|
157 (defun packages-add-suffix (str)
|
|
158 (if (null (string-match "\\.el\\'" str))
|
|
159 (concat str ".elc")
|
|
160 str))
|
|
161
|
235
|
162 (defun packages-list-autoloads-path ()
|
209
|
163 "List autoloads from precomputed load-path."
|
|
164 (let ((path load-path)
|
|
165 autoloads)
|
|
166 (while path
|
|
167 (if (file-exists-p (concat (car path)
|
|
168 autoload-file-name))
|
|
169 (setq autoloads (cons (concat (car path)
|
|
170 autoload-file-name)
|
|
171 autoloads)))
|
|
172 (setq path (cdr path)))
|
|
173 autoloads))
|
|
174
|
235
|
175 (defun packages-list-autoloads ()
|
209
|
176 "List autoload files in (what will be) the normal lisp search path.
|
|
177 This function is used during build to find where the global symbol files so
|
|
178 they can be perused for their useful information."
|
|
179 ;; Source directory may not be initialized yet.
|
|
180 ;; (print (prin1-to-string load-path))
|
|
181 (if (null source-directory)
|
215
|
182 (setq source-directory (concat (car load-path) "./")))
|
235
|
183 (let ((files (directory-files (file-name-as-directory source-directory)
|
|
184 t ".*"))
|
209
|
185 file autolist)
|
215
|
186 ;; (print (prin1-to-string source-directory))
|
|
187 ;; (print (prin1-to-string files))
|
209
|
188 (while (setq file (car-safe files))
|
|
189 (if (and (file-directory-p file)
|
|
190 (file-exists-p (concat file "/" autoload-file-name)))
|
|
191 (setq autolist (cons (concat file "/" autoload-file-name)
|
|
192 autolist)))
|
|
193 (setq files (cdr files)))
|
|
194 autolist))
|
|
195
|
235
|
196 ;; The following function cannot be called from a bare temacs
|
|
197 (defun packages-new-autoloads ()
|
|
198 "Return autoloads files that have been added or modified since XEmacs dump."
|
|
199 (require 'loadhist)
|
|
200 (let ((me (concat invocation-directory invocation-name))
|
|
201 (path load-path)
|
|
202 result dir)
|
|
203 (while path
|
|
204 (setq dir (file-truename (car path)))
|
|
205 (let ((autoload-file (file-name-sans-extension (concat
|
|
206 dir
|
|
207 autoload-file-name))))
|
|
208 ;; Check for:
|
|
209 ;; 1. An auto-autoload file that hasn't provided a feature (because
|
|
210 ;; it has been installed since XEmacs was dumped).
|
|
211 ;; 2. auto-autoload.el being newer than the executable
|
|
212 ;; 3. auto-autoload.elc being newer than the executable (the .el
|
|
213 ;; could be missing or compressed)
|
|
214 (when (or (and (null (file-provides autoload-file))
|
|
215 (or (file-exists-p (concat autoload-file ".elc"))
|
|
216 (file-exists-p (concat autoload-file ".el"))))
|
|
217 (and (file-newer-than-file-p (concat autoload-file ".el") me)
|
|
218 (setq autoload-file (concat autoload-file ".el")))
|
|
219 (and (file-newer-than-file-p (concat autoload-file
|
|
220 ".elc")
|
|
221 me)
|
|
222 (setq autoload-file (concat autoload-file ".elc"))))
|
|
223 (push autoload-file result)))
|
|
224 (setq path (cdr path)))
|
|
225 result))
|
|
226
|
|
227 ;; The following function cannot be called from a bare temacs
|
|
228 (defun packages-reload-autoloads ()
|
|
229 "Reload new or updated auto-autoloads files.
|
|
230 This is an extremely dangerous function to call after the user-init-files
|
|
231 is run. Don't call it or you'll be sorry."
|
|
232 (let ((autoload-list (packages-new-autoloads)))
|
|
233 (while autoload-list
|
|
234 (let* ((autoload-file (car autoload-list))
|
|
235 (feature (car-safe (file-provides autoload-file))))
|
|
236 (when feature
|
|
237 ;; (message "(unload-feature %S)" feature)
|
|
238 (unload-feature feature))
|
237
|
239 (condition-case nil
|
|
240 (load autoload-file)
|
|
241 (t nil)))
|
235
|
242 (setq autoload-list (cdr autoload-list)))))
|
|
243
|
|
244 ;; The following function cannot be called from a bare temacs
|
|
245 (defun packages-reload-dumped-lisp ()
|
|
246 "Reload new or updated dumped lisp files (with exceptions).
|
|
247 This is an extremely dangerous function to call at any time."
|
|
248 ;; Nothing for the moment
|
|
249 nil)
|
|
250
|
209
|
251 ;; The following function is called from temacs
|
215
|
252 (defun packages-find-packages-1 (package path-only append-p user-package)
|
209
|
253 "Search the supplied directory for associated directories.
|
|
254 The top level is assumed to look like:
|
|
255 info/ Contain texinfo files for lisp installed in this hierarchy
|
243
|
256 etc/ Contain data files for lisp installled in this hierarchy
|
209
|
257 lisp/ Contain directories which either have straight lisp code
|
|
258 or are self-contained packages of their own.
|
|
259
|
215
|
260 If the argument `append-p' is non-nil, the found directories will be
|
|
261 appended to the paths, otherwise, they will be prepended.
|
|
262
|
209
|
263 This is an internal function. Do not call it after startup."
|
|
264 ;; Info files
|
|
265 (if (and (null path-only) (file-directory-p (concat package "/info")))
|
|
266 (let ((dir (concat package "/info/")))
|
|
267 (if (not (member dir Info-default-directory-list))
|
|
268 (nconc Info-default-directory-list (list dir)))))
|
|
269 ;; Data files
|
|
270 (if (and (null path-only) (file-directory-p (concat package "/etc")))
|
|
271 (setq data-directory-list
|
215
|
272 (if append-p
|
|
273 (append data-directory-list (list (concat package "/etc/")))
|
|
274 (cons (concat package "/etc/") data-directory-list))))
|
209
|
275 ;; Lisp files
|
|
276 (if (file-directory-p (concat package "/lisp"))
|
|
277 (progn
|
|
278 ; (print (concat "DIR: "
|
|
279 ; (if user-package "[USER]" "")
|
|
280 ; package
|
|
281 ; "/lisp/"))
|
215
|
282 (setq load-path
|
|
283 (if append-p
|
|
284 (append load-path (list (concat package "/lisp/")))
|
|
285 (cons (concat package "/lisp/") load-path)))
|
227
|
286
|
|
287 ;; Locate and process a dumped-lisp.el file if it exists
|
|
288 (if (and (running-temacs-p)
|
|
289 (file-exists-p (concat package "/lisp/dumped-lisp.el")))
|
|
290 (let (package-lisp)
|
243
|
291 (let (preloaded-file-list)
|
|
292 (load (concat package "/lisp/dumped-lisp.el")))
|
227
|
293 (if package-lisp
|
|
294 (progn
|
|
295 (if (boundp 'preloaded-file-list)
|
|
296 (setq preloaded-file-list
|
|
297 (append preloaded-file-list package-lisp)))
|
|
298 (if (fboundp 'load-gc)
|
|
299 (setq dumped-lisp-packages
|
|
300 (append dumped-lisp-packages package-lisp)))))))
|
|
301
|
209
|
302 (if user-package
|
233
|
303 (condition-case error
|
209
|
304 (load (concat package "/lisp/"
|
233
|
305 (file-name-sans-extension autoload-file-name))
|
|
306 t)
|
|
307 (error
|
|
308 (warn (format "Autoload error in: %s/lisp/:\n\t%s"
|
|
309 package
|
|
310 (with-output-to-string
|
|
311 (display-error error nil)))))))
|
209
|
312 (let ((dirs (directory-files (concat package "/lisp/")
|
|
313 t "^[^-.]" nil 'dirs-only))
|
|
314 dir)
|
|
315 (while dirs
|
|
316 (setq dir (car dirs))
|
|
317 ; (print (concat "DIR: " dir "/"))
|
215
|
318 (setq load-path
|
|
319 (if append-p
|
|
320 (append load-path (list (concat dir "/")))
|
|
321 (cons (concat dir "/") load-path)))
|
227
|
322
|
|
323 ;; Locate and process a dumped-lisp.el file if it exists
|
|
324 (if (and (running-temacs-p)
|
|
325 (file-exists-p (concat dir "/dumped-lisp.el")))
|
|
326 (let (package-lisp)
|
247
|
327 (let (preloaded-file-list)
|
|
328 (load (concat dir "/dumped-lisp.el")))
|
227
|
329 (if package-lisp
|
|
330 (progn
|
|
331 (if (boundp 'preloaded-file-list)
|
|
332 (setq preloaded-file-list
|
|
333 (append preloaded-file-list package-lisp)))
|
|
334 (if (fboundp 'load-gc)
|
|
335 (setq dumped-lisp-packages
|
235
|
336 (append dumped-lisp-packages
|
|
337 package-lisp)))))))
|
227
|
338
|
209
|
339 (if user-package
|
233
|
340 (condition-case error
|
209
|
341 (progn
|
|
342 ; (print
|
|
343 ; (concat dir "/"
|
|
344 ; (file-name-sans-extension autoload-file-name)))
|
|
345 (load
|
|
346 (concat dir "/"
|
233
|
347 (file-name-sans-extension autoload-file-name))
|
|
348 t))
|
|
349 (error
|
|
350 (warn (format "Autoload error in: %s/:\n\t%s"
|
|
351 dir
|
|
352 (with-output-to-string
|
|
353 (display-error error nil)))))))
|
215
|
354 (packages-find-packages-1 dir path-only append-p user-package)
|
209
|
355 (setq dirs (cdr dirs)))))))
|
|
356
|
|
357 ;; The following function is called from temacs
|
215
|
358 (defun packages-find-packages-2 (path path-only append-p suppress-user)
|
|
359 "Search the supplied path for associated directories.
|
|
360 If the argument `append-p' is non-nil, the found directories will be
|
|
361 appended to the paths, otherwise, they will be prepended.
|
|
362
|
|
363 This is an internal function. Do not call it after startup."
|
|
364 (let (dir)
|
|
365 (while path
|
|
366 (setq dir (car path))
|
|
367 ;; (prin1 (concat "Find: " (expand-file-name dir) "\n"))
|
|
368 (if (null (and (or suppress-user inhibit-package-init)
|
|
369 (string-match "^~" dir)))
|
|
370 (progn
|
|
371 ;; (print dir)
|
|
372 (packages-find-packages-1 (expand-file-name dir)
|
|
373 path-only
|
|
374 append-p
|
|
375 (string-match "^~" dir))))
|
|
376 (setq path (cdr path)))))
|
|
377
|
|
378 ;; The following function is called from temacs
|
209
|
379 (defun packages-find-packages (pkg-path path-only &optional suppress-user)
|
|
380 "Search the supplied path for additional info/etc/lisp directories.
|
|
381 Lisp directories if configured prior to build time will have equivalent
|
|
382 status as bundled packages.
|
|
383 If the argument `path-only' is non-nil, only the `load-path' will be set,
|
|
384 otherwise data directories and info directories will be added.
|
|
385 If the optional argument `suppress-user' is non-nil, package directories
|
|
386 rooted in a user login directory (like ~/.xemacs) will not be searched.
|
|
387 This is used at dump time to suppress the builder's local environment."
|
215
|
388 (let ((prefix-path nil))
|
|
389 (while (and pkg-path (car pkg-path))
|
|
390 (setq prefix-path (cons (car pkg-path) prefix-path)
|
|
391 pkg-path (cdr pkg-path)))
|
|
392 (packages-find-packages-2 (cdr pkg-path) path-only t suppress-user)
|
|
393 (packages-find-packages-2 prefix-path path-only nil suppress-user)))
|
|
394
|
209
|
395
|
|
396 ;; Data-directory is really a list now. Provide something to search it for
|
|
397 ;; directories.
|
|
398
|
|
399 (defun locate-data-directory (name &optional dir-list)
|
|
400 "Locate a directory in a search path DIR-LIST (a list of directories).
|
|
401 If no DIR-LIST is supplied, it defaults to `data-directory-list'."
|
|
402 (unless dir-list
|
|
403 (setq dir-list data-directory-list))
|
|
404 (let (found found-dir)
|
|
405 (while (and (null found-dir) dir-list)
|
|
406 (setq found (concat (car dir-list) name "/")
|
|
407 found-dir (file-directory-p found))
|
|
408 (or found-dir
|
|
409 (setq found nil))
|
|
410 (setq dir-list (cdr dir-list)))
|
|
411 found))
|
|
412
|
215
|
413 ;; Data-directory is really a list now. Provide something to search it for
|
|
414 ;; files.
|
|
415
|
|
416 (defun locate-data-file (name &optional dir-list)
|
|
417 "Locate a file in a search path DIR-LIST (a list of directories).
|
239
|
418 If no DIR-LIST is supplied, it defaults to `data-directory-list'.
|
|
419 This function is basically a wrapper over `locate-file'."
|
215
|
420 (unless dir-list
|
|
421 (setq dir-list data-directory-list))
|
239
|
422 (locate-file name dir-list))
|
215
|
423
|
209
|
424 ;; If we are being loaded as part of being dumped, bootstrap the rest of the
|
|
425 ;; load-path for loaddefs.
|
|
426 (if (fboundp 'load-gc)
|
|
427 (packages-find-packages package-path t t))
|
|
428
|
|
429 (provide 'packages)
|
|
430
|
|
431 ;;; packages.el ends here
|