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