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