comparison lisp/loadhist.el @ 79145:e635cd6341e6

(unload-function-features-list): Rename from `unload-hook-features-list'. (unload-hook-features-list): Add as obsolete alias. (unload-feature): Use `unload-function-features-list' and new FEATURE-unload-function.
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 19 Oct 2007 08:55:14 +0000
parents c52ee056d7b0
children 8f2e292b71d0
comparison
equal deleted inserted replaced
79144:3adf56a260f9 79145:e635cd6341e6
144 144
145 These are symbols with hook-type values whose names don't end in 145 These are symbols with hook-type 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' tries to remove
147 pertinent symbols.") 147 pertinent symbols.")
148 148
149 (defvar unload-hook-features-list nil 149 (defvar unload-function-features-list nil
150 "List of features of the package being unloaded. 150 "List of features of the package being unloaded.
151 151
152 This is meant to be used by FEATURE-unload-hook hooks, 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
155 'unload-function-features-list "22.2")
154 156
155 ;;;###autoload 157 ;;;###autoload
156 (defun unload-feature (feature &optional force) 158 (defun unload-feature (feature &optional force)
157 "Unload the library that provided FEATURE, restoring all its autoloads. 159 "Unload the library that provided FEATURE, restoring all its autoloads.
158 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
179 (let* ((file (feature-file feature)) 181 (let* ((file (feature-file feature))
180 (dependents (delete file (copy-sequence (file-dependents file))))) 182 (dependents (delete file (copy-sequence (file-dependents file)))))
181 (when dependents 183 (when dependents
182 (error "Loaded libraries %s depend on %s" 184 (error "Loaded libraries %s depend on %s"
183 (prin1-to-string dependents) file)))) 185 (prin1-to-string dependents) file))))
184 (let* ((unload-hook-features-list (feature-symbols feature)) 186 (let* ((unload-function-features-list (feature-symbols feature))
185 (file (pop unload-hook-features-list)) 187 (file (pop unload-function-features-list))
186 ;; If non-nil, this is a symbol for which we should 188 ;; If non-nil, this is a symbol for which we should
187 ;; restore a previous autoload if possible. 189 ;; restore a previous autoload if possible.
188 restore-autoload 190 restore-autoload
189 (unload-hook (intern-soft (concat (symbol-name feature) 191 (name (symbol-name feature))
190 "-unload-hook")))) 192 (unload-hook (intern-soft (concat name "-unload-hook")))
191 ;; Try to avoid losing badly when hooks installed in critical 193 (unload-func (intern-soft (concat name "-unload-function"))))
192 ;; places go away. (Some packages install things on 194 ;; If FEATURE-unload-function is defined and returns non-nil,
193 ;; `kill-buffer-hook', `activate-menubar-hook' and the like.) 195 ;; don't try to do anything more; otherwise proceed normally.
194 ;; First off, provide a clean way for package FOO to arrange 196 (unless (and (bound-and-true-p unload-func)
195 ;; this by adding hooks on the variable `FOO-unload-hook'. 197 (funcall unload-func))
196 (if unload-hook 198 ;; Try to avoid losing badly when hooks installed in critical
197 (run-hooks unload-hook) 199 ;; places go away. (Some packages install things on
198 ;; Otherwise, do our best. Look through the obarray for symbols 200 ;; `kill-buffer-hook', `activate-menubar-hook' and the like.)
199 ;; which seem to be hook variables or special hook functions and 201 (if unload-hook
200 ;; remove anything from them which matches the feature-symbols 202 ;; First off, provide a clean way for package FOO to arrange
201 ;; about to get zapped. Obviously this won't get anonymous 203 ;; this by adding hooks on the variable `FOO-unload-hook'.
202 ;; functions which the package might just have installed, and 204 ;; This is obsolete; FEATURE-unload-function should be used now.
203 ;; there might be other important state, but this tactic 205 (run-hooks unload-hook)
204 ;; normally works. 206 ;; Otherwise, do our best. Look through the obarray for symbols
205 (mapatoms 207 ;; which seem to be hook variables or special hook functions and
206 (lambda (x) 208 ;; remove anything from them which matches the feature-symbols
207 (when (and (boundp x) 209 ;; about to get zapped. Obviously this won't get anonymous
208 (or (and (consp (symbol-value x)) ; Random hooks. 210 ;; functions which the package might just have installed, and
209 (string-match "-hooks?\\'" (symbol-name x))) 211 ;; there might be other important state, but this tactic
210 (memq x unload-feature-special-hooks))) ; Known abnormal hooks etc. 212 ;; normally works.
211 (dolist (y unload-hook-features-list) 213 (mapatoms
212 (when (and (eq (car-safe y) 'defun) 214 (lambda (x)
213 (not (get (cdr y) 'autoload))) 215 (when (and (boundp x)
214 (remove-hook x (cdr y))))))) 216 (or (and (consp (symbol-value x)) ; Random hooks.
215 ;; Remove any feature-symbols from auto-mode-alist as well. 217 (string-match "-hooks?\\'" (symbol-name x)))
216 (dolist (y unload-hook-features-list) 218 (memq x unload-feature-special-hooks))) ; Known abnormal hooks etc.
217 (when (and (eq (car-safe y) 'defun) 219 (dolist (y unload-function-features-list)
218 (not (get (cdr y) 'autoload))) 220 (when (and (eq (car-safe y) 'defun)
219 (setq auto-mode-alist 221 (not (get (cdr y) 'autoload)))
220 (rassq-delete-all (cdr y) auto-mode-alist))))) 222 (remove-hook x (cdr y)))))))
221 (when (fboundp 'elp-restore-function) ; remove ELP stuff first 223 ;; Remove any feature-symbols from auto-mode-alist as well.
222 (dolist (elt unload-hook-features-list) 224 (dolist (y unload-function-features-list)
223 (when (symbolp elt) 225 (when (and (eq (car-safe y) 'defun)
224 (elp-restore-function elt)))) 226 (not (get (cdr y) 'autoload)))
225 227 (setq auto-mode-alist
226 (dolist (x unload-hook-features-list) 228 (rassq-delete-all (cdr y) auto-mode-alist)))))
227 (if (consp x) 229 (when (fboundp 'elp-restore-function) ; remove ELP stuff first
228 (case (car x) 230 (dolist (elt unload-function-features-list)
229 ;; Remove any feature names that this file provided. 231 (when (symbolp elt)
230 (provide 232 (elp-restore-function elt))))
231 (setq features (delq (cdr x) features))) 233
232 ((defun autoload) 234 (dolist (x unload-function-features-list)
233 (let ((fun (cdr x))) 235 (if (consp x)
234 (when (fboundp fun) 236 (case (car x)
235 (when (fboundp 'ad-unadvise) 237 ;; Remove any feature names that this file provided.
236 (ad-unadvise fun)) 238 (provide
237 (let ((aload (get fun 'autoload))) 239 (setq features (delq (cdr x) features)))
238 (if (and aload (eq fun restore-autoload)) 240 ((defun autoload)
239 (fset fun (cons 'autoload aload)) 241 (let ((fun (cdr x)))
240 (fmakunbound fun)))))) 242 (when (fboundp fun)
241 ;; (t . SYMBOL) comes before (defun . SYMBOL) 243 (when (fboundp 'ad-unadvise)
242 ;; and says we should restore SYMBOL's autoload 244 (ad-unadvise fun))
243 ;; when we undefine it. 245 (let ((aload (get fun 'autoload)))
244 ((t) (setq restore-autoload (cdr x))) 246 (if (and aload (eq fun restore-autoload))
245 ((require defface) nil) 247 (fset fun (cons 'autoload aload))
246 (t (message "Unexpected element %s in load-history" x))) 248 (fmakunbound fun))))))
247 ;; Kill local values as much as possible. 249 ;; (t . SYMBOL) comes before (defun . SYMBOL)
248 (dolist (buf (buffer-list)) 250 ;; and says we should restore SYMBOL's autoload
249 (with-current-buffer buf 251 ;; when we undefine it.
250 (if (and (boundp x) (timerp (symbol-value x))) 252 ((t) (setq restore-autoload (cdr x)))
251 (cancel-timer (symbol-value x))) 253 ((require defface) nil)
252 (kill-local-variable x))) 254 (t (message "Unexpected element %s in load-history" x)))
253 (if (and (boundp x) (timerp (symbol-value x))) 255 ;; Kill local values as much as possible.
254 (cancel-timer (symbol-value x))) 256 (dolist (buf (buffer-list))
255 ;; Get rid of the default binding if we can. 257 (with-current-buffer buf
256 (unless (local-variable-if-set-p x) 258 (if (and (boundp x) (timerp (symbol-value x)))
257 (makunbound x)))) 259 (cancel-timer (symbol-value x)))
258 ;; Delete the load-history element for this file. 260 (kill-local-variable x)))
259 (setq load-history (delq (assoc file load-history) load-history))) 261 (if (and (boundp x) (timerp (symbol-value x)))
262 (cancel-timer (symbol-value x)))
263 ;; Get rid of the default binding if we can.
264 (unless (local-variable-if-set-p x)
265 (makunbound x))))
266 ;; Delete the load-history element for this file.
267 (setq load-history (delq (assoc file load-history) load-history))))
260 ;; Don't return load-history, it is not useful. 268 ;; Don't return load-history, it is not useful.
261 nil) 269 nil)
262 270
263 (provide 'loadhist) 271 (provide 'loadhist)
264 272