comparison lisp/loadhist.el @ 53998:2e361a295c26

(unload-feature): Doc fix. Rename flist to unload-hook-features-list.
author Eli Zaretskii <eliz@is.elta.co.il>
date Mon, 16 Feb 2004 17:39:38 +0000
parents aa04e56e2a40
children 8d106818ca97
comparison
equal deleted inserted replaced
53997:d45c69658d14 53998:2e361a295c26
118 118
119 ;;;###autoload 119 ;;;###autoload
120 (defun unload-feature (feature &optional force) 120 (defun unload-feature (feature &optional force)
121 "Unload the library that provided FEATURE, restoring all its autoloads. 121 "Unload the library that provided FEATURE, restoring all its autoloads.
122 If the feature is required by any other loaded code, and prefix arg FORCE 122 If the feature is required by any other loaded code, and prefix arg FORCE
123 is nil, raise an error." 123 is nil, raise an error.
124
125 This function tries to undo modifications made by the package to
126 hooks. Packages may define a hook FEATURE-unload-hook that is called
127 instead of the normal heuristics for doing this. Such a hook should
128 undo all the relevant global state changes that may have been made by
129 loading the package or executing functions in it. It has access to
130 the package's feature list (before anything is unbound) in the
131 variable `unload-hook-features-list' and could remove features from it
132 in the event that the package has done something normally-ill-advised,
133 such as redefining an Emacs function."
124 (interactive (list (read-feature "Feature: ") current-prefix-arg)) 134 (interactive (list (read-feature "Feature: ") current-prefix-arg))
125 (if (not (featurep feature)) 135 (if (not (featurep feature))
126 (error "%s is not a currently loaded feature" (symbol-name feature))) 136 (error "%s is not a currently loaded feature" (symbol-name feature)))
127 (if (not force) 137 (if (not force)
128 (let* ((file (feature-file feature)) 138 (let* ((file (feature-file feature))
129 (dependents (delete file (copy-sequence (file-dependents file))))) 139 (dependents (delete file (copy-sequence (file-dependents file)))))
130 (if dependents 140 (if dependents
131 (error "Loaded libraries %s depend on %s" 141 (error "Loaded libraries %s depend on %s"
132 (prin1-to-string dependents) file)))) 142 (prin1-to-string dependents) file))))
133 (let* ((flist (feature-symbols feature)) 143 (let* ((unload-hook-features-list (feature-symbols feature))
134 (file (car flist)) 144 (file (car unload-hook-features-list))
135 (unload-hook (intern-soft (concat (symbol-name feature) 145 (unload-hook (intern-soft (concat (symbol-name feature)
136 "-unload-hook")))) 146 "-unload-hook"))))
137 ;; Try to avoid losing badly when hooks installed in critical 147 ;; Try to avoid losing badly when hooks installed in critical
138 ;; places go away. (Some packages install things on 148 ;; places go away. (Some packages install things on
139 ;; `kill-buffer-hook', `activate-menubar-hook' and the like.) 149 ;; `kill-buffer-hook', `activate-menubar-hook' and the like.)
153 (if (or (and (boundp x) ; Random hooks. 163 (if (or (and (boundp x) ; Random hooks.
154 (consp (symbol-value x)) 164 (consp (symbol-value x))
155 (string-match "-hooks?\\'" (symbol-name x))) 165 (string-match "-hooks?\\'" (symbol-name x)))
156 (and (boundp x) ; Known abnormal hooks etc. 166 (and (boundp x) ; Known abnormal hooks etc.
157 (memq x unload-feature-special-hooks))) 167 (memq x unload-feature-special-hooks)))
158 (dolist (y (cdr flist)) 168 (dolist (y (cdr unload-hook-features-list))
159 (remove-hook x y)))))) 169 (remove-hook x y))))))
160 (if (fboundp 'elp-restore-function) ; remove ELP stuff first 170 (if (fboundp 'elp-restore-function) ; remove ELP stuff first
161 (dolist (elt (cdr flist)) 171 (dolist (elt (cdr unload-hook-features-list))
162 (if (symbolp elt) 172 (if (symbolp elt)
163 (elp-restore-function elt)))) 173 (elp-restore-function elt))))
164 (mapc 174 (mapc
165 (lambda (x) 175 (lambda (x)
166 (cond ((stringp x) nil) 176 (cond ((stringp x) nil)
181 (if (fboundp 'ad-unadvise) 191 (if (fboundp 'ad-unadvise)
182 (ad-unadvise x)) 192 (ad-unadvise x))
183 (fmakunbound x) 193 (fmakunbound x)
184 (let ((aload (get x 'autoload))) 194 (let ((aload (get x 'autoload)))
185 (if aload (fset x (cons 'autoload aload)))))))) 195 (if aload (fset x (cons 'autoload aload))))))))
186 (cdr flist)) 196 (cdr unload-hook-features-list))
187 ;; Delete the load-history element for this file. 197 ;; Delete the load-history element for this file.
188 (let ((elt (assoc file load-history))) 198 (let ((elt (assoc file load-history)))
189 (setq load-history (delq elt load-history))))) 199 (setq load-history (delq elt load-history)))))
190 200
191 (provide 'loadhist) 201 (provide 'loadhist)