Customized.
[bpt/emacs.git] / lisp / cus-dep.el
CommitLineData
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
27(require 'cl)
c9aadf03
RS
28(require 'widget)
29(require 'cus-face)
860af8ec
PA
30
31(defun custom-make-dependencies ()
32 "Batch function to extract custom dependencies from .el files.
efbdca12 33Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
860af8ec 34 (let ((enable-local-eval nil)
efbdca12 35 (all-subdirs command-line-args-left)
c9aadf03
RS
36 (start-directory default-directory))
37 (get-buffer-create " cus-dep temp")
38 (set-buffer " cus-dep temp")
c9aadf03
RS
39 (while all-subdirs
40 (message "Directory %s" (car all-subdirs))
41 (let ((files (directory-files (car all-subdirs) nil "\\`[^=].*\\.el\\'"))
42 (default-directory default-directory)
43 file)
44 (cd (car all-subdirs))
45 (while files
46 (setq file (car files)
47 files (cdr files))
efbdca12 48 (when (file-exists-p file)
efbdca12
RS
49 (erase-buffer)
50 (insert-file-contents file)
51 (goto-char (point-min))
52 (string-match "\\`\\(.*\\)\\.el\\'" file)
53 (let ((name (file-name-nondirectory (match-string 1 file))))
54 (condition-case nil
55 (while (re-search-forward "^(defcustom\\|^(defface\\|^(defgroup"
56 nil t)
57 (beginning-of-line)
58 (let ((expr (read (current-buffer))))
59 (eval expr)
60 (put (nth 1 expr) 'custom-where name)))
61 (error nil)))))
c9aadf03 62 (setq all-subdirs (cdr all-subdirs)))))
860af8ec
PA
63 (message "Generating cus-load.el...")
64 (find-file "cus-load.el")
65 (erase-buffer)
66 (insert "\
67;;; cus-load.el --- automatically extracted custom dependencies
68;;
69;;; Code:
a3edd195 70
860af8ec
PA
71")
72 (mapatoms (lambda (symbol)
73 (let ((members (get symbol 'custom-group))
74 item where found)
75 (when members
76 (while members
77 (setq item (car (car members))
78 members (cdr members)
79 where (get item 'custom-where))
80 (unless (or (null where)
81 (member where found))
82 (if found
83 (insert " ")
84 (insert "(put '" (symbol-name symbol)
85 " 'custom-loads '("))
a9d3a78b 86 (prin1 where (current-buffer))
860af8ec 87 (push where found)))
a9d3a78b
PA
88 (when found
89 (insert "))\n"))))))
8cd58e14
PA
90 (insert "\
91
92\(provide 'cus-load)
93
94;;; cus-load.el ends here\n")
c9aadf03
RS
95 (let ((kept-new-versions 10000000))
96 (save-buffer))
efbdca12
RS
97 (message "Generating cus-load.el...done")
98 (kill-emacs))
860af8ec
PA
99
100;;; cus-dep.el ends here