annotate lisp/cus-dep.el @ 209:41ff10fd062f r20-4b3

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