From xemacs-m  Sun Sep 14 08:34:29 1997
Received: from jagor.srce.hr (hniksic@jagor.srce.hr [161.53.2.130])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id IAA27361
	for <xemacs-beta@xemacs.org>; Sun, 14 Sep 1997 08:34:15 -0500 (CDT)
Received: (from hniksic@localhost)
	by jagor.srce.hr (8.8.7/8.8.6) id PAA23368;
	Sun, 14 Sep 1997 15:34:07 +0200 (MET DST)
To: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: Re: Customization groups
References: <kigu3fo1o42.fsf@jagor.srce.hr> <m23en8pfgr.fsf@altair.xemacs.org> <kigwwkkupdj.fsf@jagor.srce.hr>
X-Attribution: Hrvoje
X-Face: Mie8:rOV<\c/~z{s.X4A{!?vY7{drJ([U]0O=W/<W*SMo/Mv:58:*_y~ki>xDi&N7XG
        KV^$k0m3Oe/)'e%3=$PCR&3ITUXH,cK>]bci&<qQ>Ff%x_>1`T(+M2Gg/fgndU%k*ft
        [(7._6e0n-V%|%'[c|q:;}td$#INd+;?!-V=c8Pqf}3J
From: Hrvoje Niksic <hniksic@srce.hr>
Date: 14 Sep 1997 15:34:07 +0200
In-Reply-To: Hrvoje Niksic's message of "14 Sep 1997 13:05:44 +0200"
Message-ID: <kigg1r89fzk.fsf@jagor.srce.hr>
Lines: 427
X-Mailer: Gnus v5.4.65/XEmacs 20.3(beta20) - "Tirana"

Hrvoje Niksic <hniksic@srce.hr> writes:

> Yup.  For instance, it has a line that says:
> 
> (put 'languages 'custom-loads '("cus-edit" "sgml-mode" "ada-mode" "fortran" "hideshow" "icon" "pascal" "prolog" "sh-script"))
> 
> ...and we don't have one.  I'll try to figure out why.

OK, I think I got it...  Many things were lacking in our
implementation.

I have defined a new function `custom-add-loads' for use in
`custom-load.el' files.  It *adds* a list to the existing
`custom-loads' list property of a symbol.  All `custom-load' files now 
use that.

So, a `custom-load' now typically contains:

...
(custom-add-loads 'fortran '("f90" "fortran"))
(custom-add-loads 'resize-minibuffer '("rsz-minibuf"))
(custom-add-loads 'languages '("asm-mode" "fortran" "icon" "pascal" "prolog" "rexx-mode" "sh-script" "simula" "tcl" "verilog-mode" "vhdl-mode" "vrml-mode" "winmgr-mode" "xrdb-mode"))
(custom-add-loads 'display '("auto-show"))
...

This is much more appropriate for multiple `custom-load.el's, because
if some other custom-load.el also adds `languages', they will be
appended to the existing lists.  To test the changes, apply the
following patches (and note that the patches create a new
lisp/prim/cus-dep.el file), byte-compile the changed files, remove all
your **/custom-load.el* files and run:

./src/xemacs -batch -l cus-dep.el -f custom-make-dependencies lisp/*(/)

# (that was zsh-ese)

People, please test it out and let me know if `xemacs -q' followed by
`M-x customize-group RET languages RET' gives all of the languages.

Note to Per: there seemed to be a bug in cus-edit that prevented the
creation of menus on time.  I think custom-load-symbol should be
called *before* trying to create a menu.  Please check it up.

Steve: please check whether my deletions in autoload.el have been too
generous.


1997-09-14  Hrvoje Niksic  <hniksic@srce.hr>

	* utils/autoload.el: Don't do custom stuff.

	* prim/cus-load.el: Simplify loading.

	* prim/cus-load.el (custom-add-loads): New function.

	* prim/cus-dep.el: New file.
	(custom-make-dependencies): Fix it, so it works.

	* custom/cus-edit.el (custom-menu-create): First load symbol
	dependencies, then create menus.

--- /dev/null	Sun Sep 14 15:30:06 1997
+++ lisp/prim/cus-dep.el	Sun Sep 14 15:27:20 1997
@@ -0,0 +1,104 @@
+;;; cus-dep.el --- Find customization dependencies.
+;;
+;; Copyright (C) 1997 Free Software Foundation, Inc.
+;;
+;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
+;; Maintainer: Hrvoje Niksic <hniksic@srce.hr>      (for XEmacs version)
+;; Keywords: internal
+
+;; This file is part of XEmacs.
+
+;; XEmacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; XEmacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with XEmacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Code:
+
+(require 'cl)
+(require 'widget)
+(require 'cus-edit)
+(require 'cus-face)
+
+(defun custom-make-dependencies ()
+  "Batch function to extract custom dependencies from .el files.
+Usage: xemacs -batch -l cus-dep.el -f custom-make-dependencies DIRS"
+  (let ((enable-local-eval nil)
+	(all-subdirs (mapcar 'expand-file-name command-line-args-left))
+	(hash (make-hash-table :test 'eq)))
+    (get-buffer-create " cus-dep temp")
+    (set-buffer " cus-dep temp")
+    (while all-subdirs
+      (message "Directory %s" (car all-subdirs))
+      (let ((files (directory-files (car all-subdirs) nil "\\`[^=].*\\.el\\'"))
+	    (default-directory default-directory)
+	    (custom-load (expand-file-name "custom-load.el" (car all-subdirs)))
+	    file)
+	(cd (car all-subdirs))
+	(while files
+	  (setq file (car files)
+		files (cdr files))
+	  (when (file-exists-p file)
+	    (erase-buffer)
+	    (insert-file-contents file)
+	    (goto-char (point-min))
+	    (string-match "\\`\\(.*\\)\\.el\\'" file)
+	    (let ((name (file-name-nondirectory (match-string 1 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)))))
+	(message "Generating %s..." custom-load)
+	(find-file custom-load)
+	(erase-buffer)
+	(insert "\
+;;; custom-load.el --- automatically extracted custom dependencies
+;;
+;;; Code:\n\n")
+	(mapatoms (lambda (sym)
+		    (let ((members (get sym 'custom-group))
+			  item where found)
+		      (when members
+			(while members
+			  (setq item (car (car members))
+				members (cdr members)
+				where (gethash item hash))
+			  (unless (or (null where)
+				      (member where found))
+			    (if found
+			       (insert " ")
+			     (insert "(custom-add-loads '" (symbol-name sym)
+				     " '("))
+			   (prin1 where (current-buffer))
+			   (push where found)))
+		       (when found
+			 (insert "))\n"))))))
+	(insert "\
+
+\(provide 'cus-load)
+
+;;; cus-load.el ends here\n")
+	(let ((kept-new-versions 10000000))
+	  (save-buffer))
+;;	(message "Generating %s...done" custom-load)
+	(clrhash hash)
+	(setq all-subdirs (cdr all-subdirs)))))
+    (kill-emacs))
+
+;;; cus-dep.el ends here
+  
+
--- lisp/prim/cus-load.el.orig	Sun Sep 14 13:22:16 1997
+++ lisp/prim/cus-load.el	Sun Sep 14 14:40:37 1997
@@ -30,14 +30,16 @@
 
 ;;; Code:
 
-(fset 'custom-put 'put)
+(defun custom-add-loads (symbol list)
+  (let ((loads (get symbol 'custom-loads)))
+    (dolist (el list)
+      (unless (member el loads)
+	(setq loads (nconc loads (list el)))))
+    (put symbol 'custom-loads loads)))
 
-(let ((dir load-path))
-  (while dir
-    (condition-case nil
-	(load (concat (car dir) "custom-load") nil nil)
-      (file-error nil))
-    (pop dir)))
+(mapc (lambda (dir)
+	(load (expand-file-name "custom-load" dir) t))
+      load-path)
 
 (provide 'cus-load)
 
--- lisp/custom/cus-edit.el.orig	Sun Sep 14 14:55:39 1997
+++ lisp/custom/cus-edit.el	Sun Sep 14 15:11:56 1997
@@ -3096,22 +3096,23 @@
     (if (and (or (not (boundp 'custom-menu-nesting))
 		 (>= custom-menu-nesting 0))
 	     (< (length (get symbol 'custom-group)) widget-menu-max-size))
-	(let ((custom-prefix-list (custom-prefix-add symbol
-						     custom-prefix-list))
-	      (members (custom-sort-items (get symbol 'custom-group)
-					  custom-menu-sort-alphabetically
-					  custom-menu-order-groups)))
+	(progn
 	  (custom-load-symbol symbol)
-	  `(,(custom-unlispify-menu-entry symbol t)
-	    ,item
-	    "--"
-	    ,@(mapcar (lambda (entry)
-			(widget-apply (if (listp (nth 1 entry))
-					  (nth 1 entry)
-					(list (nth 1 entry)))
-				      :custom-menu (nth 0 entry)))
-		      members)))
-      item)))
+	  (let ((custom-prefix-list (custom-prefix-add symbol
+						       custom-prefix-list))
+		(members (custom-sort-items (get symbol 'custom-group)
+					    custom-menu-sort-alphabetically
+					    custom-menu-order-groups)))
+	    `(,(custom-unlispify-menu-entry symbol t)
+	      ,item
+	      "--"
+	      ,@(mapcar (lambda (entry)
+			  (widget-apply (if (listp (nth 1 entry))
+					    (nth 1 entry)
+					  (list (nth 1 entry)))
+					:custom-menu (nth 0 entry)))
+			members))))
+	  item)))
 
 ;;;###autoload
 (defun customize-menu-create (symbol &optional name)
--- lisp/utils/autoload.el.orig	Sun Sep 14 15:15:17 1997
+++ lisp/utils/autoload.el	Sun Sep 14 15:31:39 1997
@@ -349,55 +349,16 @@
 A .el file can set this in its local variables section to make its
 autoloads go somewhere else.")
 
-(defconst cusload-file-name "custom-load.el"
-  "Generic filename ot put custom loads into.
-Unless you are an XEmacs maintainr, it is probably unwise to change this.")
-
-(defvar generated-custom-file
-  (expand-file-name (concat autoload-target-directory
-			    cusload-file-name)
-		    data-directory)
-  "*File `update-file-autoloads' puts customization into.")
-
-(defvar customized-symbols nil)
-
-;; Written by Per Abrahamsen
-(defun autoload-snarf-defcustom (file)
-  "Snarf all customizations in the current buffer."
-  (let ((visited (get-file-buffer file)))
-    (save-excursion
-      (set-buffer (or visited (find-file-noselect file)))
-      (when (and file
-		 (string-match "\\`\\(.*\\)\\.el\\'" file)
-		 (not (buffer-modified-p)))
-	(goto-char (point-min))
-	(condition-case nil
-	    (let ((name (file-name-nondirectory (match-string 1 file))))
-	      (while t
-		(let ((expr (read (current-buffer))))
-		  (when (and (listp expr)
-			     (memq (car expr) '(defcustom defface defgroup)))
-		    (eval expr)
-		    (put (nth 1 expr) 'custom-where name)
-		    (pushnew (nth 1 expr) customized-symbols)))))
-	  (error nil)))
-      (unless (buffer-modified-p)
-	(kill-buffer (current-buffer))))))
-
-(defvar autoload-do-custom-save nil)
-
 ;;;###autoload
 (defun update-file-autoloads (file)
   "Update the autoloads for FILE in `generated-autoload-file'
 \(which FILE might bind in its local variables).
-This functions refuses to update autolaods files and custom loads."
+This functions refuses to update autoloads files."
   (interactive "fUpdate autoloads for file: ")
   (setq file (expand-file-name file))
   (when (and (file-newer-than-file-p file generated-autoload-file)
-	     (not (member (file-name-nondirectory file)
-			  (list autoload-file-name cusload-file-name))))
-
-    (setq autoload-do-custom-save t)
+	     (not (equal (file-name-nondirectory file)
+			 autoload-file-name)))
     (let ((load-name (replace-in-string (file-name-nondirectory file)
 					"\\.elc?$"
 					""))
@@ -430,8 +391,7 @@
 	    (goto-char (point-max))))	; Append.
 
 	;; Add in new sections for file
-	(generate-file-autoloads file)
-	(autoload-snarf-defcustom file))
+	(generate-file-autoloads file))
 
       (when (interactive-p) (save-buffer)))))
 
@@ -491,7 +451,6 @@
 This runs `update-file-autoloads' on each .el file in DIR.
 Obsolete autoload entries for files that no longer exist are deleted."
   (interactive "DUpdate autoloads for directory: ")
-  (setq autoload-do-custom-save nil)
   (setq dir (expand-file-name dir))
   (let ((simple-dir (file-name-as-directory
 		     (file-name-nondirectory
@@ -520,48 +479,6 @@
       (unless noninteractive
 	(save-buffer)))))
 
-;; Based on code from Per Abrahamsen
-(defun autoload-save-customization ()
-  (save-excursion
-    (set-buffer (find-file-noselect generated-custom-file))
-    (erase-buffer)
-    (insert
-     (with-output-to-string
-      (mapcar (lambda (symbol)
-		(let ((members (condition-case nil
-				   (get symbol 'custom-group)
-				 (t (progn
-				      (message "Bad plist in %s"
-					       (symbol-name symbol)))
-				    nil)))
-		      item where
-		      (found (condition-case nil
-				 (get symbol 'custom-loads)
-			       (t nil)))
-		      )
-		  (when (or members found)
-		    (princ "(custom-put '")
-		    (princ symbol)
-		    (princ " 'custom-loads '(")
-		    (when found
-		      ;; (message "found = `%s'" found)
-		      (insert (mapconcat 'prin1-to-string found " ")))
-		    (while members
-		      (setq item (car (car members))
-			    members (cdr members)
-			    where (get item 'custom-where))
-		      (unless (or (null where)
-				  (member where found))
-			;; (message "where = `%s', found = `%s'" where found)
-			(when found
-			  (princ " "))
-			(prin1 where)
-			(push where found)))
-		    (princ "))\n"))))
-	      customized-symbols)))
-    (when (= (point-min) (point-max))
-      (set-buffer-modified-p nil))))
-
 ;;;###autoload
 (defun batch-update-autoloads ()
   "Update the autoloads for the files or directories on the command line.
@@ -569,18 +486,12 @@
 on directories.  Must be used only with -batch, and kills Emacs on completion.
 Each file will be processed even if an error occurred previously.
 For example, invoke `xemacs -batch -f batch-update-autoloads *.el'.
-The directory to which the auto-autoloads.el and custom-load.el files must
-be the first parameter on the command line."
+The directory to which the auto-autoloads.el file must be the first
+parameter on the command line."
   (unless noninteractive
     (error "batch-update-autoloads is to be used only with -batch"))
   (let ((defdir default-directory)
 	(enable-local-eval nil))	; Don't query in batch mode.
-    (when (file-exists-p generated-custom-file)
-      (flet ((custom-put (symbol property value)
-			  (progn
-			    (put symbol property value)
-			    (pushnew symbol customized-symbols))))
-	(load generated-custom-file nil t)))
     ;; (message "Updating autoloads in %s..." generated-autoload-file)
     (dolist (arg command-line-args-left)
       (setq arg (expand-file-name arg defdir))
@@ -591,8 +502,6 @@
        ((file-exists-p arg)
 	(update-file-autoloads arg))
        (t (error "No such file or directory: %s" arg))))
-    (when autoload-do-custom-save
-      (autoload-save-customization))
     (fixup-autoload-buffer (concat (file-name-nondirectory defdir)
 				   "-autoloads"))
     (save-some-buffers t)
@@ -625,25 +534,12 @@
 	(enable-local-eval nil))	; Don't query in batch mode.
     (dolist (arg command-line-args-left)
       (setq arg (expand-file-name arg defdir))
-      (let ((generated-autoload-file (concat arg "/" autoload-file-name))
-	    (generated-custom-file (concat arg "/" cusload-file-name)))
-	(when (file-exists-p generated-custom-file)
-	  (flet ((custom-put (symbol property value)
-			      (progn
-				(put symbol property value)
-				;; (message "Loading %s = %s"
-					 ;; (symbol-name symbol)
-					 ;; (prin1-to-string value))
-				(pushnew symbol customized-symbols))))
-	    (load generated-custom-file nil t)))
+      (let ((generated-autoload-file (concat arg "/" autoload-file-name)))
 	(cond
 	 ((file-directory-p arg)
 	  (message "Updating autoloads in directory %s..." arg)
 	  (update-autoloads-from-directory arg))
 	 (t (error "No such file or directory: %s" arg)))
-	(when autoload-do-custom-save
-	  (autoload-save-customization)
-	  (setq customized-symbols nil))
 	(fixup-autoload-buffer (concat (if autoload-package-name
 					   autoload-package-name
 					 (file-name-nondirectory arg))


-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
"Silence!" cries Freydag. "I did not call thee in for a consultation!" 
"They are my innards! I will not have them misread by a poseur!"

