annotate lisp/custom/cus-dep.el @ 203:850242ba4a81 r20-3b28

Import from CVS: tag r20-3b28
author cvs
date Mon, 13 Aug 2007 10:02:21 +0200
parents 169c0442b401
children e45d5e7c476e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
1 ;;; cus-dep.el --- Find customization dependencies.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
2 ;;
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
4 ;;
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>, then
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
6 ;; Richar Stallman <rms@gnu.ai.mit.edu>, then
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
7 ;; Hrvoje Niksic <hniksic@srce.hr> (rewritten for XEmacs)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
8 ;; Maintainer: Hrvoje Niksic <hniksic@srce.hr>
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
9 ;; Keywords: internal
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
10
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
12
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
16 ;; any later version.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
17
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful,
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
21 ;; GNU General Public License for more details.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
22
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
27
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
28 ;;; Synched up with: Not synched with FSF.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
29
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
30
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
31 ;;; Commentary:
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
32
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
33 ;; This file generates the custom-load files, loaded by cus-load.el.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
34 ;; The only entry point is `Custom-make-dependencies'.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
35
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
36 ;; It works so that it scans all the `.el' files in a directory, and
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
37 ;; evaluates any `defcustom', `defgroup', or `defface' expression that
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
38 ;; it finds. The symbol changed by this expression is stored to a
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
39 ;; hash table as the hash key, file name being the value.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
40
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
41 ;; After all the files have been examined, custom-loads.el is
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
42 ;; generated by mapping all the atoms, and seeing if any of them
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
43 ;; contains a `custom-group' property. This property is a list whose
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
44 ;; each element's car is the "child" group symbol. If that property
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
45 ;; is in the hash-table, the file name will be looked up from the
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
46 ;; hash-table, and added to cusload-file. Because the hash-table is
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
47 ;; cleared whenever we process a new directory, we cannot get confused
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
48 ;; by custom-loads from another directory, or from a previous
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
49 ;; installation. This is also why it is perfectly safe to have old
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
50 ;; custom-loads around, and have them loaded by `cus-load.el' (as
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
51 ;; invoked by `cus-edit.el').
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
52
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
53 ;; A trivial, but crucial optimization is that if cusload-file exists,
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
54 ;; and no .el files in the directory are newer than cusload-file, it
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
55 ;; will not be generated. This means that the directories where
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
56 ;; nothing has changed will be skipped.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
57
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
58 ;; The `custom-put' function, generated by this file, is a specialized
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
59 ;; form of `put' that deals with lists, eliminating the duplicates.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
60 ;; For instance:
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
61
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
62 ;; (custom-put 'foo 'custom-loads '("bar" "baz"))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
63 ;; (get 'foo 'custom-loads)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
64 ;; => ("bar" "baz")
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
65 ;;
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
66 ;; (custom-put 'foo 'custom-loads '("hmph" "baz" "quz"))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
67 ;; (get 'foo 'custom-loads)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
68 ;; => ("bar" "baz" "hmph" "qux")
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
69
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
70 ;; Obviously, this allows correct incremental loading of custom-load
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
71 ;; files. This is not necessary under FSF (they use a simple `put'),
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
72 ;; since they have only *one* file. With the advent of packages, we
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
73 ;; cannot afford the same luxury.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
74
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
75
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
76 ;;; Code:
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
77
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
78 (require 'cl)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
79 (require 'widget)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
80 (require 'cus-face)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
81
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
82 ;; Don't change this, unless you plan to change the code in
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
83 ;; cus-start.el, too.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
84 (defconst cusload-base-file "custom-load.el")
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
85
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
86 ;;;###autoload
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
87 (defun Custom-make-dependencies (&optional subdirs)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
88 "Extract custom dependencies from .el files in SUBDIRS.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
89 SUBDIRS is a list of directories. If it is nil, the command-line
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
90 arguments are used. If it is a string, only that directory is
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
91 processed. This function is especially useful in batch mode.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
92
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
93 Batch usage: xemacs -batch -l cus-dep.el -f Custom-make-dependencies DIRS"
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
94 (interactive "DDirectory: ")
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
95 (and (stringp subdirs)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
96 (setq subdirs (list subdirs)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
97 (or subdirs
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
98 ;; Usurp the command-line-args
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
99 (setq subdirs command-line-args-left
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
100 command-line-args-left nil))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
101 (setq subdirs (mapcar #'expand-file-name subdirs))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
102 (with-temp-buffer
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
103 (let ((enable-local-eval nil)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
104 (hash (make-hash-table :test 'eq)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
105 (dolist (dir subdirs)
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
106 (princ (format "Processing %s\n" dir))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
107 (let ((cusload-file (expand-file-name cusload-base-file dir))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
108 (files (directory-files dir t "\\`[^=].*\\.el\\'")))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
109 ;; A trivial optimization: if no files in the directory is
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
110 ;; newer than custom-load.el, no need to do anything!
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
111 (if (and (file-exists-p cusload-file)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
112 (dolist (file files t)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
113 (when (file-newer-than-file-p file cusload-file)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
114 (return nil))))
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
115 (princ "(No changes need to be written)\n")
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
116 ;; Process directory
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
117 (dolist (file files)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
118 (when (file-exists-p file)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
119 (erase-buffer)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
120 (insert-file-contents file)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
121 (goto-char (point-min))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
122 (let ((name (file-name-sans-extension
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
123 (file-name-nondirectory file))))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
124 (condition-case nil
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
125 (while (re-search-forward
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
126 "^(defcustom\\|^(defface\\|^(defgroup"
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
127 nil t)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
128 (beginning-of-line)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
129 (let ((expr (read (current-buffer))))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
130 (eval expr)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
131 (setf (gethash (nth 1 expr) hash) name)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
132 (error nil)))))
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
133 (cond
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
134 ((zerop (hash-table-count hash))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
135 (princ "(No customization dependencies")
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
136 (when (file-exists-p cusload-file)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
137 (princ (format ", deleting %s" cusload-file))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
138 (delete-file cusload-file))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
139 (princ ")\n"))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
140 (t
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
141 (princ (format "Generating %s...\n" cusload-base-file))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
142 (with-temp-file cusload-file
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
143 (insert ";;; " cusload-base-file
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
144 " --- automatically extracted custom dependencies\n"
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
145 "\n;; Created by " (user-full-name) " on "
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
146 (current-time-string) "\n\n;;; Code:\n\n")
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
147 (mapatoms
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
148 (lambda (sym)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
149 (let ((members (get sym 'custom-group))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
150 item where found)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
151 (when members
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
152 (while members
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
153 (setq item (car (car members))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
154 members (cdr members)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
155 where (gethash item hash))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
156 (unless (or (null where)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
157 (member where found))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
158 (if found
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
159 (insert " ")
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
160 (insert "(custom-put '" (symbol-name sym)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
161 " 'custom-loads '("))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
162 (prin1 where (current-buffer))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
163 (push where found)))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
164 (when found
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
165 (insert "))\n"))))))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
166 (insert "\n;;; custom-load.el ends here\n"))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 199
diff changeset
167 (clrhash hash)))))))))
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
168
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
169 (provide 'cus-dep)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
170
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
171 ;;; cus-dep.el ends here