diff lisp/bytecomp.el @ 4289:20accccbebd6

[xemacs-hg @ 2007-11-27 22:15:32 by aidan] Byte compile defcustom init values; save the Lisp values for correct editing, correct some comments and indentation, and expose some lambda expressions to the byte compile; make custom-initialize-changed a defubst, since it's only called from one place and calls to that place cluster.
author aidan
date Tue, 27 Nov 2007 22:15:34 +0000
parents adecfd791c9b
children 27150c937a22
line wrap: on
line diff
--- a/lisp/bytecomp.el	Tue Nov 27 15:38:40 2007 +0000
+++ b/lisp/bytecomp.el	Tue Nov 27 22:15:34 2007 +0000
@@ -2376,13 +2376,40 @@
 (put 'custom-declare-variable 'byte-hunk-handler
      'byte-compile-file-form-custom-declare-variable)
 (defun byte-compile-file-form-custom-declare-variable (form)
-  (if (memq 'free-vars byte-compile-warnings)
-      (setq byte-compile-bound-variables
-	    (cons (cons (nth 1 (nth 1 form))
-			byte-compile-global-bit)
-		  byte-compile-bound-variables)))
-  form)
-
+  ;; XEmacs change; our implementation byte compiles and gives warnings
+  ;; about the default value code, which GNU's doesn't.
+  (let* ((quoted-default (car-safe (cdr-safe (cdr-safe form))))
+         (to-examine (car-safe (cdr-safe quoted-default))))
+    (if (memq 'free-vars byte-compile-warnings)
+        (setq byte-compile-bound-variables
+              (cons (cons (nth 1 (nth 1 form))
+                          byte-compile-global-bit)
+                    byte-compile-bound-variables)))
+    ;; Byte compile anything that smells like a lambda. I initially
+    ;; considered limiting it to the :initialize, :set and :get args, but
+    ;; that's not amazingly forward-compatible, and anyone expecting other
+    ;; things to be stored as data, not code, is unrealistic. 
+     (loop
+       for entry in-ref (nthcdr 4 form)
+       do (cond ((and (eq 'function (car-safe entry))
+                      (consp (car-safe (cdr-safe entry))))
+                 (setf entry (copy-sequence entry))
+                 (setcar (cdr entry) (byte-compile-lambda (car (cdr entry)))))
+                ((and (eq 'lambda (car-safe entry)))
+                 (setf entry (byte-compile-lambda entry)))))
+     ;; Byte compile the default value, as we do for defvar. 
+     (when (consp (cdr-safe to-examine))
+       (setq form (copy-sequence form))
+       (setcdr (third form)
+               (list (byte-compile-top-level to-examine nil 'file)))
+       ;; And save a value to be examined in the custom UI, if that differs
+       ;; from the init value.
+       (unless (equal to-examine (car-safe (cdr (third form))))
+         (setf (nthcdr 4 form) (nconc
+                                (list :default 
+                                      (list 'quote to-examine))
+                                (nthcdr 4 form)))))
+    form))
 
 ;;;###autoload
 (defun byte-compile (form)