- (unload-hook (intern-soft (concat (symbol-name feature)
- "-unload-hook"))))
- ;; Try to avoid losing badly when hooks installed in critical
- ;; places go away. (Some packages install things on
- ;; `kill-buffer-hook', `activate-menubar-hook' and the like.)
- ;; First off, provide a clean way for package FOO to arrange
- ;; this by adding hooks on the variable `FOO-unload-hook'.
- (if unload-hook
- (run-hooks unload-hook)
- ;; Otherwise, do our best. Look through the obarray for symbols
- ;; which seem to be hook variables or special hook functions and
- ;; remove anything from them which matches the feature-symbols
- ;; about to get zapped. Obviously this won't get anonymous
- ;; functions which the package might just have installed, and
- ;; there might be other important state, but this tactic
- ;; normally works.
- (mapatoms
- (lambda (x)
- (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))))
+ (name (symbol-name feature))
+ (unload-hook (intern-soft (concat name "-unload-hook")))
+ (unload-func (intern-soft (concat name "-unload-function"))))
+ ;; If FEATURE-unload-function is defined and returns non-nil,
+ ;; don't try to do anything more; otherwise proceed normally.
+ (unless (and (fboundp unload-func)
+ (funcall unload-func))
+ ;; Try to avoid losing badly when hooks installed in critical
+ ;; places go away. (Some packages install things on
+ ;; `kill-buffer-hook', `activate-menubar-hook' and the like.)
+ (if unload-hook
+ ;; First off, provide a clean way for package FOO to arrange
+ ;; this by adding hooks on the variable `FOO-unload-hook'.
+ ;; This is obsolete; FEATURE-unload-function should be used now.
+ (run-hooks unload-hook)
+ ;; Otherwise, do our best. Look through the obarray for symbols
+ ;; which seem to be hook variables or special hook functions and
+ ;; remove anything from them which matches the feature-symbols
+ ;; about to get zapped. Obviously this won't get anonymous
+ ;; functions which the package might just have installed, and
+ ;; there might be other important state, but this tactic
+ ;; normally works.
+ (mapatoms
+ (lambda (x)
+ (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-function-defs-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-function-defs-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)))))
+
+ ;; Change major mode in all buffers using one defined in the feature being unloaded.
+ (unload--set-major-mode)
+
+ (when (fboundp 'elp-restore-function) ; remove ELP stuff first
+ (dolist (elt unload-function-defs-list)
+ (when (symbolp elt)
+ (elp-restore-function elt))))