annotate lisp/loadhist.el @ 13678:7d9570072e6c libc-951201 libc-951202 libc-951203 libc-951204

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