summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorChong Yidong <cyd@stupidchicken.com>2011-06-29 21:39:52 -0400
committerChong Yidong <cyd@stupidchicken.com>2011-06-29 21:39:52 -0400
commit658d8eb8fceb1d5f0f7a71c4f7145dd43b78081b (patch)
treefac3229b9f3f5ed01817341dfa23a295c0c0937d /lisp
parent732b9594ceab70733e55dba8dec85e7def3824b0 (diff)
downloademacs-658d8eb8fceb1d5f0f7a71c4f7145dd43b78081b.tar.gz
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/cus-edit.el23
-rw-r--r--lisp/cus-theme.el4
-rw-r--r--lisp/custom.el32
-rw-r--r--lisp/files.el11
5 files changed, 60 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 29ae3715531..7deafcaa647 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -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
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 7c96b526f41..693b36040ea 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -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.
diff --git a/lisp/cus-theme.el b/lisp/cus-theme.el
index 7f926c85e56..04a9e728b22 100644
--- a/lisp/cus-theme.el
+++ b/lisp/cus-theme.el
@@ -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)
diff --git a/lisp/custom.el b/lisp/custom.el
index 8295777f1f1..2504b4f2cd9 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -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
diff --git a/lisp/files.el b/lisp/files.el
index 895cbba0ede..c2c2eae9d05 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -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)