- (if (or (and (boundp x) ; Random hooks.
- (consp (symbol-value x))
- (string-match "-hooks?\\'" (symbol-name x)))
- (and (boundp x) ; Known abnormal hooks etc.
- (memq x loadhist-hook-functions)))
- (dolist (y (cdr flist))
- (remove-hook x y))))))
- (if (fboundp 'elp-restore-list)
- (elp-restore-list (cdr flist)))
- (mapc
- (lambda (x)
- (cond ((stringp x) nil)
- ((consp x)
- ;; Remove any feature names that this file provided.
- (if (eq (car x) 'provide)
- (setq features (delq (cdr x) features))))
- (t
- (when (boundp x)
- (makunbound x))
- (when (fboundp x)
- (if (fboundp 'ad-unadvise)
- (ad-unadvise x))
- (fmakunbound x)
- (let ((aload (get x 'autoload)))
- (if aload (fset x (cons 'autoload aload))))))))
- (cdr flist))
+ (when (and (boundp x)
+ (or (and (consp (symbol-value x)) ; Random hooks.
+ (string-match "-hooks?\\'" (symbol-name x)))
+ (memq x unload-feature-special-hooks))) ; Known abnormal hooks etc.
+ (dolist (y unload-hook-features-list)
+ (when (and (eq (car-safe y) 'defun)
+ (not (get (cdr y) 'autoload)))
+ (remove-hook x (cdr y)))))))
+ ;; Remove any feature-symbols from auto-mode-alist as well.
+ (dolist (y unload-hook-features-list)
+ (when (and (eq (car-safe y) 'defun)
+ (not (get (cdr y) 'autoload)))
+ (setq auto-mode-alist
+ (rassq-delete-all (cdr y) auto-mode-alist)))))
+ (when (fboundp 'elp-restore-function) ; remove ELP stuff first
+ (dolist (elt unload-hook-features-list)
+ (when (symbolp elt)
+ (elp-restore-function elt))))
+ (dolist (x unload-hook-features-list)
+ (if (consp x)
+ (case (car x)
+ ;; Remove any feature names that this file provided.
+ (provide
+ (setq features (delq (cdr x) features)))
+ (defun
+ (let ((fun (cdr x)))
+ (when (fboundp fun)
+ (when (fboundp 'ad-unadvise)
+ (ad-unadvise fun))
+ (let ((aload (get fun 'autoload)))
+ (if aload
+ (fset fun (cons 'autoload aload))
+ (fmakunbound fun))))))
+ ((t require) nil)
+ (t (message "Unexpected element %s in load-history" x)))
+ ;; Kill local values as much as possible.
+ (dolist (buf (buffer-list))
+ (with-current-buffer buf
+ (if (and (boundp x) (timerp (symbol-value x)))
+ (cancel-timer (symbol-value x)))
+ (kill-local-variable x)))
+ (if (and (boundp x) (timerp (symbol-value x)))
+ (cancel-timer (symbol-value x)))
+ ;; Get rid of the default binding if we can.
+ (unless (local-variable-if-set-p x)
+ (makunbound x))))