annotate lisp/loadhist.el @ 272:c5d627a313b1 r21-0b34

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