1 ;;; cus-dep.el --- find customization dependencies
3 ;; Copyright (C) 1997, 2001-2013 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/>.
31 (defvar generated-custom-dependencies-file
"cus-load.el"
32 "Output file for `custom-make-dependencies'.")
34 ;; See finder-no-scan-regexp in finder.el.
35 (defvar custom-dependencies-no-scan-regexp
"\\(^\\.#\\|\\(loaddefs\\|\
36 ldefs-boot\\|cus-load\\|finder-inf\\|esh-groups\\|subdirs\\)\\.el$\\)"
37 "Regexp matching file names not to scan for `custom-make-dependencies'.")
41 ;; Hack workaround for bug#14384.
42 ;; Define defcustom-mh as an alias for defcustom, etc.
43 ;; Only do this in batch mode to avoid messing up a normal Emacs session.
44 ;; Alternative would be to load mh-e when making cus-load.
45 ;; (Would be better to split just the necessary parts of mh-e into a
46 ;; separate file and only load that.)
47 (when (and noninteractive
)
48 (mapc (lambda (e) (let ((sym (intern (format "%s-mh" e
))))
51 '(defcustom defface defgroup
)))
53 (defun custom-make-dependencies ()
54 "Batch function to extract custom dependencies from .el files.
55 Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
56 (let ((enable-local-eval nil
)
57 (enable-local-variables :safe
)
60 ;; Use up command-line-args-left else Emacs can try to open
61 ;; the args as directories after we are done.
62 (while (setq subdir
(pop command-line-args-left
))
63 (message "Directory %s" subdir
)
64 (let ((files (directory-files subdir nil
"\\`[^=].*\\.el\\'"))
65 (default-directory (expand-file-name subdir
))
66 (preloaded (concat "\\`"
69 preloaded-file-list
) t
)
72 (unless (or (string-match custom-dependencies-no-scan-regexp file
)
73 (string-match preloaded file
)
74 (not (file-exists-p file
)))
76 (kill-all-local-variables)
77 (insert-file-contents file
)
78 (hack-local-variables)
79 (goto-char (point-min))
80 (string-match "\\`\\(.*\\)\\.el\\'" file
)
81 (let ((name (or generated-autoload-load-name
; see bug#5277
82 (file-name-nondirectory (match-string 1 file
))))
83 (load-file-name file
))
86 (concat "(\\(cc-\\)?provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*"
87 (regexp-quote name
) "[ \t\n)]")
89 (setq name
(intern name
)))
91 (while (re-search-forward
92 "^(def\\(custom\\|face\\|group\\)" nil t
)
94 (let ((expr (read (current-buffer))))
96 (let ((custom-dont-initialize t
))
97 ;; Why do we need to eval just for the name?
99 (put (nth 1 expr
) 'custom-where name
))
102 (message "Generating %s..." generated-custom-dependencies-file
)
103 (set-buffer (find-file-noselect generated-custom-dependencies-file
))
104 (setq buffer-undo-list t
)
106 (insert (autoload-rubric generated-custom-dependencies-file
107 "custom dependencies" t
))
108 (search-backward "\f")
109 (mapatoms (lambda (symbol)
110 (let ((members (get symbol
'custom-group
))
114 ;; So x and no-x builds won't differ.
115 (sort (mapcar 'car members
) 'string
<))
116 (setq where
(get member
'custom-where
))
117 (unless (or (null where
)
118 (member where found
))
121 (insert "(put '" (symbol-name symbol
)
123 (prin1 (nreverse found
) (current-buffer))
126 ;; These are for handling :version. We need to have a minimum of
127 ;; information so `customize-changed-options' could do its job.
129 ;; For groups we set `custom-version', `group-documentation' and
130 ;; `custom-tag' (which are shown in the customize buffer), so we
131 ;; don't have to load the file containing the group.
133 ;; `custom-versions-load-alist' is an alist that has as car a version
134 ;; number and as elts the files that have variables or faces that
135 ;; contain that version. These files should be loaded before showing
136 ;; the customization buffer that `customize-changed-options'
139 ;; This macro is used so we don't modify the information about
140 ;; variables and groups if it's already set. (We don't know when
141 ;; " (file-name-nondirectory generated-custom-dependencies-file
)
142 " is going to be loaded and at that time some of the
143 ;; files might be loaded and some others might not).
144 \(defmacro custom-put-if-not (symbol propname value)
145 `(unless (get ,symbol ,propname)
146 (put ,symbol ,propname ,value)))
149 (let ((version-alist nil
))
150 (mapatoms (lambda (symbol)
151 (let ((version (get symbol
'custom-version
))
154 (setq where
(get symbol
'custom-where
))
156 (if (or (custom-variable-p symbol
)
157 (custom-facep symbol
))
158 ;; This means it's a variable or a face.
160 (if (assoc version version-alist
)
163 (cdr (assoc version version-alist
)))
164 (push where
(cdr (assoc version version-alist
))))
165 (push (list version where
) version-alist
)))
167 (insert "(custom-put-if-not '" (symbol-name symbol
)
169 (prin1 version
(current-buffer))
171 (insert "(custom-put-if-not '" (symbol-name symbol
))
172 (insert " 'group-documentation ")
173 (prin1 (get symbol
'group-documentation
) (current-buffer))
175 (when (get symbol
'custom-tag
)
176 (insert "(custom-put-if-not '" (symbol-name symbol
))
177 (insert " 'custom-tag ")
178 (prin1 (get symbol
'custom-tag
) (current-buffer))
182 (insert "\n(defvar custom-versions-load-alist "
183 (if version-alist
"'" ""))
184 (prin1 version-alist
(current-buffer))
185 (insert "\n \"For internal use by custom.\")\n"))
187 (message "Generating %s...done" generated-custom-dependencies-file
))
191 ;;; cus-dep.el ends here