comparison lisp/loadhist.el @ 79192:8f2e292b71d0

(unload-function-defs-list): Renamed from unload-function-features-list. (unload-feature-special-hooks, unload-feature): Doc fixes.
author Richard M. Stallman <rms@gnu.org>
date Wed, 24 Oct 2007 08:12:40 +0000
parents e635cd6341e6
children 70c9d3c324c3 b210bba3f477
comparison
equal deleted inserted replaced
79191:24b435ba9bce 79192:8f2e292b71d0
140 window-scroll-functions window-size-change-functions 140 window-scroll-functions window-size-change-functions
141 write-contents-functions write-file-functions 141 write-contents-functions write-file-functions
142 write-region-annotate-functions) 142 write-region-annotate-functions)
143 "A list of special hooks from Info node `(elisp)Standard Hooks'. 143 "A list of special hooks from Info node `(elisp)Standard Hooks'.
144 144
145 These are symbols with hook-type values whose names don't end in 145 These are symbols with hooklike values whose names don't end in
146 `-hook' or `-hooks', from which `unload-feature' tries to remove 146 `-hook' or `-hooks', from which `unload-feature' should try to remove
147 pertinent symbols.") 147 pertinent symbols.")
148 148
149 (defvar unload-function-features-list nil 149 (defvar unload-function-defs-list nil
150 "List of features of the package being unloaded. 150 "List of defintions in the Lisp library being unloaded.
151 151
152 This is meant to be used by FEATURE-unload-function, see the 152 This is meant to be used by `FEATURE-unload-function'; see the
153 documentation of `unload-feature' for details.") 153 documentation of `unload-feature' for details.")
154 (define-obsolete-variable-alias 'unload-hook-features-list 154 (define-obsolete-variable-alias 'unload-hook-features-list
155 'unload-function-features-list "22.2") 155 'unload-function-defs-list "22.2")
156 156
157 ;;;###autoload 157 ;;;###autoload
158 (defun unload-feature (feature &optional force) 158 (defun unload-feature (feature &optional force)
159 "Unload the library that provided FEATURE, restoring all its autoloads. 159 "Unload the library that provided FEATURE.
160 If the feature is required by any other loaded code, and prefix arg FORCE 160 If the feature is required by any other loaded code, and prefix arg FORCE
161 is nil, raise an error. 161 is nil, raise an error.
162 162
163 This function tries to undo any modifications that the package has 163 Standard unloading activities include restoring old autoloads for
164 made to hook values in Emacs. Normally it does this using heuristics. 164 functions defined by the library, undoing any additions that the
165 The packages may define a hook `FEATURE-unload-hook'; if that exists, 165 library has made to hook variables or to `auto-mode-alist', undoing
166 it is called instead of the normal heuristics. 166 ELP profiling of functions in that library, unproviding any features
167 167 provided by the library, and canceling timers held in variables
168 Such a hook should undo all the relevant global state changes that may 168 defined by the library.
169 have been made by loading the package or executing functions in it. 169
170 It has access to the package's feature list (before anything is unbound) 170 If a function `FEATURE-unload-function' is defined, this function
171 in the variable `unload-hook-features-list' and could remove features 171 calls it with no arguments, before doing anything else. That function
172 from it in the event that the package has done something strange, 172 can do whatever is appropriate to undo the loading of the library. If
173 such as redefining an Emacs function." 173 `FEATURE-unload-function' returns non-nil, that suppresses the
174 standard unloading of the library. Otherwise the standard unloading
175 proceeds.
176
177 `FEATURE-unload-function' has access to the package's list of
178 definitions in the variable `unload-function-defs-list' and could
179 remove symbols from it in the event that the package has done
180 something strange, such as redefining an Emacs function."
174 (interactive 181 (interactive
175 (list 182 (list
176 (read-feature "Unload feature: " t) 183 (read-feature "Unload feature: " t)
177 current-prefix-arg)) 184 current-prefix-arg))
178 (unless (featurep feature) 185 (unless (featurep feature)
181 (let* ((file (feature-file feature)) 188 (let* ((file (feature-file feature))
182 (dependents (delete file (copy-sequence (file-dependents file))))) 189 (dependents (delete file (copy-sequence (file-dependents file)))))
183 (when dependents 190 (when dependents
184 (error "Loaded libraries %s depend on %s" 191 (error "Loaded libraries %s depend on %s"
185 (prin1-to-string dependents) file)))) 192 (prin1-to-string dependents) file))))
186 (let* ((unload-function-features-list (feature-symbols feature)) 193 (let* ((unload-function-defs-list (feature-symbols feature))
187 (file (pop unload-function-features-list)) 194 (file (pop unload-function-defs-list))
188 ;; If non-nil, this is a symbol for which we should 195 ;; If non-nil, this is a symbol for which we should
189 ;; restore a previous autoload if possible. 196 ;; restore a previous autoload if possible.
190 restore-autoload 197 restore-autoload
191 (name (symbol-name feature)) 198 (name (symbol-name feature))
192 (unload-hook (intern-soft (concat name "-unload-hook"))) 199 (unload-hook (intern-soft (concat name "-unload-hook")))
214 (lambda (x) 221 (lambda (x)
215 (when (and (boundp x) 222 (when (and (boundp x)
216 (or (and (consp (symbol-value x)) ; Random hooks. 223 (or (and (consp (symbol-value x)) ; Random hooks.
217 (string-match "-hooks?\\'" (symbol-name x))) 224 (string-match "-hooks?\\'" (symbol-name x)))
218 (memq x unload-feature-special-hooks))) ; Known abnormal hooks etc. 225 (memq x unload-feature-special-hooks))) ; Known abnormal hooks etc.
219 (dolist (y unload-function-features-list) 226 (dolist (y unload-function-defs-list)
220 (when (and (eq (car-safe y) 'defun) 227 (when (and (eq (car-safe y) 'defun)
221 (not (get (cdr y) 'autoload))) 228 (not (get (cdr y) 'autoload)))
222 (remove-hook x (cdr y))))))) 229 (remove-hook x (cdr y)))))))
223 ;; Remove any feature-symbols from auto-mode-alist as well. 230 ;; Remove any feature-symbols from auto-mode-alist as well.
224 (dolist (y unload-function-features-list) 231 (dolist (y unload-function-defs-list)
225 (when (and (eq (car-safe y) 'defun) 232 (when (and (eq (car-safe y) 'defun)
226 (not (get (cdr y) 'autoload))) 233 (not (get (cdr y) 'autoload)))
227 (setq auto-mode-alist 234 (setq auto-mode-alist
228 (rassq-delete-all (cdr y) auto-mode-alist))))) 235 (rassq-delete-all (cdr y) auto-mode-alist)))))
229 (when (fboundp 'elp-restore-function) ; remove ELP stuff first 236 (when (fboundp 'elp-restore-function) ; remove ELP stuff first
230 (dolist (elt unload-function-features-list) 237 (dolist (elt unload-function-defs-list)
231 (when (symbolp elt) 238 (when (symbolp elt)
232 (elp-restore-function elt)))) 239 (elp-restore-function elt))))
233 240
234 (dolist (x unload-function-features-list) 241 (dolist (x unload-function-defs-list)
235 (if (consp x) 242 (if (consp x)
236 (case (car x) 243 (case (car x)
237 ;; Remove any feature names that this file provided. 244 ;; Remove any feature names that this file provided.
238 (provide 245 (provide
239 (setq features (delq (cdr x) features))) 246 (setq features (delq (cdr x) features)))