Mercurial > emacs
comparison lisp/loadhist.el @ 85370:2ad51c213e7d
(feature-symbols, file-provides, file-requires, file-set-intersect,
file-dependents): Simplify.
(unload-feature-special-hooks): Update list of special hooks.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Wed, 17 Oct 2007 23:03:55 +0000 |
parents | e8d941fbbe78 |
children | cb2dd077ba75 1251cabc40b7 |
comparison
equal
deleted
inserted
replaced
85369:5b96a46cc08a | 85370:2ad51c213e7d |
---|---|
36 | 36 |
37 (defun feature-symbols (feature) | 37 (defun feature-symbols (feature) |
38 "Return the file and list of definitions associated with FEATURE. | 38 "Return the file and list of definitions associated with FEATURE. |
39 The value is actually the element of `load-history' | 39 The value is actually the element of `load-history' |
40 for the file that did (provide FEATURE)." | 40 for the file that did (provide FEATURE)." |
41 (catch 'foundit | 41 (catch 'foundit |
42 (mapc (lambda (x) | 42 (let ((element (cons 'provide feature))) |
43 (if (member (cons 'provide feature) (cdr x)) | 43 (dolist (x load-history nil) |
44 (throw 'foundit x))) | 44 (when (member element (cdr x)) |
45 load-history) | 45 (throw 'foundit x)))))) |
46 nil)) | |
47 | 46 |
48 (defun feature-file (feature) | 47 (defun feature-file (feature) |
49 "Return the file name from which a given FEATURE was loaded. | 48 "Return the file name from which a given FEATURE was loaded. |
50 Actually, return the load argument, if any; this is sometimes the name of a | 49 Actually, return the load argument, if any; this is sometimes the name of a |
51 Lisp file without an extension. If the feature came from an `eval-buffer' on | 50 Lisp file without an extension. If the feature came from an `eval-buffer' on |
70 | 69 |
71 (defun file-provides (file) | 70 (defun file-provides (file) |
72 "Return the list of features provided by FILE as it was loaded. | 71 "Return the list of features provided by FILE as it was loaded. |
73 FILE can be a file name, or a library name. | 72 FILE can be a file name, or a library name. |
74 A library name is equivalent to the file name that `load-library' would load." | 73 A library name is equivalent to the file name that `load-library' would load." |
75 (let ((symbols (file-loadhist-lookup file)) | 74 (let (provides) |
76 provides) | 75 (dolist (x (file-loadhist-lookup file) provides) |
77 (mapc (lambda (x) | 76 (when (eq (car-safe x) 'provide) |
78 (if (and (consp x) (eq (car x) 'provide)) | 77 (push x provides))))) |
79 (setq provides (cons (cdr x) provides)))) | |
80 symbols) | |
81 provides)) | |
82 | 78 |
83 (defun file-requires (file) | 79 (defun file-requires (file) |
84 "Return the list of features required by FILE as it was loaded. | 80 "Return the list of features required by FILE as it was loaded. |
85 FILE can be a file name, or a library name. | 81 FILE can be a file name, or a library name. |
86 A library name is equivalent to the file name that `load-library' would load." | 82 A library name is equivalent to the file name that `load-library' would load." |
87 (let ((symbols (file-loadhist-lookup file)) | 83 (let (requires) |
88 requires) | 84 (dolist (x (file-loadhist-lookup file) requires) |
89 (mapc (lambda (x) | 85 (when (eq (car-safe x) 'require) |
90 (if (and (consp x) (eq (car x) 'require)) | 86 (push x requires))))) |
91 (setq requires (cons (cdr x) requires)))) | |
92 symbols) | |
93 requires)) | |
94 | 87 |
95 (defsubst file-set-intersect (p q) | 88 (defsubst file-set-intersect (p q) |
96 "Return the set intersection of two lists." | 89 "Return the set intersection of two lists." |
97 (let ((ret nil)) | 90 (let (ret) |
98 (dolist (x p ret) | 91 (dolist (x p ret) |
99 (if (memq x q) (setq ret (cons x ret)))) | 92 (when (memq x q) (push x ret))))) |
100 ret)) | |
101 | 93 |
102 (defun file-dependents (file) | 94 (defun file-dependents (file) |
103 "Return the list of loaded libraries that depend on FILE. | 95 "Return the list of loaded libraries that depend on FILE. |
104 This can include FILE itself. | 96 This can include FILE itself. |
105 FILE can be a file name, or a library name. | 97 FILE can be a file name, or a library name. |
106 A library name is equivalent to the file name that `load-library' would load." | 98 A library name is equivalent to the file name that `load-library' would load." |
107 (let ((provides (file-provides file)) | 99 (let ((provides (file-provides file)) |
108 (dependents nil)) | 100 (dependents nil)) |
109 (dolist (x load-history dependents) | 101 (dolist (x load-history dependents) |
110 (if (file-set-intersect provides (file-requires (car x))) | 102 (when (file-set-intersect provides (file-requires (car x))) |
111 (setq dependents (cons (car x) dependents)))) | 103 (push (car x) dependents))))) |
112 dependents)) | |
113 | 104 |
114 (defun read-feature (prompt &optional loaded-p) | 105 (defun read-feature (prompt &optional loaded-p) |
115 "Read feature name from the minibuffer, prompting with string PROMPT. | 106 "Read feature name from the minibuffer, prompting with string PROMPT. |
116 If optional second arg LOADED-P is non-nil, the feature must be loaded | 107 If optional second arg LOADED-P is non-nil, the feature must be loaded |
117 from a file." | 108 from a file." |
124 (feature-file f)))) | 115 (feature-file f)))) |
125 loaded-p))) | 116 loaded-p))) |
126 | 117 |
127 (defvaralias 'loadhist-hook-functions 'unload-feature-special-hooks) | 118 (defvaralias 'loadhist-hook-functions 'unload-feature-special-hooks) |
128 (defvar unload-feature-special-hooks | 119 (defvar unload-feature-special-hooks |
129 '(after-change-functions | 120 '(after-change-functions after-insert-file-functions |
130 after-insert-file-functions auto-fill-function | 121 after-make-frame-functions auto-fill-function before-change-functions |
131 before-change-functions blink-paren-function | 122 blink-paren-function buffer-access-fontify-functions command-line-functions |
132 buffer-access-fontify-functions command-line-functions | 123 comment-indent-function compilation-finish-functions |
133 comment-indent-function kill-buffer-query-functions | 124 disabled-command-function find-file-not-found-functions |
134 kill-emacs-query-functions lisp-indent-function | 125 font-lock-beginning-of-syntax-function font-lock-fontify-buffer-function |
135 mouse-position-function | 126 font-lock-fontify-region-function font-lock-mark-block-function |
127 font-lock-syntactic-face-function font-lock-unfontify-buffer-function | |
128 font-lock-unfontify-region-function kill-buffer-query-functions | |
129 kill-emacs-query-functions lisp-indent-function mouse-position-function | |
136 redisplay-end-trigger-functions temp-buffer-show-function | 130 redisplay-end-trigger-functions temp-buffer-show-function |
137 window-scroll-functions window-size-change-functions | 131 window-scroll-functions window-size-change-functions |
132 write-contents-functions write-file-functions | |
138 write-region-annotate-functions) | 133 write-region-annotate-functions) |
139 "A list of special hooks from Info node `(elisp)Standard Hooks'. | 134 "A list of special hooks from Info node `(elisp)Standard Hooks'. |
140 | 135 |
141 These are symbols with hook-type values whose names don't end in | 136 These are symbols with hook-type values whose names don't end in |
142 `-hook' or `-hooks', from which `unload-feature' tries to remove | 137 `-hook' or `-hooks', from which `unload-feature' tries to remove |