annotate lisp/utils/loadhist.el @ 80:1ce6082ce73f r20-0b90

Import from CVS: tag r20-0b90
author cvs
date Mon, 13 Aug 2007 09:06:37 +0200
parents 131b0175ea99
children
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
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
0
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
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; These functions exploit the load-history system variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; Entry points include `unload-feature', `symbol-file', and `feature-file'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defun symbol-file (sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "Return the input source from which SYM was loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 This is a file name, or nil if the source was a buffer with no associated file."
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
37 (interactive "S") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (catch 'foundit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (function (lambda (x) (if (memq sym (cdr x)) (throw 'foundit (car x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 load-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defun feature-symbols (feature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "Return the file and list of symbols associated with a given FEATURE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (catch 'foundit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (if (member (cons 'provide feature) (cdr x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (throw 'foundit x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 load-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defun feature-file (feature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 "Return the file name from which a given FEATURE was loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 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
57 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
58 a buffer with no associated file, or an eval-region, return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (if (not (featurep feature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (error "%s is not a currently loaded feature" (symbol-name feature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (car (feature-symbols feature))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defun file-provides (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 "Return the list of features provided by FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (let ((symbols (cdr (assoc file load-history))) (provides nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (if (and (consp x) (eq (car x) 'provide))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (setq provides (cons (cdr x) provides)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 symbols)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 provides
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defun file-requires (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "Return the list of features required by FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (let ((symbols (cdr (assoc file load-history))) (requires nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if (and (consp x) (eq (car x) 'require))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (setq requires (cons (cdr x) requires)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 symbols)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 requires
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defun file-set-intersect (p q)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; Return the set intersection of two lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (let ((ret nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (function (lambda (x) (if (memq x q) (setq ret (cons x ret)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ret
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun file-dependents (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "Return the list of loaded libraries that depend on FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 This can include FILE itself."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (let ((provides (file-provides file)) (dependents nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (if (file-set-intersect provides (file-requires (car x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq dependents (cons (car x) dependents)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 load-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 dependents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defun unload-feature (feature &optional force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "Unload the library that provided FEATURE, restoring all its autoloads.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 If the feature is required by any other loaded code, and optional FORCE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 is nil, raise an error."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (interactive "SFeature: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (if (not (featurep feature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (error "%s is not a currently loaded feature" (symbol-name feature)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if (not force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (let* ((file (feature-file feature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (dependents (delete file (copy-sequence (file-dependents file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (if dependents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (error "Loaded libraries %s depend on %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (prin1-to-string dependents) file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (let* ((flist (feature-symbols feature)) (file (car flist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (cond ((stringp x) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ((consp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; Remove any feature names that this file provided.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (if (eq (car x) 'provide)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (setq features (delq (cdr x) features))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ((boundp x) (makunbound x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ((fboundp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (fmakunbound x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (let ((aload (get x 'autoload)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (if aload (fset x (cons 'autoload aload))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (cdr flist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; Delete the load-history element for this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (let ((elt (assoc file load-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (setq load-history (delq elt load-history)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (provide 'loadhist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;;; loadhist.el ends here