annotate lisp/loadhist.el @ 4372:ebb35ddea76a

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