* 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.
+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
(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.
;; 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)
(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)
: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.
(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)
;; 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)
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
(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)