Add minibuffer-completion-contents.
[emacs.git] / lisp / cus-dep.el
blob1b13a12698f8cefe2d5f0b9cd8b0bcbcc42f5979
1 ;;; cus-dep.el --- find customization dependencies
2 ;;
3 ;; Copyright (C) 1997, 2002, 2003, 2004, 2005 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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
25 ;;; Commentary:
27 ;;; Code:
29 (eval-when-compile (require 'cl))
30 (require 'widget)
31 (require 'cus-face)
33 (defvar generated-custom-dependencies-file "cus-load.el"
34 "File \\[cusom-make-dependencies] puts custom dependencies into.")
36 (defun custom-make-dependencies ()
37 "Batch function to extract custom dependencies from .el files.
38 Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
39 (let ((enable-local-eval nil))
40 (set-buffer (get-buffer-create " cus-dep temp"))
41 (dolist (subdir command-line-args-left)
42 (message "Directory %s" subdir)
43 (let ((files (directory-files subdir nil "\\`[^=].*\\.el\\'"))
44 (default-directory (expand-file-name subdir))
45 (preloaded (concat "\\`"
46 (regexp-opt (mapcar
47 (lambda (f)
48 (file-name-sans-extension
49 (file-name-nondirectory f)))
50 preloaded-file-list) t)
51 "\\.el\\'")))
52 (dolist (file files)
53 (when (and (file-exists-p file)
54 ;; Ignore files that are preloaded.
55 (not (string-match preloaded file)))
56 (erase-buffer)
57 (insert-file-contents file)
58 (goto-char (point-min))
59 (string-match "\\`\\(.*\\)\\.el\\'" file)
60 (let ((name (file-name-nondirectory (match-string 1 file)))
61 (load-file-name file))
62 (if (save-excursion
63 (re-search-forward
64 (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*"
65 (regexp-quote name) "[ \t\n)]")
66 nil t))
67 (setq name (intern name)))
68 (condition-case nil
69 (while (re-search-forward
70 "^(def\\(custom\\|face\\|group\\)" nil t)
71 (beginning-of-line)
72 (let ((expr (read (current-buffer))))
73 (condition-case nil
74 (let ((custom-dont-initialize t))
75 (eval expr)
76 (put (nth 1 expr) 'custom-where name))
77 (error nil))))
78 (error nil))))))))
79 (message "Generating %s..." generated-custom-dependencies-file)
80 (set-buffer (find-file-noselect generated-custom-dependencies-file))
81 (erase-buffer)
82 (insert ";;; " (file-name-nondirectory generated-custom-dependencies-file)
83 " --- automatically extracted custom dependencies
84 ;;\n;;; Code:
87 (mapatoms (lambda (symbol)
88 (let ((members (get symbol 'custom-group))
89 where found)
90 (when members
91 (dolist (member
92 ;; So x and no-x builds won't differ.
93 (sort (mapcar 'car members) 'string<))
94 (setq where (get member 'custom-where))
95 (unless (or (null where)
96 (member where found))
97 (push where found)))
98 (when found
99 (insert "(put '" (symbol-name symbol)
100 " 'custom-loads '")
101 (prin1 (nreverse found) (current-buffer))
102 (insert ")\n"))))))
103 (insert "\
104 ;; These are for handling :version. We need to have a minimum of
105 ;; information so `customize-changed-options' could do its job.
107 ;; For groups we set `custom-version', `group-documentation' and
108 ;; `custom-tag' (which are shown in the customize buffer), so we
109 ;; 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 or faces that
113 ;; contain that version. These files should be loaded before showing
114 ;; the customization buffer that `customize-changed-options'
115 ;; 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 ;; " (file-name-nondirectory generated-custom-dependencies-file)
120 " is going to be loaded and at that time some of the
121 ;; files might be loaded and some others might not).
122 \(defmacro custom-put-if-not (symbol propname value)
123 `(unless (get ,symbol ,propname)
124 (put ,symbol ,propname ,value)))
127 (let ((version-alist nil))
128 (mapatoms (lambda (symbol)
129 (let ((version (get symbol 'custom-version))
130 where)
131 (when version
132 (setq where (get symbol 'custom-where))
133 (when where
134 (if (or (custom-variable-p symbol)
135 (custom-facep symbol))
136 ;; This means it's a variable or a face.
137 (progn
138 (if (assoc version version-alist)
139 (unless
140 (member where
141 (cdr (assoc version version-alist)))
142 (push where (cdr (assoc version version-alist))))
143 (push (cons version (list where)) version-alist)))
144 ;; This is a group
145 (insert "(custom-put-if-not '" (symbol-name symbol)
146 " 'custom-version ")
147 (prin1 version (current-buffer))
148 (insert ")\n")
149 (insert "(custom-put-if-not '" (symbol-name symbol))
150 (insert " 'group-documentation ")
151 (prin1 (get symbol 'group-documentation) (current-buffer))
152 (insert ")\n")
153 (when (get symbol 'custom-tag)
154 (insert "(custom-put-if-not '" (symbol-name symbol))
155 (insert " 'custom-tag ")
156 (prin1 (get symbol 'custom-tag) (current-buffer))
157 (insert ")\n"))
158 ))))))
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"))
165 (insert "\
167 \(provide '" (file-name-sans-extension
168 (file-name-nondirectory generated-custom-dependencies-file)) ")
170 ;; Local Variables:
171 ;; version-control: never
172 ;; no-byte-compile: t
173 ;; no-update-autoloads: t
174 ;; End:\n;;; "
175 (file-name-nondirectory generated-custom-dependencies-file)
176 " ends here\n")
177 (let ((kept-new-versions 10000000))
178 (save-buffer))
179 (message "Generating %s...done" generated-custom-dependencies-file)
180 (kill-emacs))
184 ;; arch-tag: b7b6421a-bf7a-44fd-a382-6f44976bdf68
185 ;;; cus-dep.el ends here