]> code.delx.au - gnu-emacs/blobdiff - lisp/loadhist.el
(cvs-tags-list, cvs-retrieve-revision, cvs-find-modif)
[gnu-emacs] / lisp / loadhist.el
index 635059f93e534b467f31bc99628ea6249c2a41c5..70f2ee2064602276b24f6815873a8a57d57da5ad 100644 (file)
@@ -1,7 +1,7 @@
 ;;; loadhist.el --- lisp functions for working with feature groups
 
-;; Copyright (C) 1995, 1998, 2000, 2002, 2003, 2004,
-;;   2005, 2006 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 1998, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
 ;; Maintainer: FSF
@@ -11,7 +11,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -111,15 +111,18 @@ A library name is equivalent to the file name that `load-library' would load."
          (setq dependents (cons (car x) dependents))))
     dependents))
 
-(defun read-feature (prompt)
-  "Read a feature name \(string\) from the minibuffer.
-Prompt with PROMPT and completing from `features', and
-return the feature \(symbol\)."
-  (intern (completing-read prompt
-                          (mapcar (lambda (feature)
-                                    (list (symbol-name feature)))
-                                  features)
-                          nil t)))
+(defun read-feature (prompt &optional loaded-p)
+  "Read feature name from the minibuffer, prompting with string PROMPT.
+If optional second arg LOADED-P is non-nil, the feature must be loaded
+from a file."
+  (intern
+   (completing-read prompt
+                   (cons nil features)
+                   (and loaded-p
+                        #'(lambda (f)
+                            (and f     ; ignore nil
+                                 (feature-file f))))
+                   loaded-p)))
 
 (defvaralias 'loadhist-hook-functions 'unload-feature-special-hooks)
 (defvar unload-feature-special-hooks
@@ -160,7 +163,10 @@ the package's feature list (before anything is unbound) in the
 variable `unload-hook-features-list' and could remove features from it
 in the event that the package has done something normally-ill-advised,
 such as redefining an Emacs function."
-  (interactive (list (read-feature "Feature: ") current-prefix-arg))
+  (interactive
+   (list
+    (read-feature "Unload feature: " t)
+    current-prefix-arg))
   (unless (featurep feature)
     (error "%s is not a currently loaded feature" (symbol-name feature)))
   (unless force
@@ -171,6 +177,9 @@ such as redefining an Emacs function."
               (prin1-to-string dependents) file))))
   (let* ((unload-hook-features-list (feature-symbols feature))
          (file (pop unload-hook-features-list))
+        ;; If non-nil, this is a symbol for which we should
+        ;; restore a previous autoload if possible.
+        restore-autoload
          (unload-hook (intern-soft (concat (symbol-name feature)
                                            "-unload-hook"))))
     ;; Try to avoid losing badly when hooks installed in critical
@@ -207,23 +216,28 @@ such as redefining an Emacs function."
       (dolist (elt unload-hook-features-list)
        (when (symbolp elt)
          (elp-restore-function elt))))
+
     (dolist (x unload-hook-features-list)
       (if (consp x)
          (case (car x)
           ;; Remove any feature names that this file provided.
           (provide
            (setq features (delq (cdr x) features)))
-          (defun
+          ((defun autoload)
            (let ((fun (cdr x)))
              (when (fboundp fun)
                (when (fboundp 'ad-unadvise)
                  (ad-unadvise fun))
                (let ((aload (get fun 'autoload)))
-                 (if aload
+                 (if (and aload (eq fun restore-autoload))
                       (fset fun (cons 'autoload aload))
                     (fmakunbound fun))))))
-           (require nil)
-           (t (message "Unexpected element %s in load-history" x)))
+          ;; (t . SYMBOL) comes before (defun . SYMBOL)
+          ;; and says we should restore SYMBOL's autoload
+          ;; when we undefine it.
+          ((t) (setq restore-autoload (cdr x)))
+           ((require defface) nil)
+          (t (message "Unexpected element %s in load-history" x)))
        ;; Kill local values as much as possible.
        (dolist (buf (buffer-list))
          (with-current-buffer buf
@@ -236,7 +250,9 @@ such as redefining an Emacs function."
        (unless (local-variable-if-set-p x)
          (makunbound x))))
     ;; Delete the load-history element for this file.
-    (setq load-history (delq (assoc file load-history) load-history))))
+    (setq load-history (delq (assoc file load-history) load-history)))
+  ;; Don't return load-history, it is not useful.
+  nil)
 
 (provide 'loadhist)