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