Commit | Line | Data |
---|---|---|
e8af40ee | 1 | ;;; cus-dep.el --- find customization dependencies |
860af8ec | 2 | ;; |
9b3cd5b4 | 3 | ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
5df4f04c | 4 | ;; 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
860af8ec PA |
5 | ;; |
6 | ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | |
7 | ;; Keywords: internal | |
bd78fa1d | 8 | ;; Package: emacs |
860af8ec | 9 | |
c2383d2d RS |
10 | ;; This file is part of GNU Emacs. |
11 | ||
eb3fa2cf | 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
c2383d2d | 13 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
14 | ;; the Free Software Foundation, either version 3 of the License, or |
15 | ;; (at your option) any later version. | |
c2383d2d RS |
16 | |
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
c2383d2d | 24 | |
e8af40ee PJ |
25 | ;;; Commentary: |
26 | ||
860af8ec PA |
27 | ;;; Code: |
28 | ||
79c70818 | 29 | (eval-when-compile (require 'cl)) |
c9aadf03 RS |
30 | (require 'widget) |
31 | (require 'cus-face) | |
860af8ec | 32 | |
b1d7940f | 33 | (defvar generated-custom-dependencies-file "cus-load.el" |
9b3cd5b4 GM |
34 | "Output file for `custom-make-dependencies'.") |
35 | ||
36 | ;; See finder-no-scan-regexp in finder.el. | |
37 | (defvar custom-dependencies-no-scan-regexp "\\(^\\.#\\|\\(loaddefs\\|\ | |
3c0d7a5e | 38 | ldefs-boot\\|cus-load\\|finder-inf\\|esh-groups\\|subdirs\\)\\.el$\\)" |
9b3cd5b4 GM |
39 | "Regexp matching file names not to scan for `custom-make-dependencies'.") |
40 | ||
41 | (autoload 'autoload-rubric "autoload") | |
b1d7940f | 42 | |
860af8ec PA |
43 | (defun custom-make-dependencies () |
44 | "Batch function to extract custom dependencies from .el files. | |
efbdca12 | 45 | Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS" |
5188f2eb | 46 | (let ((enable-local-eval nil)) |
9b3cd5b4 GM |
47 | (with-temp-buffer |
48 | (dolist (subdir command-line-args-left) | |
49 | (message "Directory %s" subdir) | |
50 | (let ((files (directory-files subdir nil "\\`[^=].*\\.el\\'")) | |
51 | (default-directory (expand-file-name subdir)) | |
52 | (preloaded (concat "\\`" | |
53 | (regexp-opt (mapcar | |
54 | (lambda (f) | |
55 | (file-name-sans-extension | |
56 | (file-name-nondirectory f))) | |
57 | preloaded-file-list) t) | |
58 | "\\.el\\'"))) | |
59 | (dolist (file files) | |
60 | (unless (or (string-match custom-dependencies-no-scan-regexp file) | |
61 | (string-match preloaded file) | |
62 | (not (file-exists-p file))) | |
63 | (erase-buffer) | |
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)) | |
69 | (if (save-excursion | |
70 | (re-search-forward | |
5188f2eb SM |
71 | (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*" |
72 | (regexp-quote name) "[ \t\n)]") | |
73 | nil t)) | |
9b3cd5b4 GM |
74 | (setq name (intern name))) |
75 | (condition-case nil | |
76 | (while (re-search-forward | |
77 | "^(def\\(custom\\|face\\|group\\)" nil t) | |
78 | (beginning-of-line) | |
79 | (let ((expr (read (current-buffer)))) | |
80 | (condition-case nil | |
81 | (let ((custom-dont-initialize t)) | |
82 | (eval expr) | |
83 | (put (nth 1 expr) 'custom-where name)) | |
84 | (error nil)))) | |
85 | (error nil))))))))) | |
b1d7940f AS |
86 | (message "Generating %s..." generated-custom-dependencies-file) |
87 | (set-buffer (find-file-noselect generated-custom-dependencies-file)) | |
9b3cd5b4 | 88 | (setq buffer-undo-list t) |
860af8ec | 89 | (erase-buffer) |
9b3cd5b4 | 90 | (insert (autoload-rubric generated-custom-dependencies-file |
60878f2d | 91 | "custom dependencies" t)) |
9b3cd5b4 | 92 | (search-backward "\f") |
860af8ec PA |
93 | (mapatoms (lambda (symbol) |
94 | (let ((members (get symbol 'custom-group)) | |
e2dc1f61 | 95 | where found) |
860af8ec | 96 | (when members |
e2dc1f61 SM |
97 | (dolist (member |
98 | ;; So x and no-x builds won't differ. | |
99 | (sort (mapcar 'car members) 'string<)) | |
100 | (setq where (get member 'custom-where)) | |
860af8ec PA |
101 | (unless (or (null where) |
102 | (member where found)) | |
860af8ec | 103 | (push where found))) |
a9d3a78b | 104 | (when found |
e2dc1f61 SM |
105 | (insert "(put '" (symbol-name symbol) |
106 | " 'custom-loads '") | |
882108c7 | 107 | (prin1 (nreverse found) (current-buffer)) |
1c32c9d6 | 108 | (insert ")\n")))))) |
8cd58e14 | 109 | (insert "\ |
e2dc1f61 SM |
110 | ;; These are for handling :version. We need to have a minimum of |
111 | ;; information so `customize-changed-options' could do its job. | |
112 | ||
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. | |
116 | ||
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' | |
121 | ;; generates. | |
122 | ||
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) | |
b1d7940f | 126 | " is going to be loaded and at that time some of the |
e2dc1f61 | 127 | ;; files might be loaded and some others might not). |
a313af11 | 128 | \(defmacro custom-put-if-not (symbol propname value) |
1e484d64 DN |
129 | `(unless (get ,symbol ,propname) |
130 | (put ,symbol ,propname ,value))) | |
131 | ||
132 | ") | |
133 | (let ((version-alist nil)) | |
134 | (mapatoms (lambda (symbol) | |
135 | (let ((version (get symbol 'custom-version)) | |
136 | where) | |
71296446 | 137 | (when version |
1e484d64 | 138 | (setq where (get symbol 'custom-where)) |
052b7009 | 139 | (when where |
d5680815 MR |
140 | (if (or (custom-variable-p symbol) |
141 | (custom-facep symbol)) | |
142 | ;; This means it's a variable or a face. | |
1e484d64 | 143 | (progn |
1e484d64 | 144 | (if (assoc version version-alist) |
71296446 JB |
145 | (unless |
146 | (member where | |
1e484d64 DN |
147 | (cdr (assoc version version-alist))) |
148 | (push where (cdr (assoc version version-alist)))) | |
526af3b0 | 149 | (push (list version where) version-alist))) |
1e484d64 | 150 | ;; This is a group |
71296446 | 151 | (insert "(custom-put-if-not '" (symbol-name symbol) |
d5680815 MR |
152 | " 'custom-version ") |
153 | (prin1 version (current-buffer)) | |
154 | (insert ")\n") | |
155 | (insert "(custom-put-if-not '" (symbol-name symbol)) | |
1e484d64 DN |
156 | (insert " 'group-documentation ") |
157 | (prin1 (get symbol 'group-documentation) (current-buffer)) | |
d5680815 MR |
158 | (insert ")\n") |
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)) | |
163 | (insert ")\n")) | |
164 | )))))) | |
1e484d64 DN |
165 | |
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")) | |
9b3cd5b4 GM |
170 | (save-buffer) |
171 | (message "Generating %s...done" generated-custom-dependencies-file)) | |
860af8ec | 172 | |
6a7ceddc | 173 | \f |
ab5796a9 | 174 | |
e2dc1f61 | 175 | ;; arch-tag: b7b6421a-bf7a-44fd-a382-6f44976bdf68 |
860af8ec | 176 | ;;; cus-dep.el ends here |