annotate lisp/utils/loadhist.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; loadhist.el --- lisp functions for working with feature groups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Version: 1.0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; These functions exploit the load-history system variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; Entry points include `unload-feature', `symbol-file', and `feature-file'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (defun symbol-file (sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 "Return the input source from which SYM was loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 This is a file name, or nil if the source was a buffer with no associated file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (catch 'foundit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (function (lambda (x) (if (memq sym (cdr x)) (throw 'foundit (car x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 load-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defun feature-symbols (feature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 "Return the file and list of symbols associated with a given FEATURE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (catch 'foundit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (if (member (cons 'provide feature) (cdr x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (throw 'foundit x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 load-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defun feature-file (feature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 "Return the file name from which a given FEATURE was loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 Actually, return the load argument, if any; this is sometimes the name of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 Lisp file without an extension. If the feature came from an eval-buffer on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 a buffer with no associated file, or an eval-region, return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (if (not (featurep feature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (error "%s is not a currently loaded feature" (symbol-name feature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (car (feature-symbols feature))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defun file-provides (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "Return the list of features provided by FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (let ((symbols (cdr (assoc file load-history))) (provides nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (if (and (consp x) (eq (car x) 'provide))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (setq provides (cons (cdr x) provides)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 symbols)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 provides
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defun file-requires (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "Return the list of features required by FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (let ((symbols (cdr (assoc file load-history))) (requires nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (if (and (consp x) (eq (car x) 'require))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (setq requires (cons (cdr x) requires)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 symbols)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 requires
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defun file-set-intersect (p q)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; Return the set intersection of two lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (let ((ret nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (function (lambda (x) (if (memq x q) (setq ret (cons x ret)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ret
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defun file-dependents (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "Return the list of loaded libraries that depend on FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 This can include FILE itself."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (let ((provides (file-provides file)) (dependents nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (if (file-set-intersect provides (file-requires (car x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (setq dependents (cons (car x) dependents)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 load-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 dependents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defun unload-feature (feature &optional force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 "Unload the library that provided FEATURE, restoring all its autoloads.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 If the feature is required by any other loaded code, and optional FORCE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 is nil, raise an error."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (interactive "SFeature: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (if (not (featurep feature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (error "%s is not a currently loaded feature" (symbol-name feature)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (if (not force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (let* ((file (feature-file feature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (dependents (delete file (copy-sequence (file-dependents file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (if dependents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (error "Loaded libraries %s depend on %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (prin1-to-string dependents) file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (let* ((flist (feature-symbols feature)) (file (car flist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (cond ((stringp x) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ((consp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; Remove any feature names that this file provided.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (if (eq (car x) 'provide)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (setq features (delq (cdr x) features))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ((boundp x) (makunbound x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ((fboundp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (fmakunbound x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (let ((aload (get x 'autoload)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (if aload (fset x (cons 'autoload aload))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (cdr flist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; Delete the load-history element for this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (let ((elt (assoc file load-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (setq load-history (delq elt load-history)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (provide 'loadhist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;;; loadhist.el ends here