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