Commit | Line | Data |
---|---|---|
860af8ec PA |
1 | ;;; cus-dep.el --- Find customization dependencies. |
2 | ;; | |
3 | ;; Copyright (C) 1997 Free Software Foundation, Inc. | |
4 | ;; | |
5 | ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | |
6 | ;; Keywords: internal | |
7 | ||
c2383d2d RS |
8 | ;; This file is part of GNU Emacs. |
9 | ||
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) | |
13 | ;; any later version. | |
14 | ||
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. | |
19 | ||
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., 59 Temple Place - Suite 330, | |
23 | ;; Boston, MA 02111-1307, USA. | |
24 | ||
860af8ec PA |
25 | ;;; Code: |
26 | ||
79c70818 | 27 | (eval-when-compile (require 'cl)) |
c9aadf03 RS |
28 | (require 'widget) |
29 | (require 'cus-face) | |
1e484d64 | 30 | (require 'autoload) |
860af8ec PA |
31 | |
32 | (defun custom-make-dependencies () | |
33 | "Batch function to extract custom dependencies from .el files. | |
efbdca12 | 34 | Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS" |
860af8ec | 35 | (let ((enable-local-eval nil) |
efbdca12 | 36 | (all-subdirs command-line-args-left) |
c9aadf03 RS |
37 | (start-directory default-directory)) |
38 | (get-buffer-create " cus-dep temp") | |
39 | (set-buffer " cus-dep temp") | |
c9aadf03 RS |
40 | (while all-subdirs |
41 | (message "Directory %s" (car all-subdirs)) | |
42 | (let ((files (directory-files (car all-subdirs) nil "\\`[^=].*\\.el\\'")) | |
43 | (default-directory default-directory) | |
1e484d64 DN |
44 | file |
45 | is-autoloaded) | |
c9aadf03 RS |
46 | (cd (car all-subdirs)) |
47 | (while files | |
48 | (setq file (car files) | |
49 | files (cdr files)) | |
efbdca12 | 50 | (when (file-exists-p file) |
efbdca12 RS |
51 | (erase-buffer) |
52 | (insert-file-contents file) | |
53 | (goto-char (point-min)) | |
54 | (string-match "\\`\\(.*\\)\\.el\\'" file) | |
55 | (let ((name (file-name-nondirectory (match-string 1 file)))) | |
56 | (condition-case nil | |
57 | (while (re-search-forward "^(defcustom\\|^(defface\\|^(defgroup" | |
58 | nil t) | |
1e484d64 | 59 | (setq is-autoloaded nil) |
efbdca12 | 60 | (beginning-of-line) |
1e484d64 DN |
61 | (save-excursion |
62 | (forward-line -1) | |
63 | (if (looking-at generate-autoload-cookie) | |
64 | (setq is-autoloaded t))) | |
efbdca12 | 65 | (let ((expr (read (current-buffer)))) |
06beea21 RS |
66 | (condition-case nil |
67 | (progn | |
68 | (eval expr) | |
1e484d64 | 69 | (put (nth 1 expr) 'custom-autoloaded is-autoloaded) |
06beea21 RS |
70 | (put (nth 1 expr) 'custom-where name)) |
71 | (error nil)))) | |
efbdca12 | 72 | (error nil))))) |
c9aadf03 | 73 | (setq all-subdirs (cdr all-subdirs))))) |
860af8ec PA |
74 | (message "Generating cus-load.el...") |
75 | (find-file "cus-load.el") | |
76 | (erase-buffer) | |
77 | (insert "\ | |
78 | ;;; cus-load.el --- automatically extracted custom dependencies | |
79 | ;; | |
80 | ;;; Code: | |
a3edd195 | 81 | |
860af8ec PA |
82 | ") |
83 | (mapatoms (lambda (symbol) | |
84 | (let ((members (get symbol 'custom-group)) | |
85 | item where found) | |
86 | (when members | |
87 | (while members | |
88 | (setq item (car (car members)) | |
89 | members (cdr members) | |
90 | where (get item 'custom-where)) | |
91 | (unless (or (null where) | |
92 | (member where found)) | |
93 | (if found | |
94 | (insert " ") | |
95 | (insert "(put '" (symbol-name symbol) | |
96 | " 'custom-loads '(")) | |
a9d3a78b | 97 | (prin1 where (current-buffer)) |
860af8ec | 98 | (push where found))) |
a9d3a78b PA |
99 | (when found |
100 | (insert "))\n")))))) | |
8cd58e14 | 101 | (insert "\ |
1e484d64 DN |
102 | ;;; These are for handling :version. We need to have a minimum of |
103 | ;;; information so `custom-changed-variables' could do its job. | |
104 | ;;; For both groups and variables we have to set `custom-version'. | |
105 | ;;; For variables we also set the `standard-value' and for groups | |
b88018d4 | 106 | ;;; `group-documentation' (which is shown in the customize buffer), so |
1e484d64 DN |
107 | ;;; we don't have to load the file containing the group. |
108 | ||
109 | ;;; `custom-versions-load-alist' is an alist that has as car a version | |
110 | ;;; number and as elts the files that have variables that contain that | |
111 | ;;; version. These files should be loaded before showing the | |
112 | ;;; customization buffer that `customize-changed-options' generates. | |
113 | ||
114 | ||
115 | ;;; This macro is used so we don't modify the information about | |
116 | ;;; variables and groups if it's already set. (We don't know when | |
117 | ;;; cus-load.el is going to be loaded and at that time some of the | |
118 | ;;; files might be loaded and some others might not). | |
a313af11 | 119 | \(defmacro custom-put-if-not (symbol propname value) |
1e484d64 DN |
120 | `(unless (get ,symbol ,propname) |
121 | (put ,symbol ,propname ,value))) | |
122 | ||
123 | ") | |
124 | (let ((version-alist nil)) | |
125 | (mapatoms (lambda (symbol) | |
126 | (let ((version (get symbol 'custom-version)) | |
127 | where) | |
128 | (when version | |
129 | (setq where (get symbol 'custom-where)) | |
130 | (when (and where | |
131 | ;; Don't bother to do anything if it's | |
132 | ;; autoloaded because we will have all | |
133 | ;; this info when emacs is running | |
134 | ;; anyway. | |
135 | (not (get symbol 'custom-autoloaded))) | |
136 | (insert "(custom-put-if-not '" (symbol-name symbol) | |
137 | " 'custom-version ") | |
138 | (prin1 version (current-buffer)) | |
139 | (insert ")\n") | |
781f7ac2 | 140 | (insert "(custom-put-if-not '" (symbol-name symbol)) |
1e484d64 DN |
141 | (if (get symbol 'standard-value) |
142 | ;; This means it's a variable | |
143 | (progn | |
144 | (insert " 'standard-value t)\n") | |
145 | (if (assoc version version-alist) | |
146 | (unless | |
147 | (member where | |
148 | (cdr (assoc version version-alist))) | |
149 | (push where (cdr (assoc version version-alist)))) | |
150 | (push (cons version (list where)) version-alist))) | |
151 | ;; This is a group | |
152 | (insert " 'group-documentation ") | |
153 | (prin1 (get symbol 'group-documentation) (current-buffer)) | |
154 | (insert ")\n"))))))) | |
155 | ||
156 | (insert "\n(defvar custom-versions-load-alist " | |
157 | (if version-alist "'" "")) | |
158 | (prin1 version-alist (current-buffer)) | |
159 | (insert "\n \"For internal use by custom.\")\n")) | |
160 | ||
161 | (insert "\ | |
8cd58e14 PA |
162 | |
163 | \(provide 'cus-load) | |
164 | ||
6a7ceddc SM |
165 | ;;; Local Variables: |
166 | ;;; version-control: never | |
167 | ;;; no-byte-compile: t | |
168 | ;;; no-update-autoloads: t | |
169 | ;;; End: | |
8cd58e14 | 170 | ;;; cus-load.el ends here\n") |
c9aadf03 RS |
171 | (let ((kept-new-versions 10000000)) |
172 | (save-buffer)) | |
efbdca12 RS |
173 | (message "Generating cus-load.el...done") |
174 | (kill-emacs)) | |
860af8ec | 175 | |
6a7ceddc | 176 | \f |
860af8ec | 177 | ;;; cus-dep.el ends here |