Commit 658d8eb8 authored by Chong Yidong's avatar Chong Yidong
Browse files

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.
parent 732b9594
2011-06-30 Chong Yidong <>
* 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 <>
* progmodes/grep.el (rgrep): Bind `process-connection-type' to
......@@ -1036,6 +1036,29 @@ If given a prefix (or a COMMENT argument), also prompt for a comment."
;; 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.
(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)))))
(defun customize ()
"Select a customization buffer which you can use to set user options.
......@@ -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)
......@@ -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."
(intern (completing-read "Load custom theme: "
(mapcar 'symbol-name
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
(customize-push-and-save 'custom-safe-themes (list hash)))
(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
......@@ -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-push-and-save 'safe-local-variable-values unsafe-vars))
(memq char '(?! ?\s ?y))))))
(defun hack-local-variables-prop-line (&optional mode-only)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment