diff lisp/custom/cus-dep.el @ 207:e45d5e7c476e r20-4b2

Import from CVS: tag r20-4b2
author cvs
date Mon, 13 Aug 2007 10:03:52 +0200
parents 850242ba4a81
children
line wrap: on
line diff
--- a/lisp/custom/cus-dep.el	Mon Aug 13 10:02:48 2007 +0200
+++ b/lisp/custom/cus-dep.el	Mon Aug 13 10:03:52 2007 +0200
@@ -33,7 +33,7 @@
 ;; This file generates the custom-load files, loaded by cus-load.el.
 ;; The only entry point is `Custom-make-dependencies'.
 
-;; It works so that it scans all the `.el' files in a directory, and
+;; It works by scanning all the `.el' files in a directory, and
 ;; evaluates any `defcustom', `defgroup', or `defface' expression that
 ;; it finds.  The symbol changed by this expression is stored to a
 ;; hash table as the hash key, file name being the value.
@@ -50,14 +50,20 @@
 ;; custom-loads around, and have them loaded by `cus-load.el' (as
 ;; invoked by `cus-edit.el').
 
-;; A trivial, but crucial optimization is that if cusload-file exists,
+;; A trivial, but useful optimization is that if cusload-file exists,
 ;; and no .el files in the directory are newer than cusload-file, it
 ;; will not be generated.  This means that the directories where
 ;; nothing has changed will be skipped.
 
-;; The `custom-put' function, generated by this file, is a specialized
-;; form of `put' that deals with lists, eliminating the duplicates.
-;; For instance:
+;; The `custom-put' function, used by files generated by
+;; `Custom-make-dependencies', is a specialized function that updates
+;; a property (which must be a list of strings) with a new list of
+;; strings, eliminating the duplicates.  As it also adds an
+;; appropriate entry to a custom hash-table, *do not* use it outside
+;; of custom.  Its inner workings can change anytime, without prior
+;; notice.  `custom-put' is defined in `cus-load.el'.
+
+;; Example:
 
 ;; (custom-put 'foo 'custom-loads '("bar" "baz"))
 ;; (get 'foo 'custom-loads)
@@ -83,6 +89,10 @@
 ;; cus-start.el, too.
 (defconst cusload-base-file "custom-load.el")
 
+;; Be very careful when changing this function.  It looks easy to
+;; understand, but is in fact very easy to break.  Be sure to read and
+;; understand the commentary above!
+
 ;;;###autoload
 (defun Custom-make-dependencies (&optional subdirs)
   "Extract custom dependencies from .el files in SUBDIRS.
@@ -106,7 +116,7 @@
 	(princ (format "Processing %s\n" dir))
 	(let ((cusload-file (expand-file-name cusload-base-file dir))
 	      (files (directory-files dir t "\\`[^=].*\\.el\\'")))
-	  ;; A trivial optimization: if no files in the directory is
+	  ;; A trivial optimization: if no file in the directory is
 	  ;; newer than custom-load.el, no need to do anything!
 	  (if (and (file-exists-p cusload-file)
 		   (dolist (file files t)
@@ -121,15 +131,17 @@
 		(goto-char (point-min))
 		(let ((name (file-name-sans-extension
 			     (file-name-nondirectory file))))
-		  (condition-case nil
-		      (while (re-search-forward
-			      "^(defcustom\\|^(defface\\|^(defgroup"
-			      nil t)
-			(beginning-of-line)
-			(let ((expr (read (current-buffer))))
-			  (eval expr)
-			  (setf (gethash (nth 1 expr) hash) name)))
-		    (error nil)))))
+		  ;; Search for defcustom/defface/defgroup
+		  ;; expressions, and evaluate them.
+		  (ignore-errors
+		    (while (re-search-forward
+			    "^(defcustom\\|^(defface\\|^(defgroup"
+			    nil t)
+		      (beginning-of-line)
+		      (let ((expr (read (current-buffer))))
+			(eval expr)
+			;; Hash the file of the affected symbol.
+			(setf (gethash (nth 1 expr) hash) name)))))))
 	    (cond
 	     ((zerop (hash-table-count hash))
 	      (princ "(No customization dependencies")
@@ -142,8 +154,7 @@
 	      (with-temp-file cusload-file
 		(insert ";;; " cusload-base-file
 			" --- automatically extracted custom dependencies\n"
-			"\n;; Created by " (user-full-name) " on "
-			(current-time-string) "\n\n;;; Code:\n\n")
+			"\n\n;;; Code:\n\n")
 		(mapatoms
 		 (lambda (sym)
 		   (let ((members (get sym 'custom-group))
@@ -157,8 +168,8 @@
 				     (member where found))
 			   (if found
 			       (insert " ")
-			     (insert "(custom-put '" (symbol-name sym)
-				     " 'custom-loads '("))
+			     (insert "(custom-add-loads '"
+				     (symbol-name sym) " '("))
 			   (prin1 where (current-buffer))
 			   (push where found)))
 		       (when found