annotate lisp/custom/cus-dep.el @ 195:a2f645c6b9f8 r20-3b24

Import from CVS: tag r20-3b24
author cvs
date Mon, 13 Aug 2007 09:59:05 +0200
parents
children 169c0442b401
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-edit)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
81 (require 'cus-face)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
82
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
83 ;; Don't change this, unless you plan to change the code in
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
84 ;; cus-start.el, too.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
85 (defconst cusload-base-file "custom-load.el")
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
86
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
87 ;;;###autoload
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
88 (defun Custom-make-dependencies (&optional subdirs)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
89 "Extract custom dependencies from .el files in SUBDIRS.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
90 SUBDIRS is a list of directories. If it is nil, the command-line
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
91 arguments are used. If it is a string, only that directory is
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
92 processed. This function is especially useful in batch mode.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
93
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
94 Batch usage: xemacs -batch -l cus-dep.el -f Custom-make-dependencies DIRS"
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
95 (interactive "DDirectory: ")
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
96 (and (stringp subdirs)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
97 (setq subdirs (list subdirs)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
98 (or subdirs
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
99 ;; Usurp the command-line-args
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
100 (setq subdirs command-line-args-left
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
101 command-line-args-left nil))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
102 (setq subdirs (mapcar #'expand-file-name subdirs))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
103 (with-temp-buffer
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
104 (let ((enable-local-eval nil)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
105 (hash (make-hash-table :test 'eq)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
106 (dolist (dir subdirs)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
107 (message "Processing %s" dir)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
108 (let ((cusload-file (expand-file-name cusload-base-file dir))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
109 (files (directory-files dir t "\\`[^=].*\\.el\\'")))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
110 ;; A trivial optimization: if no files in the directory is
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
111 ;; newer than custom-load.el, no need to do anything!
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
112 (if (and (file-exists-p cusload-file)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
113 (dolist (file files t)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
114 (when (file-newer-than-file-p file cusload-file)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
115 (return nil))))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
116 (message "No changes need to be written.")
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
117 ;; Process directory
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
118 (dolist (file files)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
119 (when (file-exists-p file)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
120 (erase-buffer)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
121 (insert-file-contents file)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
122 (goto-char (point-min))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
123 (let ((name (file-name-sans-extension
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
124 (file-name-nondirectory file))))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
125 (condition-case nil
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
126 (while (re-search-forward
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
127 "^(defcustom\\|^(defface\\|^(defgroup"
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
128 nil t)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
129 (beginning-of-line)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
130 (let ((expr (read (current-buffer))))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
131 (eval expr)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
132 (setf (gethash (nth 1 expr) hash) name)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
133 (error nil)))))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
134 (message "Generating %s..." cusload-base-file)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
135 (with-temp-file cusload-file
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
136 (insert ";;; " cusload-base-file
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
137 " --- automatically extracted custom dependencies\n"
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
138 "\n;; Created by " (user-full-name) " on "
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
139 (current-time-string) "\n\n;;; Code:\n\n")
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
140 (mapatoms
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
141 (lambda (sym)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
142 (let ((members (get sym 'custom-group))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
143 item where found)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
144 (when members
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
145 (while members
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
146 (setq item (car (car members))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
147 members (cdr members)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
148 where (gethash item hash))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
149 (unless (or (null where)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
150 (member where found))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
151 (if found
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
152 (insert " ")
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
153 (insert "(custom-put '" (symbol-name sym)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
154 " 'custom-loads '("))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
155 (prin1 where (current-buffer))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
156 (push where found)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
157 (when found
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
158 (insert "))\n"))))))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
159 (insert "\n;;; custom-load.el ends here\n"))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
160 (clrhash hash)))))))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
161
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
162 (provide 'cus-dep)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
163
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents:
diff changeset
164 ;;; cus-dep.el ends here