]> code.delx.au - gnu-emacs/blob - lisp/cus-dep.el
#
[gnu-emacs] / lisp / cus-dep.el
1 ;;; cus-dep.el --- find customization dependencies
2 ;;
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: internal
7
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 the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30 (require 'widget)
31 (require 'cus-face)
32 (require 'autoload)
33
34 (defun custom-make-dependencies ()
35 "Batch function to extract custom dependencies from .el files.
36 Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
37 (let ((enable-local-eval nil))
38 (set-buffer (get-buffer-create " cus-dep temp"))
39 (dolist (subdir command-line-args-left)
40 (message "Directory %s" subdir)
41 (let ((files (directory-files subdir nil "\\`[^=].*\\.el\\'"))
42 (default-directory (expand-file-name subdir))
43 (preloaded (concat "\\`"
44 (regexp-opt (mapcar
45 (lambda (f)
46 (file-name-sans-extension
47 (file-name-nondirectory f)))
48 preloaded-file-list) t)
49 "\\.el\\'"))
50 is-autoloaded)
51 (dolist (file files)
52 (when (and (file-exists-p file)
53 ;; Ignore files that are preloaded.
54 (not (string-match preloaded file)))
55 (erase-buffer)
56 (insert-file-contents file)
57 (goto-char (point-min))
58 (string-match "\\`\\(.*\\)\\.el\\'" file)
59 (let ((name (file-name-nondirectory (match-string 1 file))))
60 (if (save-excursion
61 (re-search-forward
62 (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*"
63 (regexp-quote name) "[ \t\n)]")
64 nil t))
65 (setq name (intern name)))
66 (condition-case nil
67 (while (re-search-forward
68 "^(def\\(custom\\|face\\|group\\)" nil t)
69 (setq is-autoloaded nil)
70 (beginning-of-line)
71 (save-excursion
72 (forward-line -1)
73 (if (looking-at generate-autoload-cookie)
74 (setq is-autoloaded t)))
75 (let ((expr (read (current-buffer))))
76 (condition-case nil
77 (let ((custom-dont-initialize t))
78 (eval expr)
79 (put (nth 1 expr) 'custom-autoloaded is-autoloaded)
80 (put (nth 1 expr) 'custom-where name))
81 (error nil))))
82 (error nil))))))))
83 (message "Generating cus-load.el...")
84 (set-buffer (find-file-noselect "cus-load.el"))
85 (erase-buffer)
86 (insert "\
87 ;;; cus-load.el --- automatically extracted custom dependencies
88 ;;
89 ;;; Code:
90
91 ")
92 (mapatoms (lambda (symbol)
93 (let ((members (get symbol 'custom-group))
94 item where found)
95 (when members
96 ;; So x and no-x builds won't differ.
97 (setq members
98 (sort (copy-sequence members)
99 (lambda (x y) (string< (car x) (car y)))))
100 (while members
101 (setq item (car (car members))
102 members (cdr members)
103 where (get item 'custom-where))
104 (unless (or (null where)
105 (member where found))
106 (if found
107 (insert " ")
108 (insert "(put '" (symbol-name symbol)
109 " 'custom-loads '("))
110 (prin1 where (current-buffer))
111 (push where found)))
112 (when found
113 (insert "))\n"))))))
114 (insert "\
115 ;;; These are for handling :version. We need to have a minimum of
116 ;;; information so `custom-changed-variables' could do its job.
117 ;;; For both groups and variables we have to set `custom-version'.
118 ;;; For variables we also set the `standard-value' and for groups
119 ;;; `group-documentation' (which is shown in the customize buffer), so
120 ;;; we don't have to load the file containing the group.
121
122 ;;; `custom-versions-load-alist' is an alist that has as car a version
123 ;;; number and as elts the files that have variables that contain that
124 ;;; version. These files should be loaded before showing the
125 ;;; customization buffer that `customize-changed-options' generates.
126
127
128 ;;; This macro is used so we don't modify the information about
129 ;;; variables and groups if it's already set. (We don't know when
130 ;;; cus-load.el is going to be loaded and at that time some of the
131 ;;; files might be loaded and some others might not).
132 \(defmacro custom-put-if-not (symbol propname value)
133 `(unless (get ,symbol ,propname)
134 (put ,symbol ,propname ,value)))
135
136 ")
137 (let ((version-alist nil))
138 (mapatoms (lambda (symbol)
139 (let ((version (get symbol 'custom-version))
140 where)
141 (when version
142 (setq where (get symbol 'custom-where))
143 (when (and where
144 ;; Don't bother to do anything if it's
145 ;; autoloaded because we will have all
146 ;; this info when emacs is running
147 ;; anyway.
148 (not (get symbol 'custom-autoloaded)))
149 (insert "(custom-put-if-not '" (symbol-name symbol)
150 " 'custom-version ")
151 (prin1 version (current-buffer))
152 (insert ")\n")
153 (insert "(custom-put-if-not '" (symbol-name symbol))
154 (if (get symbol 'standard-value)
155 ;; This means it's a variable
156 (progn
157 (insert " 'standard-value t)\n")
158 (if (assoc version version-alist)
159 (unless
160 (member where
161 (cdr (assoc version version-alist)))
162 (push where (cdr (assoc version version-alist))))
163 (push (cons version (list where)) version-alist)))
164 ;; This is a group
165 (insert " 'group-documentation ")
166 (prin1 (get symbol 'group-documentation) (current-buffer))
167 (insert ")\n")))))))
168
169 (insert "\n(defvar custom-versions-load-alist "
170 (if version-alist "'" ""))
171 (prin1 version-alist (current-buffer))
172 (insert "\n \"For internal use by custom.\")\n"))
173
174 (insert "\
175
176 \(provide 'cus-load)
177
178 ;;; Local Variables:
179 ;;; version-control: never
180 ;;; no-byte-compile: t
181 ;;; no-update-autoloads: t
182 ;;; End:
183 ;;; cus-load.el ends here\n")
184 (let ((kept-new-versions 10000000))
185 (save-buffer))
186 (message "Generating cus-load.el...done")
187 (kill-emacs))
188
189 \f
190 ;;; cus-dep.el ends here