1 ;;; cus-dep.el --- find customization dependencies
3 ;; Copyright (C) 1997, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; This file is part of GNU Emacs.
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)
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.
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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
29 (eval-when-compile (require 'cl
))
33 (defvar generated-custom-dependencies-file
"cus-load.el"
34 "File \\[cusom-make-dependencies] puts custom dependencies into.")
36 (defun custom-make-dependencies ()
37 "Batch function to extract custom dependencies from .el files.
38 Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
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
))
45 (preloaded (concat "\\`"
48 (file-name-sans-extension
49 (file-name-nondirectory f
)))
50 preloaded-file-list
) t
)
53 (when (and (file-exists-p file
)
54 ;; Ignore files that are preloaded.
55 (not (string-match preloaded file
)))
57 (insert-file-contents file
)
58 (goto-char (point-min))
59 (string-match "\\`\\(.*\\)\\.el\\'" file
)
60 (let ((name (file-name-nondirectory (match-string 1 file
)))
61 (load-file-name file
))
64 (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*"
65 (regexp-quote name
) "[ \t\n)]")
67 (setq name
(intern name
)))
69 (while (re-search-forward
70 "^(def\\(custom\\|face\\|group\\)" nil t
)
72 (let ((expr (read (current-buffer))))
74 (let ((custom-dont-initialize t
))
76 (put (nth 1 expr
) 'custom-where name
))
79 (message "Generating %s..." generated-custom-dependencies-file
)
80 (set-buffer (find-file-noselect generated-custom-dependencies-file
))
82 (insert ";;; " (file-name-nondirectory generated-custom-dependencies-file
)
83 " --- automatically extracted custom dependencies
87 (mapatoms (lambda (symbol)
88 (let ((members (get symbol
'custom-group
))
92 ;; So x and no-x builds won't differ.
93 (sort (mapcar 'car members
) 'string
<))
94 (setq where
(get member
'custom-where
))
95 (unless (or (null where
)
99 (insert "(put '" (symbol-name symbol
)
101 (prin1 (nreverse found
) (current-buffer))
104 ;; These are for handling :version. We need to have a minimum of
105 ;; information so `customize-changed-options' could do its job.
107 ;; For groups we set `custom-version', `group-documentation' and
108 ;; `custom-tag' (which are shown in the customize buffer), so we
109 ;; don't have to load the file containing the group.
111 ;; `custom-versions-load-alist' is an alist that has as car a version
112 ;; number and as elts the files that have variables or faces that
113 ;; contain that version. These files should be loaded before showing
114 ;; the customization buffer that `customize-changed-options'
117 ;; This macro is used so we don't modify the information about
118 ;; variables and groups if it's already set. (We don't know when
119 ;; " (file-name-nondirectory generated-custom-dependencies-file
)
120 " is going to be loaded and at that time some of the
121 ;; files might be loaded and some others might not).
122 \(defmacro custom-put-if-not (symbol propname value)
123 `(unless (get ,symbol ,propname)
124 (put ,symbol ,propname ,value)))
127 (let ((version-alist nil
))
128 (mapatoms (lambda (symbol)
129 (let ((version (get symbol
'custom-version
))
132 (setq where
(get symbol
'custom-where
))
134 (if (or (custom-variable-p symbol
)
135 (custom-facep symbol
))
136 ;; This means it's a variable or a face.
138 (if (assoc version version-alist
)
141 (cdr (assoc version version-alist
)))
142 (push where
(cdr (assoc version version-alist
))))
143 (push (cons version
(list where
)) version-alist
)))
145 (insert "(custom-put-if-not '" (symbol-name symbol
)
147 (prin1 version
(current-buffer))
149 (insert "(custom-put-if-not '" (symbol-name symbol
))
150 (insert " 'group-documentation ")
151 (prin1 (get symbol
'group-documentation
) (current-buffer))
153 (when (get symbol
'custom-tag
)
154 (insert "(custom-put-if-not '" (symbol-name symbol
))
155 (insert " 'custom-tag ")
156 (prin1 (get symbol
'custom-tag
) (current-buffer))
160 (insert "\n(defvar custom-versions-load-alist "
161 (if version-alist
"'" ""))
162 (prin1 version-alist
(current-buffer))
163 (insert "\n \"For internal use by custom.\")\n"))
167 \(provide '" (file-name-sans-extension
168 (file-name-nondirectory generated-custom-dependencies-file
)) ")
171 ;; version-control: never
172 ;; no-byte-compile: t
173 ;; no-update-autoloads: t
175 (file-name-nondirectory generated-custom-dependencies-file
)
177 (let ((kept-new-versions 10000000))
179 (message "Generating %s...done" generated-custom-dependencies-file
)
184 ;; arch-tag: b7b6421a-bf7a-44fd-a382-6f44976bdf68
185 ;;; cus-dep.el ends here