1 ;;; cus-dep.el --- find customization dependencies
3 ;; Copyright (C) 1997, 2001-2012 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 (eval-when-compile (require 'cl
))
32 (defvar generated-custom-dependencies-file
"cus-load.el"
33 "Output file for `custom-make-dependencies'.")
35 ;; See finder-no-scan-regexp in finder.el.
36 (defvar custom-dependencies-no-scan-regexp
"\\(^\\.#\\|\\(loaddefs\\|\
37 ldefs-boot\\|cus-load\\|finder-inf\\|esh-groups\\|subdirs\\)\\.el$\\)"
38 "Regexp matching file names not to scan for `custom-make-dependencies'.")
40 (autoload 'autoload-rubric
"autoload")
42 (defun custom-make-dependencies ()
43 "Batch function to extract custom dependencies from .el files.
44 Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
45 (let ((enable-local-eval nil
)
48 ;; Use up command-line-args-left else Emacs can try to open
49 ;; the args as directories after we are done.
50 (while (setq subdir
(pop command-line-args-left
))
51 (message "Directory %s" subdir
)
52 (let ((files (directory-files subdir nil
"\\`[^=].*\\.el\\'"))
53 (default-directory (expand-file-name subdir
))
54 (preloaded (concat "\\`"
57 preloaded-file-list
) t
)
60 (unless (or (string-match custom-dependencies-no-scan-regexp file
)
61 (string-match preloaded file
)
62 (not (file-exists-p file
)))
64 (insert-file-contents file
)
65 (goto-char (point-min))
66 (string-match "\\`\\(.*\\)\\.el\\'" file
)
67 (let ((name (file-name-nondirectory (match-string 1 file
)))
68 (load-file-name file
))
71 (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*"
72 (regexp-quote name
) "[ \t\n)]")
74 (setq name
(intern name
)))
76 (while (re-search-forward
77 "^(def\\(custom\\|face\\|group\\)" nil t
)
79 (let ((expr (read (current-buffer))))
81 (let ((custom-dont-initialize t
))
83 (put (nth 1 expr
) 'custom-where name
))
86 (message "Generating %s..." generated-custom-dependencies-file
)
87 (set-buffer (find-file-noselect generated-custom-dependencies-file
))
88 (setq buffer-undo-list t
)
90 (insert (autoload-rubric generated-custom-dependencies-file
91 "custom dependencies" t
))
92 (search-backward "\f")
93 (mapatoms (lambda (symbol)
94 (let ((members (get symbol
'custom-group
))
98 ;; So x and no-x builds won't differ.
99 (sort (mapcar 'car members
) 'string
<))
100 (setq where
(get member
'custom-where
))
101 (unless (or (null where
)
102 (member where found
))
105 (insert "(put '" (symbol-name symbol
)
107 (prin1 (nreverse found
) (current-buffer))
110 ;; These are for handling :version. We need to have a minimum of
111 ;; information so `customize-changed-options' could do its job.
113 ;; For groups we set `custom-version', `group-documentation' and
114 ;; `custom-tag' (which are shown in the customize buffer), so we
115 ;; don't have to load the file containing the group.
117 ;; `custom-versions-load-alist' is an alist that has as car a version
118 ;; number and as elts the files that have variables or faces that
119 ;; contain that version. These files should be loaded before showing
120 ;; the customization buffer that `customize-changed-options'
123 ;; This macro is used so we don't modify the information about
124 ;; variables and groups if it's already set. (We don't know when
125 ;; " (file-name-nondirectory generated-custom-dependencies-file
)
126 " is going to be loaded and at that time some of the
127 ;; files might be loaded and some others might not).
128 \(defmacro custom-put-if-not (symbol propname value)
129 `(unless (get ,symbol ,propname)
130 (put ,symbol ,propname ,value)))
133 (let ((version-alist nil
))
134 (mapatoms (lambda (symbol)
135 (let ((version (get symbol
'custom-version
))
138 (setq where
(get symbol
'custom-where
))
140 (if (or (custom-variable-p symbol
)
141 (custom-facep symbol
))
142 ;; This means it's a variable or a face.
144 (if (assoc version version-alist
)
147 (cdr (assoc version version-alist
)))
148 (push where
(cdr (assoc version version-alist
))))
149 (push (list version where
) version-alist
)))
151 (insert "(custom-put-if-not '" (symbol-name symbol
)
153 (prin1 version
(current-buffer))
155 (insert "(custom-put-if-not '" (symbol-name symbol
))
156 (insert " 'group-documentation ")
157 (prin1 (get symbol
'group-documentation
) (current-buffer))
159 (when (get symbol
'custom-tag
)
160 (insert "(custom-put-if-not '" (symbol-name symbol
))
161 (insert " 'custom-tag ")
162 (prin1 (get symbol
'custom-tag
) (current-buffer))
166 (insert "\n(defvar custom-versions-load-alist "
167 (if version-alist
"'" ""))
168 (prin1 version-alist
(current-buffer))
169 (insert "\n \"For internal use by custom.\")\n"))
171 (message "Generating %s...done" generated-custom-dependencies-file
))
175 ;;; cus-dep.el ends here