emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r104789: Avoid calling customize-save


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104789: Avoid calling customize-save-variable during startup (Bug#8720).
Date: Wed, 29 Jun 2011 21:39:52 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104789
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Wed 2011-06-29 21:39:52 -0400
message:
  Avoid calling customize-save-variable during startup (Bug#8720).
  
  * 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.
modified:
  lisp/ChangeLog
  lisp/cus-edit.el
  lisp/cus-theme.el
  lisp/custom.el
  lisp/files.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-06-30 01:09:13 +0000
+++ b/lisp/ChangeLog    2011-06-30 01:39:52 +0000
@@ -1,3 +1,16 @@
+2011-06-30  Chong Yidong  <address@hidden>
+
+       * 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  <address@hidden>
 
        * progmodes/grep.el (rgrep): Bind `process-connection-type' to

=== modified file 'lisp/cus-edit.el'
--- a/lisp/cus-edit.el  2011-06-20 16:02:31 +0000
+++ b/lisp/cus-edit.el  2011-06-30 01:39:52 +0000
@@ -1036,6 +1036,29 @@
   (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.

=== modified file 'lisp/cus-theme.el'
--- a/lisp/cus-theme.el 2011-06-14 05:06:26 +0000
+++ b/lisp/cus-theme.el 2011-06-30 01:39:52 +0000
@@ -157,7 +157,7 @@
     ;; 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 @@
   (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)

=== modified file 'lisp/custom.el'
--- a/lisp/custom.el    2011-04-25 16:52:51 +0000
+++ b/lisp/custom.el    2011-06-30 01:39:52 +0000
@@ -1119,20 +1119,29 @@
   :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 @@
       (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 @@
          ;; 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 @@
 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

=== modified file 'lisp/files.el'
--- a/lisp/files.el     2011-06-29 18:38:39 +0000
+++ b/lisp/files.el     2011-06-30 01:39:52 +0000
@@ -2943,16 +2943,7 @@
            (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)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]