428
|
1 ;;; loadhist.el --- lisp functions for working with feature groups
|
|
2
|
|
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
|
|
6 ;; Version: 1.0
|
|
7 ;; Keywords: internal, dumped
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
24 ;; 02111-1307, USA.
|
|
25
|
|
26 ;;; Synched up with: FSF 20.2.
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; This file is dumped with XEmacs.
|
|
31
|
|
32 ;; These functions exploit the load-history system variable.
|
|
33 ;; Entry points include `unload-feature', `symbol-file', and `feature-file'.
|
|
34
|
|
35 ;;; Code:
|
|
36
|
|
37 ;; load-history is a list of entries that look like this:
|
|
38 ;; ("outline" outline-regexp ... (require . wid-edit) ... (provide . outline) ...)
|
|
39
|
|
40 (defun symbol-file (sym)
|
|
41 "Return the input source from which SYM was loaded.
|
|
42 This is a file name, or nil if the source was a buffer with no associated file."
|
|
43 (interactive "SFind source file for symbol: ") ; XEmacs
|
3368
|
44 (block look-up-symbol-file
|
|
45 (dolist (entry load-history)
|
|
46 (when (memq sym (cdr entry))
|
|
47 (return-from look-up-symbol-file (car entry))))
|
|
48 (when (or (and (boundp sym) (built-in-variable-type sym))
|
|
49 (and (fboundp sym) (subrp (symbol-function sym))))
|
|
50 (let ((built-in-file (built-in-symbol-file sym)))
|
|
51 (if built-in-file
|
3511
|
52 (concat source-directory "/src/" built-in-file))))))
|
428
|
53
|
|
54 (defun feature-symbols (feature)
|
|
55 "Return the file and list of symbols associated with a given FEATURE."
|
|
56 (let ((pair `(provide . ,feature)))
|
|
57 (dolist (entry load-history)
|
|
58 (when (member pair (cdr entry))
|
|
59 (return entry)))))
|
|
60
|
|
61 (defun feature-file (feature)
|
|
62 "Return the file name from which a given FEATURE was loaded.
|
|
63 Actually, return the load argument, if any; this is sometimes the name of a
|
|
64 Lisp file without an extension. If the feature came from an eval-buffer on
|
|
65 a buffer with no associated file, or an eval-region, return nil."
|
|
66 (unless (featurep feature)
|
|
67 (error "%s is not a currently loaded feature" (symbol-name feature)))
|
|
68 (car (feature-symbols feature)))
|
|
69
|
|
70 (defun file-symbols (file)
|
|
71 "Return the file and list of symbols associated with FILE.
|
|
72 The file name in the returned list is the string used to load the file,
|
|
73 and may not be the same string as FILE, but it will be equivalent."
|
|
74 (or (assoc file load-history)
|
|
75 (assoc (file-name-sans-extension file) load-history)
|
|
76 (assoc (concat file ".el") load-history)
|
|
77 (assoc (concat file ".elc") load-history)))
|
|
78
|
|
79 (defun file-provides (file)
|
|
80 "Return the list of features provided by FILE."
|
|
81 (let ((provides nil))
|
|
82 (dolist (x (cdr (file-symbols file)))
|
|
83 (when (eq (car-safe x) 'provide)
|
|
84 (push (cdr x) provides)))
|
|
85 provides))
|
|
86
|
|
87 (defun file-requires (file)
|
|
88 "Return the list of features required by FILE."
|
|
89 (let ((requires nil))
|
|
90 (dolist (x (cdr (file-symbols file)))
|
|
91 (when (eq (car-safe x) 'require)
|
|
92 (push (cdr x) requires)))
|
|
93 requires))
|
|
94
|
|
95 (defun file-dependents (file)
|
|
96 "Return the list of loaded libraries that depend on FILE.
|
|
97 This can include FILE itself."
|
|
98 (let ((provides (file-provides file))
|
|
99 (dependents nil))
|
|
100 (dolist (entry load-history)
|
|
101 (dolist (x (cdr entry))
|
|
102 (when (and (eq (car-safe x) 'require)
|
|
103 (memq (cdr-safe x) provides))
|
|
104 (push (car entry) dependents))))
|
|
105 dependents))
|
|
106
|
|
107 ;; FSFmacs
|
|
108 ;(defun read-feature (prompt)
|
|
109 ; "Read a feature name \(string\) from the minibuffer,
|
|
110 ;prompting with PROMPT and completing from `features', and
|
|
111 ;return the feature \(symbol\)."
|
|
112 ; (intern (completing-read prompt
|
|
113 ; (mapcar #'(lambda (feature)
|
|
114 ; (list (symbol-name feature)))
|
|
115 ; features)
|
|
116 ; nil t)))
|
|
117
|
|
118 ;; ;;;###autoload
|
|
119 (defun unload-feature (feature &optional force)
|
|
120 "Unload the library that provided FEATURE, restoring all its autoloads.
|
|
121 If the feature is required by any other loaded code, and optional FORCE
|
|
122 is nil, raise an error."
|
|
123 (interactive "SFeature: ")
|
|
124 (unless (featurep feature)
|
|
125 (error "%s is not a currently loaded feature" (symbol-name feature)))
|
|
126 (when (not force)
|
|
127 (let* ((file (feature-file feature))
|
|
128 (dependents (delete file (copy-sequence (file-dependents file)))))
|
|
129 (when dependents
|
|
130 (error "Loaded libraries %s depend on %s"
|
|
131 (prin1-to-string dependents) file))))
|
442
|
132 (let* ((flist (feature-symbols feature))
|
996
|
133 (file (car flist))
|
|
134 (unloading-module nil))
|
442
|
135 (flet ((reset-aload (x)
|
|
136 (let ((aload (get x 'autoload)))
|
|
137 (if aload (fset x (cons 'autoload aload))))))
|
428
|
138 (mapcar
|
|
139 #'(lambda (x)
|
|
140 (cond ((stringp x) nil)
|
|
141 ((consp x)
|
|
142 ;; Remove any feature names that this file provided.
|
|
143 (if (eq (car x) 'provide)
|
996
|
144 (setq features (delq (cdr x) features))
|
|
145 (if (eq (car x) 'module)
|
|
146 (setq unloading-module t))))
|
442
|
147 ((and (boundp x)
|
|
148 (fboundp x))
|
|
149 (makunbound x)
|
|
150 (fmakunbound x)
|
|
151 (reset-aload x))
|
|
152 ((boundp x)
|
|
153 (makunbound x))
|
428
|
154 ((fboundp x)
|
|
155 (fmakunbound x)
|
442
|
156 (reset-aload x))))
|
|
157 (cdr flist)))
|
428
|
158 ;; Delete the load-history element for this file.
|
|
159 (let ((elt (assoc file load-history)))
|
996
|
160 (setq load-history (delq elt load-history)))
|
|
161 ;; If it is a module, really unload it.
|
|
162 (if unloading-module
|
1111
|
163 (declare-fboundp (unload-module (symbol-name feature))))))
|
428
|
164
|
|
165 (provide 'loadhist)
|
|
166
|
|
167 ;;; loadhist.el ends here
|