]> code.delx.au - gnu-emacs/blob - lisp/cus-dep.el
* mail/sendmail.el (mail-envelope-from): New option `header' to
[gnu-emacs] / lisp / cus-dep.el
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
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
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30 (require 'widget)
31 (require 'cus-face)
32 (require 'autoload)
33
34 (defun custom-make-dependencies ()
35 "Batch function to extract custom dependencies from .el files.
36 Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
37 (let ((enable-local-eval nil))
38 (set-buffer (get-buffer-create " cus-dep temp"))
39 (dolist (subdir command-line-args-left)
40 (message "Directory %s" subdir)
41 (let ((files (directory-files subdir nil "\\`[^=].*\\.el\\'"))
42 (default-directory (expand-file-name subdir))
43 is-autoloaded)
44 (dolist (file files)
45 (when (file-exists-p file)
46 (erase-buffer)
47 (insert-file-contents file)
48 (goto-char (point-min))
49 (string-match "\\`\\(.*\\)\\.el\\'" file)
50 (let ((name (file-name-nondirectory (match-string 1 file))))
51 (if (save-excursion
52 (re-search-forward
53 (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*"
54 (regexp-quote name) "[ \t\n)]")
55 nil t))
56 (setq name (intern name)))
57 (condition-case nil
58 (while (re-search-forward
59 "^(def\\(custom\\|face\\|group\\)" nil t)
60 (setq is-autoloaded nil)
61 (beginning-of-line)
62 (save-excursion
63 (forward-line -1)
64 (if (looking-at generate-autoload-cookie)
65 (setq is-autoloaded t)))
66 (let ((expr (read (current-buffer))))
67 (condition-case nil
68 (let ((custom-dont-initialize t))
69 (eval expr)
70 (put (nth 1 expr) 'custom-autoloaded is-autoloaded)
71 (put (nth 1 expr) 'custom-where name))
72 (error nil))))
73 (error nil))))))))
74 (message "Generating cus-load.el...")
75 (set-buffer (find-file-noselect "cus-load.el"))
76 (erase-buffer)
77 (insert "\
78 ;;; cus-load.el --- automatically extracted custom dependencies
79 ;;
80 ;;; Code:
81
82 ")
83 (mapatoms (lambda (symbol)
84 (let ((members (get symbol 'custom-group))
85 item where found)
86 (when members
87 ;; So x and no-x builds won't differ.
88 (setq members
89 (sort (copy-sequence members)
90 (lambda (x y) (string< (car x) (car y)))))
91 (while members
92 (setq item (car (car members))
93 members (cdr members)
94 where (get item 'custom-where))
95 (unless (or (null where)
96 (member where found))
97 (if found
98 (insert " ")
99 (insert "(put '" (symbol-name symbol)
100 " 'custom-loads '("))
101 (prin1 where (current-buffer))
102 (push where found)))
103 (when found
104 (insert "))\n"))))))
105 (insert "\
106 ;;; These are for handling :version. We need to have a minimum of
107 ;;; information so `custom-changed-variables' could do its job.
108 ;;; For both groups and variables we have to set `custom-version'.
109 ;;; For variables we also set the `standard-value' and for groups
110 ;;; `group-documentation' (which is shown in the customize buffer), so
111 ;;; we don't have to load the file containing the group.
112
113 ;;; `custom-versions-load-alist' is an alist that has as car a version
114 ;;; number and as elts the files that have variables that contain that
115 ;;; version. These files should be loaded before showing the
116 ;;; customization buffer that `customize-changed-options' generates.
117
118
119 ;;; This macro is used so we don't modify the information about
120 ;;; variables and groups if it's already set. (We don't know when
121 ;;; cus-load.el is going to be loaded and at that time some of the
122 ;;; files might be loaded and some others might not).
123 \(defmacro custom-put-if-not (symbol propname value)
124 `(unless (get ,symbol ,propname)
125 (put ,symbol ,propname ,value)))
126
127 ")
128 (let ((version-alist nil))
129 (mapatoms (lambda (symbol)
130 (let ((version (get symbol 'custom-version))
131 where)
132 (when version
133 (setq where (get symbol 'custom-where))
134 (when (and where
135 ;; Don't bother to do anything if it's
136 ;; autoloaded because we will have all
137 ;; this info when emacs is running
138 ;; anyway.
139 (not (get symbol 'custom-autoloaded)))
140 (insert "(custom-put-if-not '" (symbol-name symbol)
141 " 'custom-version ")
142 (prin1 version (current-buffer))
143 (insert ")\n")
144 (insert "(custom-put-if-not '" (symbol-name symbol))
145 (if (get symbol 'standard-value)
146 ;; This means it's a variable
147 (progn
148 (insert " 'standard-value t)\n")
149 (if (assoc version version-alist)
150 (unless
151 (member where
152 (cdr (assoc version version-alist)))
153 (push where (cdr (assoc version version-alist))))
154 (push (cons version (list where)) version-alist)))
155 ;; This is a group
156 (insert " 'group-documentation ")
157 (prin1 (get symbol 'group-documentation) (current-buffer))
158 (insert ")\n")))))))
159
160 (insert "\n(defvar custom-versions-load-alist "
161 (if version-alist "'" ""))
162 (prin1 version-alist (current-buffer))
163 (insert "\n \"For internal use by custom.\")\n"))
164
165 (insert "\
166
167 \(provide 'cus-load)
168
169 ;;; Local Variables:
170 ;;; version-control: never
171 ;;; no-byte-compile: t
172 ;;; no-update-autoloads: t
173 ;;; End:
174 ;;; cus-load.el ends here\n")
175 (let ((kept-new-versions 10000000))
176 (save-buffer))
177 (message "Generating cus-load.el...done")
178 (kill-emacs))
179
180 \f
181 ;;; cus-dep.el ends here