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