comparison lisp/loadhist.el @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 375f2633d815
children cb67264d6096
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
96 (mapcar (lambda (feature) 96 (mapcar (lambda (feature)
97 (list (symbol-name feature))) 97 (list (symbol-name feature)))
98 features) 98 features)
99 nil t))) 99 nil t)))
100 100
101 (defvar loadhist-hook-functions 101 (defvaralias 'loadhist-hook-functions 'unload-feature-special-hooks)
102 (defvar unload-feature-special-hooks
102 '(after-change-functions 103 '(after-change-functions
103 after-insert-file-functions auto-fill-function 104 after-insert-file-functions auto-fill-function
104 before-change-functions blink-paren-function 105 before-change-functions blink-paren-function
105 buffer-access-fontify-functions command-line-functions 106 buffer-access-fontify-functions command-line-functions
106 comment-indent-function kill-buffer-query-functions 107 comment-indent-function kill-buffer-query-functions
113 114
114 These are symbols with hook-type values whose names don't end in 115 These are symbols with hook-type values whose names don't end in
115 `-hook' or `-hooks', from which `unload-feature' tries to remove 116 `-hook' or `-hooks', from which `unload-feature' tries to remove
116 pertinent symbols.") 117 pertinent symbols.")
117 118
119 (defvar unload-hook-features-list nil
120 "List of features of the package being unloaded.
121
122 This is meant to be used by FEATURE-unload-hook hooks, see the
123 documentation of `unload-feature' for details.")
124
118 ;;;###autoload 125 ;;;###autoload
119 (defun unload-feature (feature &optional force) 126 (defun unload-feature (feature &optional force)
120 "Unload the library that provided FEATURE, restoring all its autoloads. 127 "Unload the library that provided FEATURE, restoring all its autoloads.
121 If the feature is required by any other loaded code, and prefix arg FORCE 128 If the feature is required by any other loaded code, and prefix arg FORCE
122 is nil, raise an error." 129 is nil, raise an error.
130
131 This function tries to undo modifications made by the package to
132 hooks. Packages may define a hook FEATURE-unload-hook that is called
133 instead of the normal heuristics for doing this. Such a hook should
134 undo all the relevant global state changes that may have been made by
135 loading the package or executing functions in it. It has access to
136 the package's feature list (before anything is unbound) in the
137 variable `unload-hook-features-list' and could remove features from it
138 in the event that the package has done something normally-ill-advised,
139 such as redefining an Emacs function."
123 (interactive (list (read-feature "Feature: ") current-prefix-arg)) 140 (interactive (list (read-feature "Feature: ") current-prefix-arg))
124 (if (not (featurep feature)) 141 (if (not (featurep feature))
125 (error "%s is not a currently loaded feature" (symbol-name feature))) 142 (error "%s is not a currently loaded feature" (symbol-name feature)))
126 (if (not force) 143 (if (not force)
127 (let* ((file (feature-file feature)) 144 (let* ((file (feature-file feature))
128 (dependents (delete file (copy-sequence (file-dependents file))))) 145 (dependents (delete file (copy-sequence (file-dependents file)))))
129 (if dependents 146 (if dependents
130 (error "Loaded libraries %s depend on %s" 147 (error "Loaded libraries %s depend on %s"
131 (prin1-to-string dependents) file)))) 148 (prin1-to-string dependents) file))))
132 (let* ((flist (feature-symbols feature)) 149 (let* ((unload-hook-features-list (feature-symbols feature))
133 (file (car flist)) 150 (file (car unload-hook-features-list))
134 (unload-hook (intern-soft (concat (symbol-name feature) 151 (unload-hook (intern-soft (concat (symbol-name feature)
135 "-unload-hook")))) 152 "-unload-hook"))))
136 ;; Try to avoid losing badly when hooks installed in critical 153 ;; Try to avoid losing badly when hooks installed in critical
137 ;; places go away. (Some packages install things on 154 ;; places go away. (Some packages install things on
138 ;; `kill-buffer-hook', `activate-menubar-hook' and the like.) 155 ;; `kill-buffer-hook', `activate-menubar-hook' and the like.)
139 ;; First off, provide a clean way for package `foo' to arrange 156 ;; First off, provide a clean way for package FOO to arrange
140 ;; this by defining `foo-unload-hook'. 157 ;; this by adding hooks on the variable `FOO-unload-hook'.
141 (if unload-hook 158 (if unload-hook
142 (run-hooks unload-hook) 159 (run-hooks unload-hook)
143 ;; Otherwise, do our best. Look through the obarray for symbols 160 ;; Otherwise, do our best. Look through the obarray for symbols
144 ;; which seem to be hook variables or special hook functions and 161 ;; which seem to be hook variables or special hook functions and
145 ;; remove anything from them which matches the feature-symbols 162 ;; remove anything from them which matches the feature-symbols
151 (lambda (x) 168 (lambda (x)
152 (if (or (and (boundp x) ; Random hooks. 169 (if (or (and (boundp x) ; Random hooks.
153 (consp (symbol-value x)) 170 (consp (symbol-value x))
154 (string-match "-hooks?\\'" (symbol-name x))) 171 (string-match "-hooks?\\'" (symbol-name x)))
155 (and (boundp x) ; Known abnormal hooks etc. 172 (and (boundp x) ; Known abnormal hooks etc.
156 (memq x loadhist-hook-functions))) 173 (memq x unload-feature-special-hooks)))
157 (dolist (y (cdr flist)) 174 (dolist (y (cdr unload-hook-features-list))
158 (remove-hook x y)))))) 175 (remove-hook x y))))))
159 (if (fboundp 'elp-restore-function) ; remove ELP stuff first 176 (if (fboundp 'elp-restore-function) ; remove ELP stuff first
160 (dolist (elt (cdr flist)) 177 (dolist (elt (cdr unload-hook-features-list))
161 (if (symbolp elt) 178 (if (symbolp elt)
162 (elp-restore-function elt)))) 179 (elp-restore-function elt))))
163 (mapc 180 (mapc
164 (lambda (x) 181 (lambda (x)
165 (cond ((stringp x) nil) 182 (cond ((stringp x) nil)
180 (if (fboundp 'ad-unadvise) 197 (if (fboundp 'ad-unadvise)
181 (ad-unadvise x)) 198 (ad-unadvise x))
182 (fmakunbound x) 199 (fmakunbound x)
183 (let ((aload (get x 'autoload))) 200 (let ((aload (get x 'autoload)))
184 (if aload (fset x (cons 'autoload aload)))))))) 201 (if aload (fset x (cons 'autoload aload))))))))
185 (cdr flist)) 202 (cdr unload-hook-features-list))
186 ;; Delete the load-history element for this file. 203 ;; Delete the load-history element for this file.
187 (let ((elt (assoc file load-history))) 204 (let ((elt (assoc file load-history)))
188 (setq load-history (delq elt load-history))))) 205 (setq load-history (delq elt load-history)))))
189 206
190 (provide 'loadhist) 207 (provide 'loadhist)
191 208
209 ;;; arch-tag: 70bb846a-c413-4f01-bf88-78dba4ac0798
192 ;;; loadhist.el ends here 210 ;;; loadhist.el ends here