]> code.delx.au - gnu-emacs/commitdiff
Avoid calling customize-save-variable during startup (Bug#8720).
authorChong Yidong <cyd@stupidchicken.com>
Thu, 30 Jun 2011 01:39:52 +0000 (21:39 -0400)
committerChong Yidong <cyd@stupidchicken.com>
Thu, 30 Jun 2011 01:39:52 +0000 (21:39 -0400)
* lisp/cus-edit.el (customize-push-and-save): New function.

* lisp/files.el (hack-local-variables-confirm): Use it.

* lisp/custom.el (load-theme): New arg NO-CONFIRM.  Use
customize-push-and-save (Bug#8720).
(custom-enabled-themes): Doc fix.

* lisp/cus-theme.el (customize-create-theme)
(custom-theme-merge-theme): Callers to load-theme changed.

lisp/ChangeLog
lisp/cus-edit.el
lisp/cus-theme.el
lisp/custom.el
lisp/files.el

index 29ae37155314b360a6fcf408fa4522b17fafded0..7deafcaa647e02b23d94b08f82b6b6f01b1c3f9c 100644 (file)
@@ -1,3 +1,16 @@
+2011-06-30  Chong Yidong  <cyd@stupidchicken.com>
+
+       * cus-edit.el (customize-push-and-save): New function.
+
+       * files.el (hack-local-variables-confirm): Use it.
+
+       * custom.el (load-theme): New arg NO-CONFIRM.  Use
+       customize-push-and-save (Bug#8720).
+       (custom-enabled-themes): Doc fix.
+
+       * cus-theme.el (customize-create-theme)
+       (custom-theme-merge-theme): Callers to load-theme changed.
+
 2011-06-30  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
        * progmodes/grep.el (rgrep): Bind `process-connection-type' to
index 7c96b526f414d8663fb15553d0351154fa17d65a..693b36040ea45d67a3bcaf0c4c5f42927b714507 100644 (file)
@@ -1036,6 +1036,29 @@ If given a prefix (or a COMMENT argument), also prompt for a comment."
   (custom-save-all)
   value)
 
+;; Some parts of Emacs might prompt the user to save customizations,
+;; during startup before customizations are loaded.  This function
+;; handles this corner case by avoiding calling `custom-save-variable'
+;; too early, which could wipe out existing customizations.
+
+;;;###autoload
+(defun customize-push-and-save (list-var elts)
+  "Add ELTS to LIST-VAR and save for future sessions, safely.
+ELTS should be a list.  This function adds each entry to the
+value of LIST-VAR using `add-to-list'.
+
+If Emacs is initialized, call `customize-save-variable' to save
+the resulting list value now.  Otherwise, add an entry to
+`after-init-hook' to save it after initialization."
+  (dolist (entry elts)
+    (add-to-list list-var entry))
+  (if after-init-time
+      (let ((coding-system-for-read nil))
+       (customize-save-variable list-var (eval list-var)))
+    (add-hook 'after-init-hook
+             `(lambda ()
+                (customize-push-and-save ',list-var ',elts)))))
+
 ;;;###autoload
 (defun customize ()
   "Select a customization buffer which you can use to set user options.
index 7f926c85e56e110b3df36e88b7ed21ecf2d06261..04a9e728b22efd7c047fe265036a9f7bd73e4e27 100644 (file)
@@ -157,7 +157,7 @@ remove them from your saved Custom file.\n\n"))
     ;; Load the theme settings.
     (when theme
       (unless (eq theme 'user)
-       (load-theme theme t))
+       (load-theme theme nil t))
       (dolist (setting (get theme 'theme-settings))
        (if (eq (car setting) 'theme-value)
            (progn (push (nth 1 setting) vars)
@@ -326,7 +326,7 @@ SPEC, if non-nil, should be a face spec to which to set the widget."
   (unless (eq theme 'user)
     (unless (custom-theme-name-valid-p theme)
       (error "Invalid theme name `%s'" theme))
-    (load-theme theme t))
+    (load-theme theme nil t))
   (let ((settings (reverse (get theme 'theme-settings))))
     (dolist (setting settings)
       (funcall (if (eq (car setting) 'theme-value)
index 8295777f1f18b384f32f158c4a9afa3cd5ed3ed9..2504b4f2cd987b8bfd092f6a97ee1d17fdfd2857 100644 (file)
@@ -1119,20 +1119,29 @@ Emacs theme directory (a directory named \"themes\" in
   :risky t
   :version "24.1")
 
-(defun load-theme (theme &optional no-enable)
+(defun load-theme (theme &optional no-confirm no-enable)
   "Load Custom theme named THEME from its file.
-Normally, this also enables THEME.  If optional arg NO-ENABLE is
-non-nil, load THEME but don't enable it.
-
 The theme file is named THEME-theme.el, in one of the directories
 specified by `custom-theme-load-path'.
 
+If THEME is not in `custom-safe-themes', prompt the user for
+confirmation, unless optional arg NO-CONFIRM is non-nil.
+
+Normally, this function also enables THEME; if optional arg
+NO-ENABLE is non-nil, load the theme but don't enable it.
+
+This function is normally called through Customize when setting
+`custom-enabled-themes'.  If used directly in your init file, it
+should be called with a non-nil NO-CONFIRM argument, or after
+`custom-safe-themes' has been loaded.
+
 Return t if THEME was successfully loaded, nil otherwise."
   (interactive
    (list
     (intern (completing-read "Load custom theme: "
                             (mapcar 'symbol-name
-                                    (custom-available-themes))))))
+                                    (custom-available-themes))))
+    nil nil))
   (unless (custom-theme-name-valid-p theme)
     (error "Invalid theme name `%s'" theme))
   ;; If reloading, clear out the old theme settings.
@@ -1152,7 +1161,8 @@ Return t if THEME was successfully loaded, nil otherwise."
       (setq hash (sha1 (current-buffer)))
       ;; Check file safety with `custom-safe-themes', prompting the
       ;; user if necessary.
-      (when (or (and (memq 'default custom-safe-themes)
+      (when (or no-confirm
+               (and (memq 'default custom-safe-themes)
                     (equal (file-name-directory fn)
                            (expand-file-name "themes/" data-directory)))
                (member hash custom-safe-themes)
@@ -1211,10 +1221,7 @@ query also about adding HASH to `custom-safe-themes'."
          ;; Offer to save to `custom-safe-themes'.
          (and (or custom-file user-init-file)
               (y-or-n-p "Treat this theme as safe in future sessions? ")
-              (let ((coding-system-for-read nil))
-                (push hash custom-safe-themes)
-                (customize-save-variable 'custom-safe-themes
-                                         custom-safe-themes)))
+              (customize-push-and-save 'custom-safe-themes (list hash)))
          t)))))
 
 (defun custom-theme-name-valid-p (name)
@@ -1291,7 +1298,10 @@ This list does not include the `user' theme, which is set by
 Customize and always takes precedence over other Custom Themes.
 
 This variable cannot be defined inside a Custom theme; there, it
-is simply ignored."
+is simply ignored.
+
+Setting this variable through Customize calls `enable-theme' or
+`load-theme' for each theme in the list."
   :group 'customize
   :type  '(repeat symbol)
   :set-after '(custom-theme-directory custom-theme-load-path
index 895cbba0edeb92cca3f46968a1fc9131d2a721d9..c2c2eae9d05ae45232d9c5aecfc708e9295a6aa2 100644 (file)
@@ -2943,16 +2943,7 @@ n  -- to ignore the local variables list.")
            (setq char nil)))
        (kill-buffer buf)
        (when (and offer-save (= char ?!) unsafe-vars)
-         (dolist (elt unsafe-vars)
-           (add-to-list 'safe-local-variable-values elt))
-         ;; When this is called from desktop-restore-file-buffer,
-         ;; coding-system-for-read may be non-nil.  Reset it before
-         ;; writing to .emacs.
-         (if (or custom-file user-init-file)
-             (let ((coding-system-for-read nil))
-               (customize-save-variable
-                'safe-local-variable-values
-                safe-local-variable-values))))
+         (customize-push-and-save 'safe-local-variable-values unsafe-vars))
        (memq char '(?! ?\s ?y))))))
 
 (defun hack-local-variables-prop-line (&optional mode-only)