Mercurial > emacs
annotate lisp/loadhist.el @ 13078:d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Don't create local vars here. Set view-mode-auto-exit.
Don't change local map--just set view-mode.
(view-mode): New function toggles minor mode in the usual way.
(view-mode-map): Put this on minor-mode-map-alist.
(view-mode-exit): Do the exit actions only if view-mode-auto-exit.
(View-scroll-lines-forward): Exit only if view-scroll-lines-forward.
(view-mode-auto-exit, view-old-buffer-read-only)
(view-old-Helper-return-blurb, view-scroll-size, view-last-regexp)
(view-exit-action, view-return-here, view-exit-position):
Defvar them and make them always-local.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 25 Sep 1995 18:36:32 +0000 |
parents | f442c14a79c4 |
children | 83f275dcd93a |
rev | line source |
---|---|
2543 | 1 ;;; loadhist.el --- lisp functions for working with feature groups |
11289 | 2 ;;; Copyright (C) 1995 Free Software Foundation, Inc. |
2543 | 3 |
4 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> | |
5 ;; Version: 1.0 | |
6 ;; Keywords: internal | |
7 | |
11289 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
2543 | 24 ;;; Commentary: |
25 | |
26 ;; These functions exploit the load-history system variable. | |
27 ;; Entry points include `unload-feature', `symbol-file', and `feature-file'. | |
28 | |
29 ;;; Code: | |
30 | |
31 (defun symbol-file (sym) | |
32 "Return the input source from which SYM was loaded. | |
33 This is a file name, or nil if the source was a buffer with no associated file." | |
34 (catch 'foundit | |
35 (mapcar | |
36 (function (lambda (x) (if (memq sym (cdr x)) (throw 'foundit (car x))))) | |
37 load-history) | |
38 nil)) | |
39 | |
40 (defun feature-symbols (feature) | |
41 "Return the file and list of symbols associated with a given FEATURE." | |
42 (catch 'foundit | |
43 (mapcar | |
44 (function (lambda (x) | |
45 (if (member (cons 'provide feature) (cdr x)) | |
46 (throw 'foundit x)))) | |
47 load-history) | |
48 nil)) | |
49 | |
50 (defun feature-file (feature) | |
51 "Return the file name from which a given FEATURE was loaded. | |
52 Actually, return the load argument, if any; this is sometimes the name of a | |
53 Lisp file without an extension. If the feature came from an eval-buffer on | |
54 a buffer with no associated file, or an eval-region, return nil." | |
55 (if (not (featurep feature)) | |
12751
f442c14a79c4
(unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents:
11844
diff
changeset
|
56 (error "%s is not a currently loaded feature" (symbol-name feature)) |
2543 | 57 (car (feature-symbols feature)))) |
58 | |
59 (defun file-provides (file) | |
60 "Return the list of features provided by FILE." | |
61 (let ((symbols (cdr (assoc file load-history))) (provides nil)) | |
62 (mapcar | |
63 (function (lambda (x) | |
64 (if (and (consp x) (eq (car x) 'provide)) | |
65 (setq provides (cons (cdr x) provides))))) | |
66 symbols) | |
67 provides | |
68 )) | |
69 | |
70 (defun file-requires (file) | |
71 "Return the list of features required by FILE." | |
72 (let ((symbols (cdr (assoc file load-history))) (requires nil)) | |
73 (mapcar | |
74 (function (lambda (x) | |
75 (if (and (consp x) (eq (car x) 'require)) | |
76 (setq requires (cons (cdr x) requires))))) | |
77 symbols) | |
78 requires | |
79 )) | |
80 | |
12751
f442c14a79c4
(unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents:
11844
diff
changeset
|
81 (defun file-set-intersect (p q) |
2543 | 82 ;; Return the set intersection of two lists |
83 (let ((ret nil)) | |
84 (mapcar | |
85 (function (lambda (x) (if (memq x q) (setq ret (cons x ret))))) | |
86 p) | |
87 ret | |
88 )) | |
89 | |
90 (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
|
91 "Return the list of loaded libraries that depend on FILE. |
8fb25f247533
(unload-feature): Don't care if FILE is a dependency of itself.
Richard M. Stallman <rms@gnu.org>
parents:
8108
diff
changeset
|
92 This can include FILE itself." |
2543 | 93 (let ((provides (file-provides file)) (dependents nil)) |
94 (mapcar | |
95 (function (lambda (x) | |
12751
f442c14a79c4
(unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents:
11844
diff
changeset
|
96 (if (file-set-intersect provides (file-requires (car x))) |
2543 | 97 (setq dependents (cons (car x) dependents))))) |
98 load-history) | |
99 dependents | |
100 )) | |
101 | |
102 ;;;###autoload | |
103 (defun unload-feature (feature &optional force) | |
104 "Unload the library that provided FEATURE, restoring all its autoloads. | |
105 If the feature is required by any other loaded code, and optional FORCE | |
106 is nil, raise an error." | |
107 (interactive "SFeature: ") | |
108 (if (not (featurep feature)) | |
12751
f442c14a79c4
(unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents:
11844
diff
changeset
|
109 (error "%s is not a currently loaded feature" (symbol-name feature))) |
2543 | 110 (if (not force) |
10498
8fb25f247533
(unload-feature): Don't care if FILE is a dependency of itself.
Richard M. Stallman <rms@gnu.org>
parents:
8108
diff
changeset
|
111 (let* ((file (feature-file feature)) |
8fb25f247533
(unload-feature): Don't care if FILE is a dependency of itself.
Richard M. Stallman <rms@gnu.org>
parents:
8108
diff
changeset
|
112 (dependents (delete file (copy-sequence (file-dependents file))))) |
2543 | 113 (if dependents |
12751
f442c14a79c4
(unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents:
11844
diff
changeset
|
114 (error "Loaded libraries %s depend on %s" |
2543 | 115 (prin1-to-string dependents) file) |
116 ))) | |
117 (let* ((flist (feature-symbols feature)) (file (car flist))) | |
118 (mapcar | |
119 (function (lambda (x) | |
120 (cond ((stringp x) nil) | |
11844
cacb7820d1c7
(unload-feature): When we come to (provide . FEATURE),
Karl Heuer <kwzh@gnu.org>
parents:
11289
diff
changeset
|
121 ((consp x) |
cacb7820d1c7
(unload-feature): When we come to (provide . FEATURE),
Karl Heuer <kwzh@gnu.org>
parents:
11289
diff
changeset
|
122 ;; Remove any feature names that this file provided. |
cacb7820d1c7
(unload-feature): When we come to (provide . FEATURE),
Karl Heuer <kwzh@gnu.org>
parents:
11289
diff
changeset
|
123 (if (eq (car x) 'provide) |
cacb7820d1c7
(unload-feature): When we come to (provide . FEATURE),
Karl Heuer <kwzh@gnu.org>
parents:
11289
diff
changeset
|
124 (setq features (delq (cdr x) features)))) |
2543 | 125 ((boundp x) (makunbound x)) |
126 ((fboundp x) | |
127 (fmakunbound x) | |
128 (let ((aload (get x 'autoload))) | |
12751
f442c14a79c4
(unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents:
11844
diff
changeset
|
129 (if aload (fset x (cons 'autoload aload)))))))) |
f442c14a79c4
(unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents:
11844
diff
changeset
|
130 (cdr flist)) |
f442c14a79c4
(unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents:
11844
diff
changeset
|
131 ;; Delete the load-history element for this file. |
f442c14a79c4
(unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents:
11844
diff
changeset
|
132 (let ((elt (assoc file load-history))) |
f442c14a79c4
(unload-feature): Delete the file's load-history element.
Richard M. Stallman <rms@gnu.org>
parents:
11844
diff
changeset
|
133 (setq load-history (delq elt load-history))))) |
2543 | 134 |
135 (provide 'loadhist) | |
136 | |
137 ;;; loadhist.el ends here |