annotate lisp/loadhist.el @ 76187:f2d38d2862fe

(vsize): Increase in 2 column case. (\key): Tweak space for description. (\overfullrule): Set to 0pt to hide small overflows. (nopagenumbers): Call to turn off numbers in 1 page document. (Obtenir de l'aide, Modifier le tampon Dired): Swap sections to balance column length. (Mettre un flag sur les fichiers \`a d\'etruire): Hack in a line break to prevent overfull line. (find-names-dired): Use \key rather than \metax as a hack fix for overflow.
author Glenn Morris <rgm@gnu.org>
date Tue, 27 Feb 2007 03:35:43 +0000
parents 1c398694f7b2
children a188649f301c 52a7f3f50b89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; loadhist.el --- lisp functions for working with feature groups
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12751
diff changeset
2
74442
b2e5081b9320 Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 73722
diff changeset
3 ;; Copyright (C) 1995, 1998, 2000, 2001, 2002, 2003, 2004,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74442
diff changeset
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
29090
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
7 ;; Maintainer: FSF
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Keywords: internal
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
11289
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
10 ;; This file is part of GNU Emacs.
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
11
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
15 ;; any later version.
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
16
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
20 ;; GNU General Public License for more details.
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
21
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
22 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12751
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 61720
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 61720
diff changeset
25 ;; Boston, MA 02110-1301, USA.
11289
b8ba33ac2f22 Comment changes.
Karl Heuer <kwzh@gnu.org>
parents: 10498
diff changeset
26
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; These functions exploit the load-history system variable.
22459
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
30 ;; Entry points include `unload-feature', `symbol-file', and
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
31 ;; `feature-file', documented in the Emacs Lisp manual.
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; Code:
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
69935
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
35 (eval-when-compile (require 'cl))
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
36
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 (defun feature-symbols (feature)
47017
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
38 "Return the file and list of definitions associated with FEATURE.
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
39 The value is actually the element of `load-history'
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
40 for the file that did (provide FEATURE)."
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (catch 'foundit
29090
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
42 (mapc (lambda (x)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
43 (if (member (cons 'provide feature) (cdr x))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
44 (throw 'foundit x)))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
45 load-history)
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 nil))
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (defun feature-file (feature)
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 "Return the file name from which a given FEATURE was loaded.
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 Actually, return the load argument, if any; this is sometimes the name of a
29090
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
51 Lisp file without an extension. If the feature came from an `eval-buffer' on
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
52 a buffer with no associated file, or an `eval-region', return nil."
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (if (not (featurep feature))
29090
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
54 (error "%S is not a currently loaded feature" feature)
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (car (feature-symbols feature))))
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
59318
55722dde9e0a (file-loadhist-lookup): New function.
Richard M. Stallman <rms@gnu.org>
parents: 54000
diff changeset
57 (defun file-loadhist-lookup (file)
66285
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
58 "Return the `load-history' element for FILE.
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
59 FILE can be a file name, or a library name.
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
60 A library name is equivalent to the file name that `load-library' would load."
59318
55722dde9e0a (file-loadhist-lookup): New function.
Richard M. Stallman <rms@gnu.org>
parents: 54000
diff changeset
61 ;; First look for FILE as given.
55722dde9e0a (file-loadhist-lookup): New function.
Richard M. Stallman <rms@gnu.org>
parents: 54000
diff changeset
62 (let ((symbols (assoc file load-history)))
55722dde9e0a (file-loadhist-lookup): New function.
Richard M. Stallman <rms@gnu.org>
parents: 54000
diff changeset
63 ;; Try converting a library name to an absolute file name.
55722dde9e0a (file-loadhist-lookup): New function.
Richard M. Stallman <rms@gnu.org>
parents: 54000
diff changeset
64 (and (null symbols)
69165
cba71dc12c14 (file-loadhist-lookup): Use `get-load-suffixes' instead of `load-suffixes'.
Luc Teirlinck <teirllm@auburn.edu>
parents: 68651
diff changeset
65 (let ((absname
cba71dc12c14 (file-loadhist-lookup): Use `get-load-suffixes' instead of `load-suffixes'.
Luc Teirlinck <teirllm@auburn.edu>
parents: 68651
diff changeset
66 (locate-file file load-path (get-load-suffixes))))
66285
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
67 (and absname (not (equal absname file))
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
68 (setq symbols (cdr (assoc absname load-history))))))
59318
55722dde9e0a (file-loadhist-lookup): New function.
Richard M. Stallman <rms@gnu.org>
parents: 54000
diff changeset
69 symbols))
55722dde9e0a (file-loadhist-lookup): New function.
Richard M. Stallman <rms@gnu.org>
parents: 54000
diff changeset
70
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (defun file-provides (file)
66285
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
72 "Return the list of features provided by FILE as it was loaded.
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
73 FILE can be a file name, or a library name.
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
74 A library name is equivalent to the file name that `load-library' would load."
59318
55722dde9e0a (file-loadhist-lookup): New function.
Richard M. Stallman <rms@gnu.org>
parents: 54000
diff changeset
75 (let ((symbols (file-loadhist-lookup file))
29090
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
76 provides)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
77 (mapc (lambda (x)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
78 (if (and (consp x) (eq (car x) 'provide))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
79 (setq provides (cons (cdr x) provides))))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
80 symbols)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
81 provides))
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (defun file-requires (file)
66285
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
84 "Return the list of features required by FILE as it was loaded.
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
85 FILE can be a file name, or a library name.
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
86 A library name is equivalent to the file name that `load-library' would load."
59318
55722dde9e0a (file-loadhist-lookup): New function.
Richard M. Stallman <rms@gnu.org>
parents: 54000
diff changeset
87 (let ((symbols (file-loadhist-lookup file))
29090
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
88 requires)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
89 (mapc (lambda (x)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
90 (if (and (consp x) (eq (car x) 'require))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
91 (setq requires (cons (cdr x) requires))))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
92 symbols)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
93 requires))
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
29090
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
95 (defsubst file-set-intersect (p q)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
96 "Return the set intersection of two lists."
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (let ((ret nil))
29090
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
98 (dolist (x p ret)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
99 (if (memq x q) (setq ret (cons x ret))))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
100 ret))
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (defun file-dependents (file)
10498
8fb25f247533 (unload-feature): Don't care if FILE is a dependency of itself.
Richard M. Stallman <rms@gnu.org>
parents: 8108
diff changeset
103 "Return the list of loaded libraries that depend on FILE.
66285
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
104 This can include FILE itself.
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
105 FILE can be a file name, or a library name.
dc2f1300400b (file-loadhist-lookup): Call locate-library
Richard M. Stallman <rms@gnu.org>
parents: 64762
diff changeset
106 A library name is equivalent to the file name that `load-library' would load."
29090
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
107 (let ((provides (file-provides file))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
108 (dependents nil))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
109 (dolist (x load-history dependents)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
110 (if (file-set-intersect provides (file-requires (car x)))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
111 (setq dependents (cons (car x) dependents))))
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
112 dependents))
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
16173
9ba176963a26 (read-feature): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
114 (defun read-feature (prompt)
22459
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
115 "Read a feature name \(string\) from the minibuffer.
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
116 Prompt with PROMPT and completing from `features', and
16173
9ba176963a26 (read-feature): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
117 return the feature \(symbol\)."
9ba176963a26 (read-feature): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
118 (intern (completing-read prompt
29090
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
119 (mapcar (lambda (feature)
86d462e378ce (feature-symbols, file-provides, file-requires): Use mapc.
Dave Love <fx@gnu.org>
parents: 23852
diff changeset
120 (list (symbol-name feature)))
16173
9ba176963a26 (read-feature): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
121 features)
73722
ccbdd770cd62 (read-feature): Don't complete features not loaded from a file (which make
Juanma Barranquero <lekktu@gmail.com>
parents: 72187
diff changeset
122 ;; Complete only features loaded from a file
ccbdd770cd62 (read-feature): Don't complete features not loaded from a file (which make
Juanma Barranquero <lekktu@gmail.com>
parents: 72187
diff changeset
123 #'(lambda (f) (feature-file (intern (car f))))
ccbdd770cd62 (read-feature): Don't complete features not loaded from a file (which make
Juanma Barranquero <lekktu@gmail.com>
parents: 72187
diff changeset
124 t)))
16173
9ba176963a26 (read-feature): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
125
52755
6c7cae7ce71a (unload-feature-special-hooks):
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
126 (defvaralias 'loadhist-hook-functions 'unload-feature-special-hooks)
6c7cae7ce71a (unload-feature-special-hooks):
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
127 (defvar unload-feature-special-hooks
29346
7ac9c66520d4 (loadhist-hook-functions): Remove before-change-function,
Dave Love <fx@gnu.org>
parents: 29241
diff changeset
128 '(after-change-functions
47017
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
129 after-insert-file-functions auto-fill-function
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
130 before-change-functions blink-paren-function
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
131 buffer-access-fontify-functions command-line-functions
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
132 comment-indent-function kill-buffer-query-functions
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
133 kill-emacs-query-functions lisp-indent-function
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
134 mouse-position-function
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
135 redisplay-end-trigger-functions temp-buffer-show-function
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
136 window-scroll-functions window-size-change-functions
0ba62d75345e (unload-feature): Distinguish functions from variables in load-history.
Richard M. Stallman <rms@gnu.org>
parents: 33094
diff changeset
137 write-region-annotate-functions)
33094
51c874361c84 (unload-feature): Call elp-restore-function,
Dave Love <fx@gnu.org>
parents: 31674
diff changeset
138 "A list of special hooks from Info node `(elisp)Standard Hooks'.
22459
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
139
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
140 These are symbols with hook-type values whose names don't end in
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
141 `-hook' or `-hooks', from which `unload-feature' tries to remove
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
142 pertinent symbols.")
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
143
54000
8d106818ca97 (unload-hook-features-list): New defvar.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53998
diff changeset
144 (defvar unload-hook-features-list nil
8d106818ca97 (unload-hook-features-list): New defvar.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53998
diff changeset
145 "List of features of the package being unloaded.
8d106818ca97 (unload-hook-features-list): New defvar.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53998
diff changeset
146
8d106818ca97 (unload-hook-features-list): New defvar.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53998
diff changeset
147 This is meant to be used by FEATURE-unload-hook hooks, see the
8d106818ca97 (unload-hook-features-list): New defvar.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53998
diff changeset
148 documentation of `unload-feature' for details.")
8d106818ca97 (unload-hook-features-list): New defvar.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53998
diff changeset
149
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;;;###autoload
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (defun unload-feature (feature &optional force)
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 "Unload the library that provided FEATURE, restoring all its autoloads.
29241
a243b2d9c015 (unload-feature): Fix interactive spec [from
Dave Love <fx@gnu.org>
parents: 29090
diff changeset
153 If the feature is required by any other loaded code, and prefix arg FORCE
53998
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
154 is nil, raise an error.
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
155
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
156 This function tries to undo modifications made by the package to
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
157 hooks. Packages may define a hook FEATURE-unload-hook that is called
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
158 instead of the normal heuristics for doing this. Such a hook should
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
159 undo all the relevant global state changes that may have been made by
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
160 loading the package or executing functions in it. It has access to
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
161 the package's feature list (before anything is unbound) in the
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
162 variable `unload-hook-features-list' and could remove features from it
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
163 in the event that the package has done something normally-ill-advised,
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
164 such as redefining an Emacs function."
29241
a243b2d9c015 (unload-feature): Fix interactive spec [from
Dave Love <fx@gnu.org>
parents: 29090
diff changeset
165 (interactive (list (read-feature "Feature: ") current-prefix-arg))
61664
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
166 (unless (featurep feature)
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
167 (error "%s is not a currently loaded feature" (symbol-name feature)))
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
168 (unless force
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
169 (let* ((file (feature-file feature))
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
170 (dependents (delete file (copy-sequence (file-dependents file)))))
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
171 (when dependents
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
172 (error "Loaded libraries %s depend on %s"
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
173 (prin1-to-string dependents) file))))
53998
2e361a295c26 (unload-feature): Doc fix. Rename flist to unload-hook-features-list.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53599
diff changeset
174 (let* ((unload-hook-features-list (feature-symbols feature))
61664
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
175 (file (pop unload-hook-features-list))
75797
1c398694f7b2 (unload-feature): Handle (t . SYMBOL) entries in load history.
Richard M. Stallman <rms@gnu.org>
parents: 75687
diff changeset
176 ;; If non-nil, this is a symbol for which we should
1c398694f7b2 (unload-feature): Handle (t . SYMBOL) entries in load history.
Richard M. Stallman <rms@gnu.org>
parents: 75687
diff changeset
177 ;; restore a previous autoload if possible.
1c398694f7b2 (unload-feature): Handle (t . SYMBOL) entries in load history.
Richard M. Stallman <rms@gnu.org>
parents: 75687
diff changeset
178 restore-autoload
22459
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
179 (unload-hook (intern-soft (concat (symbol-name feature)
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
180 "-unload-hook"))))
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
181 ;; Try to avoid losing badly when hooks installed in critical
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
182 ;; places go away. (Some packages install things on
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
183 ;; `kill-buffer-hook', `activate-menubar-hook' and the like.)
53599
aa04e56e2a40 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 52755
diff changeset
184 ;; First off, provide a clean way for package FOO to arrange
aa04e56e2a40 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 52755
diff changeset
185 ;; this by adding hooks on the variable `FOO-unload-hook'.
22459
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
186 (if unload-hook
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
187 (run-hooks unload-hook)
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
188 ;; Otherwise, do our best. Look through the obarray for symbols
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
189 ;; which seem to be hook variables or special hook functions and
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
190 ;; remove anything from them which matches the feature-symbols
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
191 ;; about to get zapped. Obviously this won't get anonymous
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
192 ;; functions which the package might just have installed, and
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
193 ;; there might be other important state, but this tactic
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
194 ;; normally works.
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
195 (mapatoms
bc88a299d2fc (read-feature): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 16173
diff changeset
196 (lambda (x)
61664
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
197 (when (and (boundp x)
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
198 (or (and (consp (symbol-value x)) ; Random hooks.
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
199 (string-match "-hooks?\\'" (symbol-name x)))
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
200 (memq x unload-feature-special-hooks))) ; Known abnormal hooks etc.
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
201 (dolist (y unload-hook-features-list)
61720
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
202 (when (and (eq (car-safe y) 'defun)
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
203 (not (get (cdr y) 'autoload)))
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
204 (remove-hook x (cdr y)))))))
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
205 ;; Remove any feature-symbols from auto-mode-alist as well.
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
206 (dolist (y unload-hook-features-list)
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
207 (when (and (eq (car-safe y) 'defun)
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
208 (not (get (cdr y) 'autoload)))
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
209 (setq auto-mode-alist
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
210 (rassq-delete-all (cdr y) auto-mode-alist)))))
61664
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
211 (when (fboundp 'elp-restore-function) ; remove ELP stuff first
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
212 (dolist (elt unload-hook-features-list)
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
213 (when (symbolp elt)
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
214 (elp-restore-function elt))))
75797
1c398694f7b2 (unload-feature): Handle (t . SYMBOL) entries in load history.
Richard M. Stallman <rms@gnu.org>
parents: 75687
diff changeset
215
61664
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
216 (dolist (x unload-hook-features-list)
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
217 (if (consp x)
69935
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
218 (case (car x)
61720
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
219 ;; Remove any feature names that this file provided.
69935
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
220 (provide
61720
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
221 (setq features (delq (cdr x) features)))
75687
8cf73d911b65 (unload-feature): Silently ignore `load-history' entries of the form `(defface
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
222 ((defun autoload)
61720
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
223 (let ((fun (cdr x)))
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
224 (when (fboundp fun)
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
225 (when (fboundp 'ad-unadvise)
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
226 (ad-unadvise fun))
314c959fa176 (unload-feature): Don't remove a function from hooks if it is about to
Lute Kamstra <lute@gnu.org>
parents: 61664
diff changeset
227 (let ((aload (get fun 'autoload)))
75797
1c398694f7b2 (unload-feature): Handle (t . SYMBOL) entries in load history.
Richard M. Stallman <rms@gnu.org>
parents: 75687
diff changeset
228 (if (and aload (eq fun restore-autoload))
69935
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
229 (fset fun (cons 'autoload aload))
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
230 (fmakunbound fun))))))
75797
1c398694f7b2 (unload-feature): Handle (t . SYMBOL) entries in load history.
Richard M. Stallman <rms@gnu.org>
parents: 75687
diff changeset
231 ;; (t . SYMBOL) comes before (defun . SYMBOL)
1c398694f7b2 (unload-feature): Handle (t . SYMBOL) entries in load history.
Richard M. Stallman <rms@gnu.org>
parents: 75687
diff changeset
232 ;; and says we should restore SYMBOL's autoload
1c398694f7b2 (unload-feature): Handle (t . SYMBOL) entries in load history.
Richard M. Stallman <rms@gnu.org>
parents: 75687
diff changeset
233 ;; when we undefine it.
1c398694f7b2 (unload-feature): Handle (t . SYMBOL) entries in load history.
Richard M. Stallman <rms@gnu.org>
parents: 75687
diff changeset
234 ((t) (setq restore-autoload (cdr x)))
1c398694f7b2 (unload-feature): Handle (t . SYMBOL) entries in load history.
Richard M. Stallman <rms@gnu.org>
parents: 75687
diff changeset
235 ((require defface) nil)
72187
a17769ba1089 * loadhist.el (unload-feature): Handle new `(t . SYMBOL)' format
Chong Yidong <cyd@stupidchicken.com>
parents: 69935
diff changeset
236 (t (message "Unexpected element %s in load-history" x)))
61664
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
237 ;; Kill local values as much as possible.
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
238 (dolist (buf (buffer-list))
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
239 (with-current-buffer buf
69935
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
240 (if (and (boundp x) (timerp (symbol-value x)))
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
241 (cancel-timer (symbol-value x)))
61664
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
242 (kill-local-variable x)))
69935
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
243 (if (and (boundp x) (timerp (symbol-value x)))
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
244 (cancel-timer (symbol-value x)))
61664
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
245 ;; Get rid of the default binding if we can.
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
246 (unless (local-variable-if-set-p x)
79b58e05730b (unload-feature): Update for new format of load-history. Simplify the code.
Lute Kamstra <lute@gnu.org>
parents: 61599
diff changeset
247 (makunbound x))))
12751
f442c14a79c4 (unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents: 11844
diff changeset
248 ;; Delete the load-history element for this file.
75687
8cf73d911b65 (unload-feature): Silently ignore `load-history' entries of the form `(defface
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
249 (setq load-history (delq (assoc file load-history) load-history)))
8cf73d911b65 (unload-feature): Silently ignore `load-history' entries of the form `(defface
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
250 ;; Don't return load-history, it is not useful.
8cf73d911b65 (unload-feature): Silently ignore `load-history' entries of the form `(defface
Juanma Barranquero <lekktu@gmail.com>
parents: 75347
diff changeset
251 nil)
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (provide 'loadhist)
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254
69935
3fc0524ae318 (unload-feature): A bit of sanity check of
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69165
diff changeset
255 ;; arch-tag: 70bb846a-c413-4f01-bf88-78dba4ac0798
2543
9a1b00513968 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;;; loadhist.el ends here