diff options
| author | Richard M. Stallman | 1998-06-13 01:38:33 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-06-13 01:38:33 +0000 |
| commit | fde4581d31747d165b404620351a3fc0bbb71f39 (patch) | |
| tree | ab5c7a488dd05cd20a5164ad5732adb8b5c3d753 | |
| parent | 221fc415b0454f4557d2c4b5e42ec184bdf8df39 (diff) | |
| download | emacs-fde4581d31747d165b404620351a3fc0bbb71f39.tar.gz emacs-fde4581d31747d165b404620351a3fc0bbb71f39.zip | |
(read-feature): Doc fix.
(loadhist-hook-functions): New variable.
(unload-feature): Act on FEATURE-unload-hook or look for unloaded
functions on hooks and remove them.
| -rw-r--r-- | lisp/loadhist.el | 78 |
1 files changed, 60 insertions, 18 deletions
diff --git a/lisp/loadhist.el b/lisp/loadhist.el index 726ae22e8da..1c727688ce7 100644 --- a/lisp/loadhist.el +++ b/lisp/loadhist.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; loadhist.el --- lisp functions for working with feature groups | 1 | ;;; loadhist.el --- lisp functions for working with feature groups |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1995 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1995, 1998 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> | 5 | ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> |
| 6 | ;; Version: 1.0 | 6 | ;; Version: 1.0 |
| @@ -26,7 +26,8 @@ | |||
| 26 | ;;; Commentary: | 26 | ;;; Commentary: |
| 27 | 27 | ||
| 28 | ;; These functions exploit the load-history system variable. | 28 | ;; These functions exploit the load-history system variable. |
| 29 | ;; Entry points include `unload-feature', `symbol-file', and `feature-file'. | 29 | ;; Entry points include `unload-feature', `symbol-file', and |
| 30 | ;; `feature-file', documented in the Emacs Lisp manual. | ||
| 30 | 31 | ||
| 31 | ;;; Code: | 32 | ;;; Code: |
| 32 | 33 | ||
| @@ -102,8 +103,8 @@ This can include FILE itself." | |||
| 102 | )) | 103 | )) |
| 103 | 104 | ||
| 104 | (defun read-feature (prompt) | 105 | (defun read-feature (prompt) |
| 105 | "Read a feature name \(string\) from the minibuffer, | 106 | "Read a feature name \(string\) from the minibuffer. |
| 106 | prompting with PROMPT and completing from `features', and | 107 | Prompt with PROMPT and completing from `features', and |
| 107 | return the feature \(symbol\)." | 108 | return the feature \(symbol\)." |
| 108 | (intern (completing-read prompt | 109 | (intern (completing-read prompt |
| 109 | (mapcar (function (lambda (feature) | 110 | (mapcar (function (lambda (feature) |
| @@ -111,6 +112,22 @@ return the feature \(symbol\)." | |||
| 111 | features) | 112 | features) |
| 112 | nil t))) | 113 | nil t))) |
| 113 | 114 | ||
| 115 | (defvar loadhist-hook-functions | ||
| 116 | '(after-change-function after-change-functions | ||
| 117 | after-insert-file-functions auto-fill-function before-change-function | ||
| 118 | before-change-functions blink-paren-function | ||
| 119 | buffer-access-fontify-functions command-line-functions | ||
| 120 | comment-indent-function kill-buffer-query-functions | ||
| 121 | kill-emacs-query-functions lisp-indent-function | ||
| 122 | redisplay-end-trigger-functions temp-buffer-show-function | ||
| 123 | window-scroll-functions window-size-change-functions | ||
| 124 | write-region-annotate-functions) | ||
| 125 | "A list of special hooks from the `Standard Hooks' node of the Lisp manual. | ||
| 126 | |||
| 127 | These are symbols with hook-type values whose names don't end in | ||
| 128 | `-hook' or `-hooks', from which `unload-feature' tries to remove | ||
| 129 | pertinent symbols.") | ||
| 130 | |||
| 114 | ;;;###autoload | 131 | ;;;###autoload |
| 115 | (defun unload-feature (feature &optional force) | 132 | (defun unload-feature (feature &optional force) |
| 116 | "Unload the library that provided FEATURE, restoring all its autoloads. | 133 | "Unload the library that provided FEATURE, restoring all its autoloads. |
| @@ -124,21 +141,46 @@ is nil, raise an error." | |||
| 124 | (dependents (delete file (copy-sequence (file-dependents file))))) | 141 | (dependents (delete file (copy-sequence (file-dependents file))))) |
| 125 | (if dependents | 142 | (if dependents |
| 126 | (error "Loaded libraries %s depend on %s" | 143 | (error "Loaded libraries %s depend on %s" |
| 127 | (prin1-to-string dependents) file) | 144 | (prin1-to-string dependents) file)))) |
| 128 | ))) | 145 | (let* ((flist (feature-symbols feature)) |
| 129 | (let* ((flist (feature-symbols feature)) (file (car flist))) | 146 | (file (car flist)) |
| 147 | (unload-hook (intern-soft (concat (symbol-name feature) | ||
| 148 | "-unload-hook")))) | ||
| 149 | ;; Try to avoid losing badly when hooks installed in critical | ||
| 150 | ;; places go away. (Some packages install things on | ||
| 151 | ;; `kill-buffer-hook', `activate-menubar-hook' and the like.) | ||
| 152 | ;; First off, provide a clean way for package `foo' to arrange | ||
| 153 | ;; this by defining `foo-unload-hook'. | ||
| 154 | (if unload-hook | ||
| 155 | (run-hooks unload-hook) | ||
| 156 | ;; Otherwise, do our best. Look through the obarray for symbols | ||
| 157 | ;; which seem to be hook variables or special hook functions and | ||
| 158 | ;; remove anything from them which matches the feature-symbols | ||
| 159 | ;; about to get zapped. Obviously this won't get anonymous | ||
| 160 | ;; functions which the package might just have installed, and | ||
| 161 | ;; there might be other important state, but this tactic | ||
| 162 | ;; normally works. | ||
| 163 | (mapatoms | ||
| 164 | (lambda (x) | ||
| 165 | (if (or (and (boundp x) ; Random hooks. | ||
| 166 | (consp (symbol-value x)) | ||
| 167 | (string-match "-hooks?\\'" (symbol-name x))) | ||
| 168 | (and (fboundp x) ; Known abnormal hooks etc. | ||
| 169 | (memq x loadhist-hook-functions))) | ||
| 170 | (mapcar (lambda (y) (remove-hook x y)) | ||
| 171 | (cdr flist)))))) | ||
| 130 | (mapcar | 172 | (mapcar |
| 131 | (function (lambda (x) | 173 | (lambda (x) |
| 132 | (cond ((stringp x) nil) | 174 | (cond ((stringp x) nil) |
| 133 | ((consp x) | 175 | ((consp x) |
| 134 | ;; Remove any feature names that this file provided. | 176 | ;; Remove any feature names that this file provided. |
| 135 | (if (eq (car x) 'provide) | 177 | (if (eq (car x) 'provide) |
| 136 | (setq features (delq (cdr x) features)))) | 178 | (setq features (delq (cdr x) features)))) |
| 137 | ((boundp x) (makunbound x)) | 179 | ((boundp x) (makunbound x)) |
| 138 | ((fboundp x) | 180 | ((fboundp x) |
| 139 | (fmakunbound x) | 181 | (fmakunbound x) |
| 140 | (let ((aload (get x 'autoload))) | 182 | (let ((aload (get x 'autoload))) |
| 141 | (if aload (fset x (cons 'autoload aload)))))))) | 183 | (if aload (fset x (cons 'autoload aload))))))) |
| 142 | (cdr flist)) | 184 | (cdr flist)) |
| 143 | ;; Delete the load-history element for this file. | 185 | ;; Delete the load-history element for this file. |
| 144 | (let ((elt (assoc file load-history))) | 186 | (let ((elt (assoc file load-history))) |