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