(url-file-name-completion): Add missing argument.
[bpt/emacs.git] / lisp / cus-dep.el
CommitLineData
e8af40ee 1;;; cus-dep.el --- find customization dependencies
860af8ec 2;;
e91081eb 3;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005,
409cc4a3 4;; 2006, 2007, 2008 Free Software Foundation, Inc.
860af8ec
PA
5;;
6;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7;; Keywords: internal
8
c2383d2d
RS
9;; This file is part of GNU Emacs.
10
eb3fa2cf 11;; GNU Emacs is free software: you can redistribute it and/or modify
c2383d2d 12;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
c2383d2d
RS
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
eb3fa2cf 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
c2383d2d 23
e8af40ee
PJ
24;;; Commentary:
25
860af8ec
PA
26;;; Code:
27
79c70818 28(eval-when-compile (require 'cl))
c9aadf03
RS
29(require 'widget)
30(require 'cus-face)
860af8ec 31
b1d7940f 32(defvar generated-custom-dependencies-file "cus-load.el"
6cc803de 33 "Output file for \\[custom-make-dependencies].")
b1d7940f 34
860af8ec
PA
35(defun custom-make-dependencies ()
36 "Batch function to extract custom dependencies from .el files.
efbdca12 37Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
5188f2eb
SM
38 (let ((enable-local-eval nil))
39 (set-buffer (get-buffer-create " cus-dep temp"))
40 (dolist (subdir command-line-args-left)
41 (message "Directory %s" subdir)
42 (let ((files (directory-files subdir nil "\\`[^=].*\\.el\\'"))
43 (default-directory (expand-file-name subdir))
a9338083
SM
44 (preloaded (concat "\\`"
45 (regexp-opt (mapcar
46 (lambda (f)
47 (file-name-sans-extension
48 (file-name-nondirectory f)))
49 preloaded-file-list) t)
052b7009 50 "\\.el\\'")))
5188f2eb 51 (dolist (file files)
a9338083
SM
52 (when (and (file-exists-p file)
53 ;; Ignore files that are preloaded.
54 (not (string-match preloaded file)))
efbdca12
RS
55 (erase-buffer)
56 (insert-file-contents file)
57 (goto-char (point-min))
58 (string-match "\\`\\(.*\\)\\.el\\'" file)
f954e891
MR
59 (let ((name (file-name-nondirectory (match-string 1 file)))
60 (load-file-name file))
5188f2eb
SM
61 (if (save-excursion
62 (re-search-forward
63 (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*"
64 (regexp-quote name) "[ \t\n)]")
65 nil t))
66 (setq name (intern name)))
efbdca12 67 (condition-case nil
5188f2eb
SM
68 (while (re-search-forward
69 "^(def\\(custom\\|face\\|group\\)" nil t)
efbdca12
RS
70 (beginning-of-line)
71 (let ((expr (read (current-buffer))))
06beea21 72 (condition-case nil
4e189812 73 (let ((custom-dont-initialize t))
06beea21
RS
74 (eval expr)
75 (put (nth 1 expr) 'custom-where name))
76 (error nil))))
5188f2eb 77 (error nil))))))))
b1d7940f
AS
78 (message "Generating %s..." generated-custom-dependencies-file)
79 (set-buffer (find-file-noselect generated-custom-dependencies-file))
860af8ec 80 (erase-buffer)
e2dc1f61 81 (insert ";;; " (file-name-nondirectory generated-custom-dependencies-file)
b1d7940f 82 " --- automatically extracted custom dependencies
e2dc1f61 83;;\n;;; Code:
a3edd195 84
860af8ec
PA
85")
86 (mapatoms (lambda (symbol)
87 (let ((members (get symbol 'custom-group))
e2dc1f61 88 where found)
860af8ec 89 (when members
e2dc1f61
SM
90 (dolist (member
91 ;; So x and no-x builds won't differ.
92 (sort (mapcar 'car members) 'string<))
93 (setq where (get member 'custom-where))
860af8ec
PA
94 (unless (or (null where)
95 (member where found))
860af8ec 96 (push where found)))
a9d3a78b 97 (when found
e2dc1f61
SM
98 (insert "(put '" (symbol-name symbol)
99 " 'custom-loads '")
882108c7 100 (prin1 (nreverse found) (current-buffer))
1c32c9d6 101 (insert ")\n"))))))
8cd58e14 102 (insert "\
e2dc1f61
SM
103;; These are for handling :version. We need to have a minimum of
104;; information so `customize-changed-options' could do its job.
105
106;; For groups we set `custom-version', `group-documentation' and
107;; `custom-tag' (which are shown in the customize buffer), so we
108;; don't have to load the file containing the group.
109
110;; `custom-versions-load-alist' is an alist that has as car a version
111;; number and as elts the files that have variables or faces that
112;; contain that version. These files should be loaded before showing
113;; the customization buffer that `customize-changed-options'
114;; generates.
115
116;; This macro is used so we don't modify the information about
117;; variables and groups if it's already set. (We don't know when
118;; " (file-name-nondirectory generated-custom-dependencies-file)
b1d7940f 119 " is going to be loaded and at that time some of the
e2dc1f61 120;; files might be loaded and some others might not).
a313af11 121\(defmacro custom-put-if-not (symbol propname value)
1e484d64
DN
122 `(unless (get ,symbol ,propname)
123 (put ,symbol ,propname ,value)))
124
125")
126 (let ((version-alist nil))
127 (mapatoms (lambda (symbol)
128 (let ((version (get symbol 'custom-version))
129 where)
71296446 130 (when version
1e484d64 131 (setq where (get symbol 'custom-where))
052b7009 132 (when where
d5680815
MR
133 (if (or (custom-variable-p symbol)
134 (custom-facep symbol))
135 ;; This means it's a variable or a face.
1e484d64 136 (progn
1e484d64 137 (if (assoc version version-alist)
71296446
JB
138 (unless
139 (member where
1e484d64
DN
140 (cdr (assoc version version-alist)))
141 (push where (cdr (assoc version version-alist))))
526af3b0 142 (push (list version where) version-alist)))
1e484d64 143 ;; This is a group
71296446 144 (insert "(custom-put-if-not '" (symbol-name symbol)
d5680815
MR
145 " 'custom-version ")
146 (prin1 version (current-buffer))
147 (insert ")\n")
148 (insert "(custom-put-if-not '" (symbol-name symbol))
1e484d64
DN
149 (insert " 'group-documentation ")
150 (prin1 (get symbol 'group-documentation) (current-buffer))
d5680815
MR
151 (insert ")\n")
152 (when (get symbol 'custom-tag)
153 (insert "(custom-put-if-not '" (symbol-name symbol))
154 (insert " 'custom-tag ")
155 (prin1 (get symbol 'custom-tag) (current-buffer))
156 (insert ")\n"))
157 ))))))
1e484d64
DN
158
159 (insert "\n(defvar custom-versions-load-alist "
160 (if version-alist "'" ""))
161 (prin1 version-alist (current-buffer))
162 (insert "\n \"For internal use by custom.\")\n"))
71296446 163
1e484d64 164 (insert "\
8cd58e14 165
b1d7940f
AS
166\(provide '" (file-name-sans-extension
167 (file-name-nondirectory generated-custom-dependencies-file)) ")
8cd58e14 168
e2dc1f61
SM
169;; Local Variables:
170;; version-control: never
171;; no-byte-compile: t
172;; no-update-autoloads: t
173;; End:\n;;; "
174 (file-name-nondirectory generated-custom-dependencies-file)
175 " ends here\n")
c9aadf03
RS
176 (let ((kept-new-versions 10000000))
177 (save-buffer))
b1d7940f 178 (message "Generating %s...done" generated-custom-dependencies-file)
efbdca12 179 (kill-emacs))
860af8ec 180
6a7ceddc 181\f
ab5796a9 182
e2dc1f61 183;; arch-tag: b7b6421a-bf7a-44fd-a382-6f44976bdf68
860af8ec 184;;; cus-dep.el ends here