Mercurial > hg > xemacs-beta
annotate lisp/loadhist.el @ 4367:69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
src/ChangeLog addition:
2007-12-30 Aidan Kehoe <kehoea@parhasard.net>
* doc.c (Fbuilt_in_symbol_file):
Take a new TYPE argument, specifying whether the function or
variable definition of the symbol should be searched for.
Handle built-in macros correctly.
lisp/ChangeLog addition:
2007-12-30 Aidan Kehoe <kehoea@parhasard.net>
* loadhist.el (symbol-file):
Accept a new TYPE argument, compatible with GNU, saying
whether function or variable definitions should be searched for.
Implement the functionality for autoloads, handling TYPE
correctly.
Pass the TYPE argument to built-in-symbol-file correctly.
Document that TYPE is not implemented for non-autoloaded Lisp
definitions. Our load-history doesn't have the relevant metadata.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 30 Dec 2007 15:33:13 +0100 |
parents | 1ee424086c62 |
children | 69a1eda3da06 |
rev | line source |
---|---|
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 | |
4367
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
28 ;; #### Sync this file! |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
29 |
428 | 30 ;;; Commentary: |
31 | |
32 ;; This file is dumped with XEmacs. | |
33 | |
34 ;; These functions exploit the load-history system variable. | |
35 ;; Entry points include `unload-feature', `symbol-file', and `feature-file'. | |
36 | |
37 ;;; Code: | |
38 | |
39 ;; load-history is a list of entries that look like this: | |
40 ;; ("outline" outline-regexp ... (require . wid-edit) ... (provide . outline) ...) | |
41 | |
4367
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
42 (defun symbol-file (sym &optional type) |
428 | 43 "Return the input source from which SYM was loaded. |
4367
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
44 This is a file name, or nil if the source was a buffer with no associated file. |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
45 |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
46 If TYPE is nil or omitted, any kind of definition is acceptable. |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
47 If TYPE is `defun', then function, subr, special form or macro definitions |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
48 are acceptable. |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
49 If TYPE is `defvar', then variable definitions are acceptable. |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
50 |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
51 #### For the moment the difference is not implemented for non-autoloaded |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
52 Lisp symbols." |
428 | 53 (interactive "SFind source file for symbol: ") ; XEmacs |
3368 | 54 (block look-up-symbol-file |
4367
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
55 (let (built-in-file autoload-cons) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
56 (when (and |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
57 (eq 'autoload |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
58 (car-safe (setq autoload-cons |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
59 (and (fboundp sym) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
60 (symbol-function sym))))) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
61 (or (and (or (null type) (eq 'defvar type)) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
62 (eq (fifth autoload-cons) 'keymap)) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
63 (and (or (null type) (eq 'defvar type)) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
64 (memq (fifth autoload-cons) '(nil macro))))) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
65 (return-from look-up-symbol-file |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
66 (locate-library (second autoload-cons)))) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
67 (dolist (entry load-history) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
68 (when (memq sym (cdr entry)) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
69 (return-from look-up-symbol-file (car entry)))) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
70 (setq built-in-file (built-in-symbol-file sym type)) |
69e6352406f0
Handle macros, autoloads correctly in symbol-file. Add an incomplete TYPE arg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3511
diff
changeset
|
71 (if built-in-file (concat source-directory "/src/" built-in-file))))) |
428 | 72 |
73 (defun feature-symbols (feature) | |
74 "Return the file and list of symbols associated with a given FEATURE." | |
75 (let ((pair `(provide . ,feature))) | |
76 (dolist (entry load-history) | |
77 (when (member pair (cdr entry)) | |
78 (return entry))))) | |
79 | |
80 (defun feature-file (feature) | |
81 "Return the file name from which a given FEATURE was loaded. | |
82 Actually, return the load argument, if any; this is sometimes the name of a | |
83 Lisp file without an extension. If the feature came from an eval-buffer on | |
84 a buffer with no associated file, or an eval-region, return nil." | |
85 (unless (featurep feature) | |
86 (error "%s is not a currently loaded feature" (symbol-name feature))) | |
87 (car (feature-symbols feature))) | |
88 | |
89 (defun file-symbols (file) | |
90 "Return the file and list of symbols associated with FILE. | |
91 The file name in the returned list is the string used to load the file, | |
92 and may not be the same string as FILE, but it will be equivalent." | |
93 (or (assoc file load-history) | |
94 (assoc (file-name-sans-extension file) load-history) | |
95 (assoc (concat file ".el") load-history) | |
96 (assoc (concat file ".elc") load-history))) | |
97 | |
98 (defun file-provides (file) | |
99 "Return the list of features provided by FILE." | |
100 (let ((provides nil)) | |
101 (dolist (x (cdr (file-symbols file))) | |
102 (when (eq (car-safe x) 'provide) | |
103 (push (cdr x) provides))) | |
104 provides)) | |
105 | |
106 (defun file-requires (file) | |
107 "Return the list of features required by FILE." | |
108 (let ((requires nil)) | |
109 (dolist (x (cdr (file-symbols file))) | |
110 (when (eq (car-safe x) 'require) | |
111 (push (cdr x) requires))) | |
112 requires)) | |
113 | |
114 (defun file-dependents (file) | |
115 "Return the list of loaded libraries that depend on FILE. | |
116 This can include FILE itself." | |
117 (let ((provides (file-provides file)) | |
118 (dependents nil)) | |
119 (dolist (entry load-history) | |
120 (dolist (x (cdr entry)) | |
121 (when (and (eq (car-safe x) 'require) | |
122 (memq (cdr-safe x) provides)) | |
123 (push (car entry) dependents)))) | |
124 dependents)) | |
125 | |
126 ;; FSFmacs | |
127 ;(defun read-feature (prompt) | |
128 ; "Read a feature name \(string\) from the minibuffer, | |
129 ;prompting with PROMPT and completing from `features', and | |
130 ;return the feature \(symbol\)." | |
131 ; (intern (completing-read prompt | |
132 ; (mapcar #'(lambda (feature) | |
133 ; (list (symbol-name feature))) | |
134 ; features) | |
135 ; nil t))) | |
136 | |
137 ;; ;;;###autoload | |
138 (defun unload-feature (feature &optional force) | |
139 "Unload the library that provided FEATURE, restoring all its autoloads. | |
140 If the feature is required by any other loaded code, and optional FORCE | |
141 is nil, raise an error." | |
142 (interactive "SFeature: ") | |
143 (unless (featurep feature) | |
144 (error "%s is not a currently loaded feature" (symbol-name feature))) | |
145 (when (not force) | |
146 (let* ((file (feature-file feature)) | |
147 (dependents (delete file (copy-sequence (file-dependents file))))) | |
148 (when dependents | |
149 (error "Loaded libraries %s depend on %s" | |
150 (prin1-to-string dependents) file)))) | |
442 | 151 (let* ((flist (feature-symbols feature)) |
996 | 152 (file (car flist)) |
153 (unloading-module nil)) | |
442 | 154 (flet ((reset-aload (x) |
155 (let ((aload (get x 'autoload))) | |
156 (if aload (fset x (cons 'autoload aload)))))) | |
428 | 157 (mapcar |
158 #'(lambda (x) | |
159 (cond ((stringp x) nil) | |
160 ((consp x) | |
161 ;; Remove any feature names that this file provided. | |
162 (if (eq (car x) 'provide) | |
996 | 163 (setq features (delq (cdr x) features)) |
164 (if (eq (car x) 'module) | |
165 (setq unloading-module t)))) | |
442 | 166 ((and (boundp x) |
167 (fboundp x)) | |
168 (makunbound x) | |
169 (fmakunbound x) | |
170 (reset-aload x)) | |
171 ((boundp x) | |
172 (makunbound x)) | |
428 | 173 ((fboundp x) |
174 (fmakunbound x) | |
442 | 175 (reset-aload x)))) |
176 (cdr flist))) | |
428 | 177 ;; Delete the load-history element for this file. |
178 (let ((elt (assoc file load-history))) | |
996 | 179 (setq load-history (delq elt load-history))) |
180 ;; If it is a module, really unload it. | |
181 (if unloading-module | |
1111 | 182 (declare-fboundp (unload-module (symbol-name feature)))))) |
428 | 183 |
184 (provide 'loadhist) | |
185 | |
186 ;;; loadhist.el ends here |