(ibuffer-formats): Change default value; bump width
[emacs.git] / lisp / cus-dep.el
blobb923dfcbacdda5fa1ec71f46b4f32b3a13abf795
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)
33 (defun custom-make-dependencies ()
34 "Batch function to extract custom dependencies from .el files.
35 Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
36 (let ((enable-local-eval nil))
37 (set-buffer (get-buffer-create " cus-dep temp"))
38 (dolist (subdir command-line-args-left)
39 (message "Directory %s" subdir)
40 (let ((files (directory-files subdir nil "\\`[^=].*\\.el\\'"))
41 (default-directory (expand-file-name subdir))
42 (preloaded (concat "\\`"
43 (regexp-opt (mapcar
44 (lambda (f)
45 (file-name-sans-extension
46 (file-name-nondirectory f)))
47 preloaded-file-list) t)
48 "\\.el\\'")))
49 (dolist (file files)
50 (when (and (file-exists-p file)
51 ;; Ignore files that are preloaded.
52 (not (string-match preloaded 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 (load-file-name file))
59 (if (save-excursion
60 (re-search-forward
61 (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*"
62 (regexp-quote name) "[ \t\n)]")
63 nil t))
64 (setq name (intern name)))
65 (condition-case nil
66 (while (re-search-forward
67 "^(def\\(custom\\|face\\|group\\)" nil t)
68 (beginning-of-line)
69 (let ((expr (read (current-buffer))))
70 (condition-case nil
71 (let ((custom-dont-initialize t))
72 (eval expr)
73 (put (nth 1 expr) 'custom-where name))
74 (error nil))))
75 (error nil))))))))
76 (message "Generating cus-load.el...")
77 (set-buffer (find-file-noselect "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 ;; So x and no-x builds won't differ.
90 (setq members
91 (sort (copy-sequence members)
92 (lambda (x y) (string< (car x) (car y)))))
93 (while members
94 (setq item (car (car members))
95 members (cdr members)
96 where (get item 'custom-where))
97 (unless (or (null where)
98 (member where found))
99 (if found
100 (insert " ")
101 (insert "(put '" (symbol-name symbol)
102 " 'custom-loads '("))
103 (prin1 where (current-buffer))
104 (push where found)))
105 (when found
106 (insert "))\n"))))))
107 (insert "\
108 ;;; These are for handling :version. We need to have a minimum of
109 ;;; information so `customize-changed-options' could do its job.
110 ;;; For both groups and variables we have to set `custom-version'.
111 ;;; For variables we also set the `standard-value' and for groups
112 ;;; `group-documentation' (which is shown in the customize buffer), so
113 ;;; we don't have to load the file containing the group.
115 ;;; `custom-versions-load-alist' is an alist that has as car a version
116 ;;; number and as elts the files that have variables that contain that
117 ;;; version. These files should be loaded before showing the
118 ;;; customization buffer that `customize-changed-options' generates.
121 ;;; This macro is used so we don't modify the information about
122 ;;; variables and groups if it's already set. (We don't know when
123 ;;; cus-load.el is going to be loaded and at that time some of the
124 ;;; files might be loaded and some others might not).
125 \(defmacro custom-put-if-not (symbol propname value)
126 `(unless (get ,symbol ,propname)
127 (put ,symbol ,propname ,value)))
130 (let ((version-alist nil))
131 (mapatoms (lambda (symbol)
132 (let ((version (get symbol 'custom-version))
133 where)
134 (when version
135 (setq where (get symbol 'custom-where))
136 (when where
137 (insert "(custom-put-if-not '" (symbol-name symbol)
138 " 'custom-version ")
139 (prin1 version (current-buffer))
140 (insert ")\n")
141 (insert "(custom-put-if-not '" (symbol-name symbol))
142 (if (get symbol 'standard-value)
143 ;; This means it's a variable
144 (progn
145 (insert " 'standard-value t)\n")
146 (if (assoc version version-alist)
147 (unless
148 (member where
149 (cdr (assoc version version-alist)))
150 (push where (cdr (assoc version version-alist))))
151 (push (cons version (list where)) version-alist)))
152 ;; This is a group
153 (insert " 'group-documentation ")
154 (prin1 (get symbol 'group-documentation) (current-buffer))
155 (insert ")\n")))))))
157 (insert "\n(defvar custom-versions-load-alist "
158 (if version-alist "'" ""))
159 (prin1 version-alist (current-buffer))
160 (insert "\n \"For internal use by custom.\")\n"))
162 (insert "\
164 \(provide 'cus-load)
166 ;;; Local Variables:
167 ;;; version-control: never
168 ;;; no-byte-compile: t
169 ;;; no-update-autoloads: t
170 ;;; End:
171 ;;; cus-load.el ends here\n")
172 (let ((kept-new-versions 10000000))
173 (save-buffer))
174 (message "Generating cus-load.el...done")
175 (kill-emacs))
178 ;;; cus-dep.el ends here