Mercurial > hg > xemacs-beta
annotate lisp/packages.el @ 5157:1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
-------------------- ChangeLog entries follow: --------------------
lisp/ChangeLog addition:
2010-03-18 Ben Wing <ben@xemacs.org>
* diagnose.el (show-memory-usage):
Rewrite to take into account API changes in memory-usage functions.
src/ChangeLog addition:
2010-03-18 Ben Wing <ben@xemacs.org>
* alloc.c:
* alloc.c (disksave_object_finalization_1):
* alloc.c (lisp_object_storage_size):
* alloc.c (listu):
* alloc.c (listn):
* alloc.c (Fobject_memory_usage_stats):
* alloc.c (compute_memusage_stats_length):
* alloc.c (Fobject_memory_usage):
* alloc.c (Ftotal_object_memory_usage):
* alloc.c (malloced_storage_size):
* alloc.c (common_init_alloc_early):
* alloc.c (reinit_alloc_objects_early):
* alloc.c (reinit_alloc_early):
* alloc.c (init_alloc_once_early):
* alloc.c (syms_of_alloc):
* alloc.c (reinit_vars_of_alloc):
* buffer.c:
* buffer.c (struct buffer_stats):
* buffer.c (compute_buffer_text_usage):
* buffer.c (compute_buffer_usage):
* buffer.c (buffer_memory_usage):
* buffer.c (buffer_objects_create):
* buffer.c (syms_of_buffer):
* buffer.c (vars_of_buffer):
* console-impl.h (struct console_methods):
* dynarr.c (Dynarr_memory_usage):
* emacs.c (main_1):
* events.c (clear_event_resource):
* extents.c:
* extents.c (compute_buffer_extent_usage):
* extents.c (extent_objects_create):
* extents.h:
* faces.c:
* faces.c (compute_face_cachel_usage):
* faces.c (face_objects_create):
* faces.h:
* general-slots.h:
* glyphs.c:
* glyphs.c (compute_glyph_cachel_usage):
* glyphs.c (glyph_objects_create):
* glyphs.h:
* lisp.h:
* lisp.h (struct usage_stats):
* lrecord.h:
* lrecord.h (enum lrecord_type):
* lrecord.h (struct lrecord_implementation):
* lrecord.h (MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE):
* lrecord.h (DEFINE_DUMPABLE_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_SIZABLE_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_FROB_BLOCK_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_FROB_BLOCK_SIZABLE_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_SIZABLE_INTERNAL_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_SIZABLE_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_FROB_BLOCK_SIZABLE_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_INTERNAL_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_SIZABLE_INTERNAL_LISP_OBJECT):
* lrecord.h (MAKE_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_MODULE_LISP_OBJECT):
* lrecord.h (DEFINE_DUMPABLE_MODULE_SIZABLE_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_MODULE_LISP_OBJECT):
* lrecord.h (DEFINE_NODUMP_MODULE_SIZABLE_LISP_OBJECT):
* lrecord.h (MAKE_MODULE_LISP_OBJECT):
* lrecord.h (INIT_LISP_OBJECT):
* lrecord.h (INIT_MODULE_LISP_OBJECT):
* lrecord.h (UNDEF_LISP_OBJECT):
* lrecord.h (UNDEF_MODULE_LISP_OBJECT):
* lrecord.h (DECLARE_LISP_OBJECT):
* lrecord.h (DECLARE_MODULE_API_LISP_OBJECT):
* lrecord.h (DECLARE_MODULE_LISP_OBJECT):
* lstream.c:
* lstream.c (syms_of_lstream):
* lstream.c (vars_of_lstream):
* marker.c:
* marker.c (compute_buffer_marker_usage):
* mc-alloc.c (mc_alloced_storage_size):
* mc-alloc.h:
* mule-charset.c:
* mule-charset.c (struct charset_stats):
* mule-charset.c (compute_charset_usage):
* mule-charset.c (charset_memory_usage):
* mule-charset.c (mule_charset_objects_create):
* mule-charset.c (syms_of_mule_charset):
* mule-charset.c (vars_of_mule_charset):
* redisplay.c:
* redisplay.c (compute_rune_dynarr_usage):
* redisplay.c (compute_display_block_dynarr_usage):
* redisplay.c (compute_glyph_block_dynarr_usage):
* redisplay.c (compute_display_line_dynarr_usage):
* redisplay.c (compute_line_start_cache_dynarr_usage):
* redisplay.h:
* scrollbar-gtk.c (gtk_compute_scrollbar_instance_usage):
* scrollbar-msw.c (mswindows_compute_scrollbar_instance_usage):
* scrollbar-x.c (x_compute_scrollbar_instance_usage):
* scrollbar.c (compute_scrollbar_instance_usage):
* scrollbar.h:
* symbols.c:
* symbols.c (reinit_symbol_objects_early):
* symbols.c (init_symbols_once_early):
* symbols.c (reinit_symbols_early):
* symbols.c (defsymbol_massage_name_1):
* symsinit.h:
* ui-gtk.c:
* ui-gtk.c (emacs_gtk_object_getprop):
* ui-gtk.c (emacs_gtk_object_putprop):
* ui-gtk.c (ui_gtk_objects_create):
* unicode.c (compute_from_unicode_table_size_1):
* unicode.c (compute_to_unicode_table_size_1):
* unicode.c (compute_from_unicode_table_size):
* unicode.c (compute_to_unicode_table_size):
* window.c:
* window.c (struct window_stats):
* window.c (compute_window_mirror_usage):
* window.c (compute_window_usage):
* window.c (window_memory_usage):
* window.c (window_objects_create):
* window.c (syms_of_window):
* window.c (vars_of_window):
* window.h:
Redo memory-usage mechanism, make it general; add way of dynamically
initializing Lisp object types -- OBJECT_HAS_METHOD(), similar to
CONSOLE_HAS_METHOD().
(1) Create OBJECT_HAS_METHOD(), OBJECT_HAS_PROPERTY() etc. for
specifying that a Lisp object type has a particular method or
property. Call such methods with OBJECT_METH, MAYBE_OBJECT_METH,
OBJECT_METH_OR_GIVEN; retrieve properties with OBJECT_PROPERTY.
Methods that formerly required a DEFINE_*GENERAL_LISP_OBJECT() to
specify them (getprop, putprop, remprop, plist, disksave) now
instead use the dynamic-method mechanism. The main benefit of
this is that new methods or properties can be added without
requiring that the declaration statements of all existing methods
be modified. We have to make the `struct lrecord_implementation'
non-const, but I don't think this should have any effect on speed --
the only possible method that's really speed-critical is the
mark method, and we already extract those out into a separate
(non-const) array for increased cache locality.
Object methods need to be reinitialized after pdump, so we put
them in separate functions such as face_objects_create(),
extent_objects_create() and call them appropriately from emacs.c
The only current object property (`memusage_stats_list') that
objects can specify is a Lisp object and gets staticpro()ed so it
only needs to be set during dump time, but because it references
symbols that might not exist in a syms_of_() function, we
initialize it in vars_of_(). There is also an object property
(`num_extra_memusage_stats') that is automatically initialized based
on `memusage_stats_list'; we do that in reinit_vars_of_alloc(),
which is called after all vars_of_() functions are called.
`disksaver' method was renamed `disksave' to correspond with the
name normally given to the function (e.g. disksave_lstream()).
(2) Generalize the memory-usage mechanism in `buffer-memory-usage',
`window-memory-usage', `charset-memory-usage' into an object-type-
specific mechanism called by a single function
`object-memory-usage'. (Former function `object-memory-usage'
renamed to `total-object-memory-usage'). Generalize the mechanism
of different "slices" so that we can have different "classes" of
memory described and different "slices" onto each class; `t'
separates classes, `nil' separates slices. Currently we have
three classes defined: the memory of an object itself,
non-Lisp-object memory associated with the object (e.g. arrays or
dynarrs stored as fields in the object), and Lisp-object memory
associated with the object (other internal Lisp objects stored in
the object). This isn't completely finished yet and we might need
to further separate the "other internal Lisp objects" class into
two classes.
The memory-usage mechanism uses a `struct usage_stats' (renamed
from `struct overhead_stats') to describe a malloc-view onto a set
of allocated memory (listing how much was requested and various
types of overhead) and a more general `struct generic_usage_stats'
(with a `struct usage_stats' in it) to hold all statistics about
object memory. `struct generic_usage_stats' contains an array of
32 Bytecounts, which are statistics of unspecified semantics. The
intention is that individual types declare a corresponding struct
(e.g. `struct window_stats') with the same structure but with
specific fields in place of the array, corresponding to specific
statistics. The number of such statistics is an object property
computed from the list of tags (Lisp symbols describing the
statistics) stored in `memusage_stats_list'. The idea here is to
allow particular object types to customize the number and
semantics of the statistics where completely avoiding consing.
This doesn't matter so much yet, but the intention is to have the
memory usage of all objects computed at the end of GC, at the same
time as other statistics are currently computed. The values for
all statistics for a single type would be added up to compute
aggregate values for all objects of a specific type. To make this
efficient, we can't allow any memory allocation at all.
(3) Create some additional functions for creating lists that
specify the elements directly as args rather than indirectly through
an array: listn() (number of args given), listu() (list terminated
by Qunbound).
(4) Delete a bit of remaining unused C window_config stuff, also
unused lrecord_type_popup_data.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Thu, 18 Mar 2010 10:50:06 -0500 |
parents | 6b6b0f8ab749 |
children | 5efbd1253905 |
rev | line source |
---|---|
428 | 1 ;;; packages.el --- Low level support for XEmacs packages |
2 | |
3 ;; Copyright (C) 1997 Free Software Foundation, Inc. | |
2557 | 4 ;; Copyright (C) 2002, 2003, 2004 Ben Wing. |
428 | 5 |
6 ;; Author: Steven L Baur <steve@xemacs.org> | |
7 ;; Maintainer: Steven L Baur <steve@xemacs.org> | |
8 ;; Keywords: internal, lisp, dumped | |
9 | |
10 ;; This file is part of XEmacs. | |
11 | |
12 ;; XEmacs is free software; you can redistribute it and/or modify it | |
13 ;; under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; XEmacs is distributed in the hope that it will be useful, but | |
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 ;; General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
25 ;; 02111-1307, USA. | |
26 | |
27 ;;; Synched up with: Not in FSF | |
28 | |
29 ;;; Commentary: | |
30 | |
31 ;; This file is dumped with XEmacs. | |
32 | |
33 ;; This file provides low level facilities for XEmacs startup -- | |
34 ;; particularly regarding the package setup. This code has to run in | |
35 ;; what we call "bare temacs" -- i.e. XEmacs without the usual Lisp | |
36 ;; environment. Pay special attention: | |
37 | |
38 ;; - not to use the `lambda' macro. Use #'(lambda ...) instead. | |
39 ;; (this goes for any package loaded before `subr.el'.) | |
40 ;; | |
41 ;; - not to use macros, because they are not yet available (and this | |
442 | 42 ;; file must be loadable uncompiled.) Built in macros, such as |
43 ;; `when' and `unless' are fine, of course. | |
428 | 44 ;; |
45 ;; - not to use `defcustom'. If you must add user-customizable | |
46 ;; variables here, use `defvar', and add the variable to | |
47 ;; `cus-start.el'. | |
48 | |
49 ;; Because of all this, make sure that the stuff you put here really | |
50 ;; belongs here. | |
51 | |
52 ;; This file requires find-paths.el. | |
53 | |
54 ;;; Code: | |
55 | |
56 ;;; Package versioning | |
57 | |
58 (defvar packages-package-list nil | |
454 | 59 "Database of installed packages and version numbers") |
428 | 60 |
2456 | 61 ;;; Directories and paths |
62 | |
63 ;;; Terminology: | |
64 | |
65 ;;; A *package hierarchy* is a directory that contains a collection of | |
66 ;;; packages; it has lisp/, info/, etc/ etc. subdirectories that | |
67 ;;; contain the files constituting the packages. | |
68 | |
69 ;;; A *package directory* contains package hierarchies---the package | |
70 ;;; hierarchies are typically in directories "xemacs-packages", | |
71 ;;; "mule-packages", and so on. A package hierarchy might only be | |
72 ;;; applicable for specific variants of XEmacs. | |
73 | |
74 ;;; Package hierarchies come in "early", "late", and "last" variants, | |
75 ;;; depending on their relative location in the various paths. | |
76 ;;; "Early" hierarchies are typically in the user's home directory, | |
77 ;;; "late" hierarchies are typically part of the XEmacs installation, | |
78 ;;; and "last" package hierarchies are for special purposes, such as | |
79 ;;; making the packages of some previous XEmacs version available. | |
428 | 80 |
81 (defvar packages-load-path-depth 1 | |
82 "Depth of load-path search in package hierarchies.") | |
83 | |
84 (defvar packages-data-path-depth 1 | |
85 "Depth of data-path search in package hierarchies.") | |
86 | |
2456 | 87 (defvar early-package-hierarchies nil |
88 "Package hierarchies early in the load path.") | |
428 | 89 |
90 (defvar early-package-load-path nil | |
91 "Load path for packages early in the load path.") | |
92 | |
2456 | 93 (defvar late-package-hierarchies nil |
94 "Package hierarchies late in the load path.") | |
428 | 95 |
96 (defvar late-package-load-path nil | |
97 "Load path for packages late in the load path.") | |
98 | |
2456 | 99 (defvar last-package-hierarchies nil |
100 "Package hierarchies last in the load path.") | |
428 | 101 |
102 (defvar last-package-load-path nil | |
103 "Load path for packages last in the load path.") | |
104 | |
2456 | 105 (defun packages-package-hierarchy-directory-names () |
106 "Returns a list package hierarchy directory names. | |
107 These are the valid immediate directory names of package | |
108 directories, directories with higher priority first" | |
4919
9c6ea1581159
Remove a couple of XEmacs-specific duplicate functions, find-paths.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4108
diff
changeset
|
109 (delq nil `("site-packages" |
9c6ea1581159
Remove a couple of XEmacs-specific duplicate functions, find-paths.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4108
diff
changeset
|
110 ,(when (featurep 'infodock) "infodock-packages") |
9c6ea1581159
Remove a couple of XEmacs-specific duplicate functions, find-paths.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4108
diff
changeset
|
111 ,(when (featurep 'mule) "mule-packages") |
9c6ea1581159
Remove a couple of XEmacs-specific duplicate functions, find-paths.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4108
diff
changeset
|
112 "xemacs-packages"))) |
428 | 113 |
114 (defun package-get-key-1 (info key) | |
115 "Locate keyword `key' in list." | |
116 (cond ((null info) | |
117 nil) | |
118 ((eq (car info) key) | |
119 (nth 1 info)) | |
120 (t (package-get-key-1 (cddr info) key)))) | |
121 | |
122 (defun package-get-key (name key) | |
123 "Get info `key' from package `name'." | |
124 (let ((info (assq name packages-package-list))) | |
125 (when info | |
126 (package-get-key-1 (cdr info) key)))) | |
127 | |
128 (defun package-provide (name &rest attributes) | |
129 (let ((info (if (and attributes (floatp (car attributes))) | |
130 (list :version (car attributes)) | |
131 attributes))) | |
132 (setq packages-package-list | |
133 (cons (cons name info) (remassq name packages-package-list))))) | |
134 | |
2557 | 135 (defun package-suppress (package file form) |
136 "Set up a package-suppress condition FORM for FILE in PACKAGE. | |
137 When XEmacs searches for a file in the load path, it will ignore FILE | |
138 if FORM evaluates to non-nil." | |
139 (setq load-suppress-alist | |
140 (acons (expand-file-name file load-file-name) form | |
141 load-suppress-alist))) | |
142 | |
428 | 143 (defun package-require (name version) |
144 (let ((pkg (assq name packages-package-list))) | |
145 (cond ((null pkg) | |
1410 | 146 (error 'invalid-state |
147 (format "Package %s has not been loaded into this XEmacsen" | |
148 name))) | |
428 | 149 ((< (package-get-key name :version) version) |
1410 | 150 (error 'search-failed |
151 (format "Need version %g of package %s, got version %g" | |
2252 | 152 version name (package-get-key name :version)))) |
428 | 153 (t t)))) |
154 | |
155 (defun package-delete-name (name) | |
156 (let (pkg) | |
157 ;; Delete ALL versions of package. | |
158 ;; This is pretty memory-intensive, as we use copy-alist when deleting | |
159 ;; package entries, to prevent side-effects in functions that call this | |
160 ;; one. | |
161 (while (setq pkg (assq name packages-package-list)) | |
162 (setq packages-package-list (delete pkg (copy-alist | |
1365 | 163 packages-package-list)))))) |
428 | 164 |
165 ;;; Build time stuff | |
166 | |
167 (defvar autoload-file-name "auto-autoloads.el" | |
168 "Filename that autoloads are expected to be found in.") | |
169 | |
1330 | 170 ;; Moved from help.el. |
428 | 171 ;; Unlike the FSF version, our `locate-library' uses the `locate-file' |
172 ;; primitive, which should make it lightning-fast. | |
173 | |
174 (defun locate-library (library &optional nosuffix path interactive-call) | |
175 "Show the precise file name of Emacs library LIBRARY. | |
176 This command searches the directories in `load-path' like `M-x load-library' | |
177 to find the file that `M-x load-library RET LIBRARY RET' would load. | |
178 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el' | |
179 to the specified name LIBRARY. | |
180 | |
181 If the optional third arg PATH is specified, that list of directories | |
182 is used instead of `load-path'." | |
624 | 183 (interactive (list (read-library-name "Locate library: ") |
428 | 184 nil nil |
185 t)) | |
186 (let ((result | |
187 (locate-file | |
188 library | |
189 (or path load-path) | |
190 (cond ((or (rassq 'jka-compr-handler file-name-handler-alist) | |
191 (and (boundp 'find-file-hooks) | |
192 (member 'crypt-find-file-hook find-file-hooks))) | |
193 ;; Compression involved. | |
194 (if nosuffix | |
448 | 195 '("" ".gz" ".Z" ".bz2") |
196 '(".elc" ".elc.gz" "elc.Z" ".elc.bz2" | |
197 ".el" ".el.gz" ".el.Z" ".el.bz2" | |
198 "" ".gz" ".Z" ".bz2"))) | |
428 | 199 (t |
200 ;; No compression. | |
201 (if nosuffix | |
202 "" | |
203 '(".elc" ".el" ""))))))) | |
204 (and interactive-call | |
205 (if result | |
206 (message "Library is file %s" result) | |
207 (message "No library %s in search path" library))) | |
208 result)) | |
209 | |
210 (defun packages-add-suffix (str) | |
211 (if (null (string-match "\\.el\\'" str)) | |
212 (concat str ".elc") | |
213 str)) | |
214 | |
215 (defun packages-list-autoloads-path () | |
216 "List autoloads from precomputed load-path." | |
217 (let ((path load-path) | |
218 autoloads) | |
219 (while path | |
220 (if (file-exists-p (concat (car path) | |
221 autoload-file-name)) | |
222 (setq autoloads (cons (concat (car path) | |
223 autoload-file-name) | |
224 autoloads))) | |
225 (setq path (cdr path))) | |
226 autoloads)) | |
227 | |
228 (defun packages-list-autoloads (source-directory) | |
229 "List autoload files in (what will be) the normal lisp search path. | |
230 This function is used during build to find where the global symbol files so | |
231 they can be perused for their useful information." | |
232 (let ((files (directory-files (file-name-as-directory source-directory) | |
233 t ".*")) | |
234 file autolist) | |
235 ;; (print (prin1-to-string source-directory)) | |
236 ;; (print (prin1-to-string files)) | |
237 (while (setq file (car-safe files)) | |
238 (if (and (file-directory-p file) | |
239 (file-exists-p (concat (file-name-as-directory file) | |
240 autoload-file-name))) | |
241 (setq autolist (cons (concat (file-name-as-directory file) | |
242 autoload-file-name) | |
243 autolist))) | |
244 (setq files (cdr files))) | |
245 autolist)) | |
246 | |
247 ;; The following function cannot be called from a bare temacs | |
248 (defun packages-new-autoloads () | |
249 "Return autoloads files that have been added or modified since XEmacs dump." | |
250 (require 'loadhist) | |
251 (let ((me (concat invocation-directory invocation-name)) | |
252 (path load-path) | |
253 result dir) | |
254 (while path | |
255 (setq dir (file-truename (car path))) | |
256 (let ((autoload-file (file-name-sans-extension (concat | |
257 dir | |
258 autoload-file-name)))) | |
259 ;; Check for: | |
260 ;; 1. An auto-autoload file that hasn't provided a feature (because | |
261 ;; it has been installed since XEmacs was dumped). | |
262 ;; 2. auto-autoload.el being newer than the executable | |
263 ;; 3. auto-autoload.elc being newer than the executable (the .el | |
264 ;; could be missing or compressed) | |
265 (when (or (and (null (file-provides autoload-file)) | |
266 (or (file-exists-p (concat autoload-file ".elc")) | |
267 (file-exists-p (concat autoload-file ".el")))) | |
268 (and (file-newer-than-file-p (concat autoload-file ".el") me) | |
269 (setq autoload-file (concat autoload-file ".el"))) | |
270 (and (file-newer-than-file-p (concat autoload-file | |
271 ".elc") | |
272 me) | |
273 (setq autoload-file (concat autoload-file ".elc")))) | |
274 (push autoload-file result))) | |
275 (setq path (cdr path))) | |
276 result)) | |
277 | |
278 ;; The following function cannot be called from a bare temacs | |
279 (defun packages-reload-autoloads () | |
280 "Reload new or updated auto-autoloads files. | |
281 This is an extremely dangerous function to call after the user-init-files | |
282 is run. Don't call it or you'll be sorry." | |
283 (let ((autoload-list (packages-new-autoloads))) | |
284 (while autoload-list | |
285 (let* ((autoload-file (car autoload-list)) | |
286 (feature (car-safe (file-provides autoload-file)))) | |
287 (when feature | |
288 ;; (message "(unload-feature %S)" feature) | |
289 (unload-feature feature)) | |
290 (condition-case nil | |
291 (load autoload-file) | |
292 (t nil))) | |
293 (setq autoload-list (cdr autoload-list))))) | |
294 | |
295 ;; Data-directory is really a list now. Provide something to search it for | |
296 ;; directories. | |
297 | |
298 (defun locate-data-directory-list (name &optional dir-list) | |
299 "Locate the matching list of directories in a search path DIR-LIST. | |
300 If no DIR-LIST is supplied, it defaults to `data-directory-list'." | |
301 (unless dir-list | |
302 (setq dir-list data-directory-list)) | |
303 (let (found found-dir found-dir-list) | |
304 (while dir-list | |
305 (setq found (file-name-as-directory (concat (car dir-list) name)) | |
306 found-dir (file-directory-p found)) | |
307 (and found-dir | |
308 (setq found-dir-list (cons found found-dir-list))) | |
309 (setq dir-list (cdr dir-list))) | |
310 (nreverse found-dir-list))) | |
311 | |
312 ;; Data-directory is really a list now. Provide something to search it for | |
313 ;; a directory. | |
314 | |
315 (defun locate-data-directory (name &optional dir-list) | |
316 "Locate a directory in a search path DIR-LIST (a list of directories). | |
317 If no DIR-LIST is supplied, it defaults to `data-directory-list'." | |
318 (unless dir-list | |
319 (setq dir-list data-directory-list)) | |
320 (let (found found-dir) | |
321 (while (and (null found-dir) dir-list) | |
322 (setq found (file-name-as-directory (concat (car dir-list) name)) | |
323 found-dir (file-directory-p found)) | |
324 (or found-dir | |
325 (setq found nil)) | |
326 (setq dir-list (cdr dir-list))) | |
327 found)) | |
328 | |
329 ;; Data-directory is really a list now. Provide something to search it for | |
330 ;; files. | |
331 | |
332 (defun locate-data-file (name &optional dir-list) | |
333 "Locate a file in a search path DIR-LIST (a list of directories). | |
334 If no DIR-LIST is supplied, it defaults to `data-directory-list'. | |
335 This function is basically a wrapper over `locate-file'." | |
633 | 336 (locate-file name (or dir-list data-directory-list))) |
428 | 337 |
338 ;; Path setup | |
339 | |
2456 | 340 (defun packages-find-package-hierarchies-named (package-directories base) |
341 "Find a set of package hierarchies within an XEmacs installation. | |
342 PACKAGE-DIRECTORIES is a list of package directories. | |
343 BASE is a subdirectory name for the hierarchy. | |
344 Returns list of hierarchies." | |
345 (paths-directories-which-exist | |
346 (mapcar #'(lambda (package-directory) | |
3179 | 347 (file-name-as-directory |
348 (concat (file-name-as-directory package-directory) | |
349 base))) | |
2456 | 350 package-directories))) |
428 | 351 |
352 (defun packages-split-path (path) | |
353 "Split PATH at \"\", return pair with two components. | |
354 The second component is shared with PATH." | |
355 (let ((reverse-tail '()) | |
356 (rest path)) | |
357 (while (and rest (null (string-equal "" (car rest)))) | |
358 (setq reverse-tail (cons (car rest) reverse-tail)) | |
359 (setq rest (cdr rest))) | |
360 (if (null rest) | |
361 (cons path nil) | |
362 (cons (nreverse reverse-tail) (cdr rest))))) | |
363 | |
364 (defun packages-split-package-path (package-path) | |
365 "Split up PACKAGE-PATH into early, late and last components. | |
366 The separation is by \"\" components. | |
2456 | 367 This returns |
368 (LIST EARLY-PACKAGE-HIERARCHIES LATE-PACKAGE-HIERARCHIES LAST-PACKAGE-HIERARCHIES)." | |
428 | 369 ;; When in doubt, it's late |
370 (let* ((stuff (packages-split-path package-path)) | |
371 (early (and (cdr stuff) (car stuff))) | |
372 (late+last (or (cdr stuff) (car stuff))) | |
373 (stuff (packages-split-path late+last)) | |
374 (late (car stuff)) | |
375 (last (cdr stuff))) | |
2456 | 376 (list (mapcar #'file-name-as-directory early) |
377 (mapcar #'file-name-as-directory late) | |
378 (mapcar #'file-name-as-directory last)))) | |
428 | 379 |
380 (defun packages-deconstruct (list consumer) | |
2456 | 381 "Deconstruct LIST and feed it to CONSUMER. |
382 CONSUMER is a function that accepts the elements of LISTS as separate arguments." | |
428 | 383 (apply consumer list)) |
384 | |
2456 | 385 (defun packages-find-installation-package-directories (roots) |
386 "Find the package directories in the XEmacs installation. | |
387 ROOTS is a list of installation roots." | |
5003
6b6b0f8ab749
#'union doesn't preserve relative order; use #'delete-duplicates instead.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4919
diff
changeset
|
388 (delete-duplicates |
6b6b0f8ab749
#'union doesn't preserve relative order; use #'delete-duplicates instead.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4919
diff
changeset
|
389 (nconc (paths-find-version-directories roots (list "") nil nil nil t) |
6b6b0f8ab749
#'union doesn't preserve relative order; use #'delete-duplicates instead.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4919
diff
changeset
|
390 (paths-find-site-directories roots (list "") nil)) |
6b6b0f8ab749
#'union doesn't preserve relative order; use #'delete-duplicates instead.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4919
diff
changeset
|
391 :test #'equal)) |
428 | 392 |
3179 | 393 (defun packages-find-package-hierarchies (package-directories &optional envvar default) |
2456 | 394 "Find package hierarchies in a list of package directories. |
395 PACKAGE-DIRECTORIES is a list of package directories. | |
3179 | 396 DEFAULT is a default list of package hierarchies. |
397 ENVVAR is the name of an environment variable that may override | |
398 the default." | |
399 (let* ((envvar-value (and envvar (getenv envvar))) | |
400 (package-directories | |
401 (if envvar-value | |
402 (split-path envvar-value) | |
403 package-directories))) | |
404 | |
405 (or (and (not envvar-value) default) | |
406 (let ((package-hierarchies '()) | |
407 (hierarchy-directories (packages-package-hierarchy-directory-names))) | |
408 (while hierarchy-directories | |
409 (setq package-hierarchies | |
410 (nconc package-hierarchies | |
411 (packages-find-package-hierarchies-named | |
412 package-directories | |
413 (car hierarchy-directories)))) | |
414 (setq hierarchy-directories (cdr hierarchy-directories))) | |
415 package-hierarchies)))) | |
2456 | 416 |
417 (defun packages-find-all-package-hierarchies (roots) | |
3179 | 418 "Find the package hierarchies. |
2456 | 419 ROOTS is a list of installation roots. |
420 Returns a list of three directory lists, the first being the list of early | |
421 hierarchies, the second that of the late hierarchies, and the third the | |
422 list of the last hierarchies." | |
3179 | 423 ;; EMACSPACKAGEPATH is a historical kludge |
428 | 424 (let ((envvar-value (getenv "EMACSPACKAGEPATH"))) |
3179 | 425 (cond |
426 (envvar-value | |
3184 | 427 (packages-deconstruct |
428 (packages-split-package-path (paths-decode-directory-path envvar-value)) | |
429 ;; we get package *directories* | |
430 #'(lambda (early late last) | |
431 (list | |
432 (packages-find-package-hierarchies early | |
433 "EMACSEARLYPACKAGES") | |
434 (packages-find-package-hierarchies late | |
435 "EMACSLATEPACKAGES") | |
436 (packages-find-package-hierarchies last | |
437 "EMACSLATEPACKAGES"))))) | |
438 ;; --with-package-path is also a historical kludge | |
3179 | 439 (configure-package-path |
428 | 440 (packages-deconstruct |
441 (packages-split-package-path configure-package-path) | |
3184 | 442 ;; we get package *hierarchies* |
3179 | 443 #'(lambda (early late last) |
2456 | 444 (list |
445 (packages-find-package-hierarchies (list user-init-directory) | |
3179 | 446 "EMACSEARLYPACKAGES" |
447 early) | |
2456 | 448 (packages-find-package-hierarchies (packages-find-installation-package-directories roots) |
3179 | 449 "EMACSLATEPACKAGES" |
450 | |
451 late) | |
2456 | 452 (packages-find-package-hierarchies '() |
3179 | 453 "EMACSLASTPACKAGES" |
454 last))))) | |
455 (t | |
456 (list | |
457 (packages-find-package-hierarchies (or configure-early-package-directories | |
458 (list user-init-directory)) | |
459 "EMACSEARLYPACKAGES") | |
460 (packages-find-package-hierarchies (or configure-late-package-directories | |
461 (packages-find-installation-package-directories roots)) | |
462 "EMACSLATEPACKAGES") | |
463 (packages-find-package-hierarchies configure-last-package-directories | |
464 "EMACSLASTPACKAGES")))))) | |
465 | |
2456 | 466 (defun packages-find-package-library-path (package-hierarchies suffixes) |
428 | 467 "Construct a path into a component of the packages hierarchy. |
2456 | 468 PACKAGE-HIERARCHIES is a list of package hierarchies. |
469 SUFFIXES is a list of names of hierarchy subdirectories to look for." | |
428 | 470 (let ((directories |
471 (apply | |
472 #'nconc | |
2456 | 473 (mapcar #'(lambda (hierarchy) |
428 | 474 (mapcar #'(lambda (suffix) |
2456 | 475 (file-name-as-directory (concat hierarchy suffix))) |
428 | 476 suffixes)) |
2456 | 477 package-hierarchies)))) |
428 | 478 (paths-directories-which-exist directories))) |
479 | |
2456 | 480 (defun packages-find-package-load-path (package-hierarchies) |
428 | 481 "Construct the load-path component for packages. |
2456 | 482 PACKAGE-HIERARCHIES is a list of package hierarchies." |
428 | 483 (paths-find-recursive-load-path |
2456 | 484 (packages-find-package-library-path package-hierarchies |
428 | 485 '("lisp")) |
486 packages-load-path-depth)) | |
487 | |
2456 | 488 (defun packages-find-package-exec-path (package-hierarchies) |
428 | 489 "Construct the exec-path component for packages. |
2456 | 490 PACKAGE-HIERARCHIES is a list of package hierarchies." |
491 (packages-find-package-library-path package-hierarchies | |
428 | 492 (list (paths-construct-path |
493 (list "bin" system-configuration)) | |
494 "lib-src"))) | |
495 | |
2456 | 496 (defun packages-find-package-info-path (package-hierarchies) |
428 | 497 "Construct the info-path component for packages. |
2456 | 498 PACKAGE-HIERARCHIES is a list of package directories." |
499 (packages-find-package-library-path package-hierarchies '("info"))) | |
428 | 500 |
2456 | 501 (defun packages-find-package-data-path (package-hierarchies) |
428 | 502 "Construct the data-path component for packages. |
2456 | 503 PACKAGE-HIERARCHIES is a list of package hierachies." |
428 | 504 (paths-find-recursive-load-path |
2456 | 505 (packages-find-package-library-path package-hierarchies |
428 | 506 '("etc")) |
507 packages-data-path-depth)) | |
508 | |
509 ;; Loading package initialization files | |
510 | |
511 (defun packages-load-package-lisps (package-load-path base) | |
512 "Load all Lisp files of a certain name along a load path. | |
513 BASE is the base name of the files." | |
514 (mapcar #'(lambda (dir) | |
793 | 515 (let ((file-name (expand-file-name base dir))) |
516 (with-trapping-errors | |
517 :operation (format "Autoload %s" file-name) | |
518 :class 'packages | |
519 (load file-name t t)))) | |
520 package-load-path)) | |
428 | 521 |
522 (defun packages-load-package-auto-autoloads (package-load-path) | |
523 "Load auto-autoload files along a load path." | |
524 (packages-load-package-lisps package-load-path | |
525 (file-name-sans-extension autoload-file-name))) | |
526 | |
527 (defun packages-handle-package-dumped-lisps (handle package-load-path) | |
528 "Load dumped-lisp.el files along a load path. | |
529 Call HANDLE on each file off definitions of PACKAGE-LISP there." | |
530 (mapcar #'(lambda (dir) | |
531 (let ((file-name (expand-file-name "dumped-lisp.el" dir))) | |
532 (if (file-exists-p file-name) | |
533 (let (package-lisp | |
534 ;; 20.4 packages could set this | |
535 preloaded-file-list) | |
536 (load file-name) | |
537 ;; dumped-lisp.el could have set this ... | |
538 (if package-lisp | |
539 (mapcar #'(lambda (base) | |
540 (funcall handle base)) | |
541 package-lisp)))))) | |
542 package-load-path)) | |
543 | |
544 (defun packages-load-package-dumped-lisps (package-load-path) | |
545 "Load dumped-lisp.el files along a load path. | |
444 | 546 Also load files off PACKAGE-LISP definitions there." |
428 | 547 (packages-handle-package-dumped-lisps #'load package-load-path)) |
548 | |
549 (defun packages-collect-package-dumped-lisps (package-load-path) | |
550 "Load dumped-lisp.el files along a load path. | |
444 | 551 Return list of files off PACKAGE-LISP definitions there." |
428 | 552 (let ((*files* '())) |
553 (packages-handle-package-dumped-lisps | |
554 #'(lambda (file) | |
555 (setq *files* (cons file *files*))) | |
556 package-load-path) | |
557 (reverse *files*))) | |
558 | |
559 (provide 'packages) | |
560 | |
561 ;;; packages.el ends here |