Commit | Line | Data |
---|---|---|
e8af40ee | 1 | ;;; cus-dep.el --- find customization dependencies |
860af8ec | 2 | ;; |
73b0cd50 | 3 | ;; Copyright (C) 1997, 2001-2011 Free Software Foundation, Inc. |
860af8ec PA |
4 | ;; |
5 | ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | |
6 | ;; Keywords: internal | |
bd78fa1d | 7 | ;; Package: emacs |
860af8ec | 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" |
9b3cd5b4 GM |
33 | "Output file for `custom-make-dependencies'.") |
34 | ||
35 | ;; See finder-no-scan-regexp in finder.el. | |
36 | (defvar custom-dependencies-no-scan-regexp "\\(^\\.#\\|\\(loaddefs\\|\ | |
3c0d7a5e | 37 | ldefs-boot\\|cus-load\\|finder-inf\\|esh-groups\\|subdirs\\)\\.el$\\)" |
9b3cd5b4 GM |
38 | "Regexp matching file names not to scan for `custom-make-dependencies'.") |
39 | ||
40 | (autoload 'autoload-rubric "autoload") | |
b1d7940f | 41 | |
860af8ec PA |
42 | (defun custom-make-dependencies () |
43 | "Batch function to extract custom dependencies from .el files. | |
efbdca12 | 44 | Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS" |
d647b7c4 GM |
45 | (let ((enable-local-eval nil) |
46 | subdir) | |
9b3cd5b4 | 47 | (with-temp-buffer |
d647b7c4 GM |
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)) | |
9b3cd5b4 GM |
51 | (message "Directory %s" subdir) |
52 | (let ((files (directory-files subdir nil "\\`[^=].*\\.el\\'")) | |
53 | (default-directory (expand-file-name subdir)) | |
54 | (preloaded (concat "\\`" | |
55 | (regexp-opt (mapcar | |
56 | (lambda (f) | |
57 | (file-name-sans-extension | |
58 | (file-name-nondirectory f))) | |
59 | preloaded-file-list) t) | |
60 | "\\.el\\'"))) | |
61 | (dolist (file files) | |
62 | (unless (or (string-match custom-dependencies-no-scan-regexp file) | |
63 | (string-match preloaded file) | |
64 | (not (file-exists-p file))) | |
65 | (erase-buffer) | |
66 | (insert-file-contents file) | |
67 | (goto-char (point-min)) | |
68 | (string-match "\\`\\(.*\\)\\.el\\'" file) | |
69 | (let ((name (file-name-nondirectory (match-string 1 file))) | |
70 | (load-file-name file)) | |
71 | (if (save-excursion | |
72 | (re-search-forward | |
5188f2eb SM |
73 | (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*" |
74 | (regexp-quote name) "[ \t\n)]") | |
75 | nil t)) | |
9b3cd5b4 GM |
76 | (setq name (intern name))) |
77 | (condition-case nil | |
78 | (while (re-search-forward | |
79 | "^(def\\(custom\\|face\\|group\\)" nil t) | |
80 | (beginning-of-line) | |
81 | (let ((expr (read (current-buffer)))) | |
82 | (condition-case nil | |
83 | (let ((custom-dont-initialize t)) | |
84 | (eval expr) | |
85 | (put (nth 1 expr) 'custom-where name)) | |
86 | (error nil)))) | |
87 | (error nil))))))))) | |
b1d7940f AS |
88 | (message "Generating %s..." generated-custom-dependencies-file) |
89 | (set-buffer (find-file-noselect generated-custom-dependencies-file)) | |
9b3cd5b4 | 90 | (setq buffer-undo-list t) |
860af8ec | 91 | (erase-buffer) |
9b3cd5b4 | 92 | (insert (autoload-rubric generated-custom-dependencies-file |
60878f2d | 93 | "custom dependencies" t)) |
9b3cd5b4 | 94 | (search-backward "\f") |
860af8ec PA |
95 | (mapatoms (lambda (symbol) |
96 | (let ((members (get symbol 'custom-group)) | |
e2dc1f61 | 97 | where found) |
860af8ec | 98 | (when members |
e2dc1f61 SM |
99 | (dolist (member |
100 | ;; So x and no-x builds won't differ. | |
101 | (sort (mapcar 'car members) 'string<)) | |
102 | (setq where (get member 'custom-where)) | |
860af8ec PA |
103 | (unless (or (null where) |
104 | (member where found)) | |
860af8ec | 105 | (push where found))) |
a9d3a78b | 106 | (when found |
e2dc1f61 SM |
107 | (insert "(put '" (symbol-name symbol) |
108 | " 'custom-loads '") | |
882108c7 | 109 | (prin1 (nreverse found) (current-buffer)) |
1c32c9d6 | 110 | (insert ")\n")))))) |
8cd58e14 | 111 | (insert "\ |
e2dc1f61 SM |
112 | ;; These are for handling :version. We need to have a minimum of |
113 | ;; information so `customize-changed-options' could do its job. | |
114 | ||
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. | |
118 | ||
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. | |
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 | |
127 | ;; " (file-name-nondirectory generated-custom-dependencies-file) | |
b1d7940f | 128 | " is going to be loaded and at that time some of the |
e2dc1f61 | 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)))) | |
526af3b0 | 151 | (push (list version where) version-alist))) |
1e484d64 | 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")) | |
9b3cd5b4 GM |
172 | (save-buffer) |
173 | (message "Generating %s...done" generated-custom-dependencies-file)) | |
860af8ec | 174 | |
6a7ceddc | 175 | \f |
ab5796a9 | 176 | |
860af8ec | 177 | ;;; cus-dep.el ends here |