;;; 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
;; 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,
(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
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
(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
(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
(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)