Add arch taglines
[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)
860af8ec 32
b1d7940f
AS
33(defvar generated-custom-dependencies-file "cus-load.el"
34 "File \\[cusom-make-dependencies] puts custom dependencies into.")
35
860af8ec
PA
36(defun custom-make-dependencies ()
37 "Batch function to extract custom dependencies from .el files.
efbdca12 38Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
5188f2eb
SM
39 (let ((enable-local-eval nil))
40 (set-buffer (get-buffer-create " cus-dep temp"))
41 (dolist (subdir command-line-args-left)
42 (message "Directory %s" subdir)
43 (let ((files (directory-files subdir nil "\\`[^=].*\\.el\\'"))
44 (default-directory (expand-file-name subdir))
a9338083
SM
45 (preloaded (concat "\\`"
46 (regexp-opt (mapcar
47 (lambda (f)
48 (file-name-sans-extension
49 (file-name-nondirectory f)))
50 preloaded-file-list) t)
052b7009 51 "\\.el\\'")))
5188f2eb 52 (dolist (file files)
a9338083
SM
53 (when (and (file-exists-p file)
54 ;; Ignore files that are preloaded.
55 (not (string-match preloaded file)))
efbdca12
RS
56 (erase-buffer)
57 (insert-file-contents file)
58 (goto-char (point-min))
59 (string-match "\\`\\(.*\\)\\.el\\'" file)
f954e891
MR
60 (let ((name (file-name-nondirectory (match-string 1 file)))
61 (load-file-name file))
5188f2eb
SM
62 (if (save-excursion
63 (re-search-forward
64 (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*"
65 (regexp-quote name) "[ \t\n)]")
66 nil t))
67 (setq name (intern name)))
efbdca12 68 (condition-case nil
5188f2eb
SM
69 (while (re-search-forward
70 "^(def\\(custom\\|face\\|group\\)" nil t)
efbdca12
RS
71 (beginning-of-line)
72 (let ((expr (read (current-buffer))))
06beea21 73 (condition-case nil
4e189812 74 (let ((custom-dont-initialize t))
06beea21
RS
75 (eval expr)
76 (put (nth 1 expr) 'custom-where name))
77 (error nil))))
5188f2eb 78 (error nil))))))))
b1d7940f
AS
79 (message "Generating %s..." generated-custom-dependencies-file)
80 (set-buffer (find-file-noselect generated-custom-dependencies-file))
860af8ec
PA
81 (erase-buffer)
82 (insert "\
b1d7940f
AS
83;;; " (file-name-nondirectory generated-custom-dependencies-file)
84 " --- automatically extracted custom dependencies
860af8ec
PA
85;;
86;;; Code:
a3edd195 87
860af8ec
PA
88")
89 (mapatoms (lambda (symbol)
90 (let ((members (get symbol 'custom-group))
91 item where found)
92 (when members
8eb52503 93 ;; So x and no-x builds won't differ.
4986d1f1 94 (setq members
71296446 95 (sort (copy-sequence members)
2912113b 96 (lambda (x y) (string< (car x) (car y)))))
860af8ec
PA
97 (while members
98 (setq item (car (car members))
99 members (cdr members)
100 where (get item 'custom-where))
101 (unless (or (null where)
102 (member where found))
103 (if found
104 (insert " ")
71296446 105 (insert "(put '" (symbol-name symbol)
860af8ec 106 " 'custom-loads '("))
a9d3a78b 107 (prin1 where (current-buffer))
860af8ec 108 (push where found)))
a9d3a78b
PA
109 (when found
110 (insert "))\n"))))))
8cd58e14 111 (insert "\
1e484d64 112;;; These are for handling :version. We need to have a minimum of
71296446 113;;; information so `customize-changed-options' could do its job.
1e484d64 114
dfc85ff2
MR
115;;; For groups we set `custom-version', `group-documentation' and
116;;; `custom-tag' (which are shown in the customize buffer), so we
117;;; don't have to load the file containing the group.
1e484d64 118
dfc85ff2
MR
119;;; `custom-versions-load-alist' is an alist that has as car a version
120;;; number and as elts the files that have variables or faces that
121;;; contain that version. These files should be loaded before showing
122;;; the customization buffer that `customize-changed-options'
123;;; generates.
1e484d64
DN
124
125;;; This macro is used so we don't modify the information about
126;;; variables and groups if it's already set. (We don't know when
b1d7940f
AS
127;;; " (file-name-nondirectory generated-custom-dependencies-file)
128 " is going to be loaded and at that time some of the
1e484d64 129;;; files might be loaded and some others might not).
a313af11 130\(defmacro custom-put-if-not (symbol propname value)
1e484d64
DN
131 `(unless (get ,symbol ,propname)
132 (put ,symbol ,propname ,value)))
133
134")
135 (let ((version-alist nil))
136 (mapatoms (lambda (symbol)
137 (let ((version (get symbol 'custom-version))
138 where)
71296446 139 (when version
1e484d64 140 (setq where (get symbol 'custom-where))
052b7009 141 (when where
d5680815
MR
142 (if (or (custom-variable-p symbol)
143 (custom-facep symbol))
144 ;; This means it's a variable or a face.
1e484d64 145 (progn
1e484d64 146 (if (assoc version version-alist)
71296446
JB
147 (unless
148 (member where
1e484d64
DN
149 (cdr (assoc version version-alist)))
150 (push where (cdr (assoc version version-alist))))
151 (push (cons version (list where)) version-alist)))
152 ;; This is a group
71296446 153 (insert "(custom-put-if-not '" (symbol-name symbol)
d5680815
MR
154 " 'custom-version ")
155 (prin1 version (current-buffer))
156 (insert ")\n")
157 (insert "(custom-put-if-not '" (symbol-name symbol))
1e484d64
DN
158 (insert " 'group-documentation ")
159 (prin1 (get symbol 'group-documentation) (current-buffer))
d5680815
MR
160 (insert ")\n")
161 (when (get symbol 'custom-tag)
162 (insert "(custom-put-if-not '" (symbol-name symbol))
163 (insert " 'custom-tag ")
164 (prin1 (get symbol 'custom-tag) (current-buffer))
165 (insert ")\n"))
166 ))))))
1e484d64
DN
167
168 (insert "\n(defvar custom-versions-load-alist "
169 (if version-alist "'" ""))
170 (prin1 version-alist (current-buffer))
171 (insert "\n \"For internal use by custom.\")\n"))
71296446 172
1e484d64 173 (insert "\
8cd58e14 174
b1d7940f
AS
175\(provide '" (file-name-sans-extension
176 (file-name-nondirectory generated-custom-dependencies-file)) ")
8cd58e14 177
6a7ceddc
SM
178;;; Local Variables:
179;;; version-control: never
180;;; no-byte-compile: t
181;;; no-update-autoloads: t
182;;; End:
b1d7940f 183;;; " (file-name-nondirectory generated-custom-dependencies-file) " ends here\n")
c9aadf03
RS
184 (let ((kept-new-versions 10000000))
185 (save-buffer))
b1d7940f 186 (message "Generating %s...done" generated-custom-dependencies-file)
efbdca12 187 (kill-emacs))
860af8ec 188
6a7ceddc 189\f
ab5796a9
MB
190
191;;; arch-tag: b7b6421a-bf7a-44fd-a382-6f44976bdf68
860af8ec 192;;; cus-dep.el ends here