Use find-file-hook instead of find-file-hooks.
[bpt/emacs.git] / lisp / custom.el
index c016981..7466913 100644 (file)
@@ -1,7 +1,7 @@
 ;;; custom.el --- tools for declaring and initializing options
 ;;
 ;; Copyright (C) 1996, 1997, 1999, 2001, 2002, 2003, 2004,
-;;   2005, 2006 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 ;;
 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
 ;; Maintainer: FSF
@@ -11,7 +11,7 @@
 
 ;; GNU Emacs 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)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -168,6 +168,10 @@ set to nil, as the value is no longer rogue."
                 (put symbol 'custom-get value))
                ((eq keyword :require)
                 (push value requests))
+               ((eq keyword :risky)
+                (put symbol 'risky-local-variable value))
+               ((eq keyword :safe)
+                (put symbol 'safe-local-variable value))
                ((eq keyword :type)
                 (put symbol 'custom-type (purecopy value)))
                ((eq keyword :options)
@@ -210,15 +214,17 @@ The following keywords are meaningful:
        `custom-initialize-reset'.
 :set   VALUE should be a function to set the value of the symbol.
        It takes two arguments, the symbol to set and the value to
-       give it.  The default choice of function is `custom-set-default'.
+       give it.  The default choice of function is `set-default'.
 :get   VALUE should be a function to extract the value of symbol.
        The function takes one argument, a symbol, and should return
        the current value for that symbol.  The default choice of function
-       is `custom-default-value'.
+       is `default-value'.
 :require
        VALUE should be a feature symbol.  If you save a value
        for this option, then when your `.emacs' file loads the value,
        it does (require VALUE) first.
+:risky Set SYMBOL's `risky-local-variable' property to VALUE.
+:safe  Set SYMBOL's `safe-local-variable' property to VALUE.
 
 The following common keywords are also meaningful.
 
@@ -331,7 +337,7 @@ For a list of valid keywords, see the common keywords listed in
 
 SPEC should be an alist of the form ((DISPLAY ATTS)...).
 
-In the first element, DISPLAY can be :default.  The ATTS in that
+In the first element, DISPLAY can be `default'.  The ATTS in that
 element then act as defaults for all the following elements.
 
 Aside from that, DISPLAY specifies conditions to match some or
@@ -341,7 +347,7 @@ frame.  The ATTRs in this element take effect, and the following
 elements are ignored, on that frame.
 
 In the last element, DISPLAY can be t.  That element applies to a
-frame if none of the previous elements (except the :default if
+frame if none of the previous elements (except the `default' if
 any) did.
 
 ATTS is a list of face attributes followed by their values:
@@ -351,7 +357,7 @@ The possible attributes are `:family', `:width', `:height', `:weight',
 `:slant', `:underline', `:overline', `:strike-through', `:box',
 `:foreground', `:background', `:stipple', `:inverse-video', and `:inherit'.
 
-DISPLAY can be `:default' (only in the first element), the symbol
+DISPLAY can be `default' (only in the first element), the symbol
 t (only in the last element) to match all frames, or an alist of
 conditions of the form \(REQ ITEM...).  For such an alist to
 match a frame, each of the conditions must be satisfied, meaning
@@ -536,6 +542,7 @@ For other custom types, this has no effect."
   (let ((options (get symbol 'custom-options)))
     (unless (member option options)
       (put symbol 'custom-options (cons option options)))))
+(defalias 'custom-add-frequent-value 'custom-add-option)
 
 (defun custom-add-link (symbol widget)
   "To the custom option SYMBOL add the link WIDGET."
@@ -558,9 +565,10 @@ LOAD should be either a library file name, or a feature name."
     (unless (member load loads)
       (put symbol 'custom-loads (cons (purecopy load) loads)))))
 
-(defun custom-autoload (symbol load)
-  "Mark SYMBOL as autoloaded custom variable and add dependency LOAD."
-  (put symbol 'custom-autoload t)
+(defun custom-autoload (symbol load &optional noset)
+  "Mark SYMBOL as autoloaded custom variable and add dependency LOAD.
+If NOSET is non-nil, don't bother autoloading LOAD when setting the variable."
+  (put symbol 'custom-autoload (if noset 'noset t))
   (custom-add-load symbol load))
 
 ;; This test is also in the C code of `user-variable-p'.
@@ -571,6 +579,15 @@ This recursively follows aliases."
   (or (get variable 'standard-value)
       (get variable 'custom-autoload)))
 
+(defun custom-note-var-changed (variable)
+  "Inform Custom that VARIABLE has been set (changed).
+VARIABLE is a symbol that names a user option.
+The result is that the change is treated as having been made through Custom."
+  (put variable 'customized-value (list (custom-quote (eval variable)))))
+
+\f
+;;; Custom Themes
+
 ;;; Loading files needed to customize a symbol.
 ;;; This is in custom.el because menu-bar.el needs it for toggle cmds.
 
@@ -640,7 +657,7 @@ this sets the local binding in that buffer instead."
     (funcall variable (if value 1 0))))
 
 (defun custom-quote (sexp)
-  "Quote SEXP iff it is not self quoting."
+  "Quote SEXP if it is not self quoting."
   (if (or (memq sexp '(t nil))
          (keywordp sexp)
          (and (listp sexp)
@@ -663,14 +680,14 @@ default value.  Otherwise, set it to nil.
 
 To actually save the value, call `custom-save-all'.
 
-Return non-nil iff the `saved-value' property actually changed."
+Return non-nil if the `saved-value' property actually changed."
   (custom-load-symbol symbol)
   (let* ((get (or (get symbol 'custom-get) 'default-value))
         (value (funcall get symbol))
         (saved (get symbol 'saved-value))
         (standard (get symbol 'standard-value))
         (comment (get symbol 'customized-variable-comment)))
-    ;; Save default value iff different from standard value.
+    ;; Save default value if different from standard value.
     (if (or (null standard)
            (not (equal value (condition-case nil
                                  (eval (car standard))
@@ -692,17 +709,17 @@ or else if it is different from the standard value, set the
 `customized-value' property to a list whose car evaluates to the
 default value.  Otherwise, set it to nil.
 
-Return non-nil iff the `customized-value' property actually changed."
+Return non-nil if the `customized-value' property actually changed."
   (custom-load-symbol symbol)
   (let* ((get (or (get symbol 'custom-get) 'default-value))
         (value (funcall get symbol))
         (customized (get symbol 'customized-value))
         (old (or (get symbol 'saved-value) (get symbol 'standard-value))))
-    ;; Mark default value as set iff different from old value.
-    (if (or (null old)
-           (not (equal value (condition-case nil
-                                 (eval (car old))
-                               (error nil)))))
+    ;; Mark default value as set if different from old value.
+    (if (not (and old
+                  (equal value (condition-case nil
+                                   (eval (car old))
+                                 (error nil)))))
        (progn (put symbol 'customized-value (list (custom-quote value)))
               (custom-push-theme 'theme-value symbol 'user 'set
                                  (custom-quote value)))
@@ -827,13 +844,9 @@ See `custom-known-themes' for a list of known themes."
            (if (and (eq prop 'theme-value)
                     (boundp symbol))
                (let ((sv (get symbol 'standard-value)))
-                 (when (and (null sv) (custom-variable-p symbol))
-                   (custom-load-symbol symbol)
-                   (setq sv (get symbol 'standard-value)))
-                 (if (or (null sv)
-                         (not (equal (eval (car (get symbol 'standard-value)))
-                                     (symbol-value symbol))))
-                     (setq old (list (list 'changed (symbol-value symbol))))))
+                 (unless (and sv
+                               (equal (eval (car sv)) (symbol-value symbol)))
+                    (setq old (list (list 'changed (symbol-value symbol))))))
              (if (and (facep symbol)
                       (not (face-spec-match-p symbol (get symbol 'face-defface-spec))))
                  (setq old (list (list 'changed (list
@@ -877,6 +890,18 @@ COMMENT is a comment string about SYMBOL.
 EXP itself is saved unevaluated as SYMBOL property `saved-value' and
 in SYMBOL's list property `theme-value' \(using `custom-push-theme')."
   (custom-check-theme theme)
+  ;; Process all the needed autoloads before anything else, so that the
+  ;; subsequent code has all the info it needs (e.g. which var corresponds
+  ;; to a minor mode), regardless of the ordering of the variables.
+  (dolist (entry args)
+    (let* ((symbol (indirect-variable (nth 0 entry))))
+      (unless (or (get symbol 'standard-value)
+                  (memq (get symbol 'custom-autoload) '(nil noset)))
+        ;; This symbol needs to be autoloaded, even just for a `set'.
+        (custom-load-symbol symbol))))
+  ;; Move minor modes and variables with explicit requires to the end.
   (setq args
        (sort args
              (lambda (a1 a2)
@@ -926,6 +951,8 @@ in SYMBOL's list property `theme-value' \(using `custom-push-theme')."
            (setq args (cdr args))
            (and (or now (default-boundp symbol))
                 (put symbol 'variable-comment comment)))
+        ;; I believe this is dead-code, because the `sort' code above would
+        ;; have burped before we could get here.  --Stef
        ;; Old format, a plist of SYMBOL VALUE pairs.
        (message "Warning: old format `custom-set-variables'")
        (ding)
@@ -997,10 +1024,7 @@ Every theme X has a property `provide-theme' whose value is \"X-theme\".
 ;;; Loading themes.
 
 (defcustom custom-theme-directory
-  (if (eq system-type 'ms-dos)
-        ;; MS-DOS cannot have initial dot.
-        "~/_emacs.d/"
-      "~/.emacs.d/")
+  user-emacs-directory
   "Directory in which Custom theme files should be written.
 `load-theme' searches this directory in addition to load-path.
 The command `customize-create-theme' writes the files it produces
@@ -1152,9 +1176,9 @@ This function returns nil if no custom theme specifies a value for VARIABLE."
 (defun custom-theme-recalc-face (face)
   "Set FACE according to currently enabled custom themes."
   (if (facep face)
-      (let ((theme-faces (reverse (get face 'theme-face))))
-       (dolist (spec theme-faces)
-         (face-spec-set face (cadr spec))))))
+      (face-spec-set face
+                     (get (or (get face 'face-alias) face)
+                          'face-override-spec))))
 \f
 ;;; XEmacs compability functions