summaryrefslogtreecommitdiff
path: root/lisp/custom.el
diff options
context:
space:
mode:
authorChong Yidong <cyd@stupidchicken.com>2011-02-01 12:34:07 -0500
committerChong Yidong <cyd@stupidchicken.com>2011-02-01 12:34:07 -0500
commit928f4e732d8b605b682cb6d41c9452028083047a (patch)
treeb39b90a80e1af3ac24fccdc675a1293c53710ca4 /lisp/custom.el
parent7d1166478188fe1fe014d3b64c22641c4fac6a25 (diff)
downloademacs-928f4e732d8b605b682cb6d41c9452028083047a.tar.gz
Drop use of unsafep for checking Custom themes; bugfixes.
* lisp/custom.el (load-theme): Define return value. Drop use of unsafep; call custom-theme-load-confirm for non-known-safe themes. (custom-theme-load-confirm): Scroll in the correct window. (custom-enabled-themes): Add custom-safe-themes to :set-after. * lisp/cus-theme.el (custom-theme-checkbox-toggle): Don't activate the checkbox if load-theme fails.
Diffstat (limited to 'lisp/custom.el')
-rw-r--r--lisp/custom.el69
1 files changed, 29 insertions, 40 deletions
diff --git a/lisp/custom.el b/lisp/custom.el
index e31948ec4b4..e41e7c7bdf8 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -1116,16 +1116,15 @@ Emacs theme directory (a directory named \"themes\" in
:risky t
:version "24.1")
-(defvar safe-functions) ; From unsafep.el
-
(defun load-theme (theme &optional no-enable)
- "Load a theme's settings from its file.
-Normally, this also enables the theme; use `disable-theme' to
-disable it. If optional arg NO-ENABLE is non-nil, don't enable
-the theme.
+ "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'.
-A theme file is named THEME-theme.el, where THEME is the theme name,
-in one of the directories specified by `custom-theme-load-path'."
+Return t if THEME was successfully loaded, nil otherwise."
(interactive
(list
(intern (completing-read "Load custom theme: "
@@ -1148,30 +1147,16 @@ in one of the directories specified by `custom-theme-load-path'."
(with-temp-buffer
(insert-file-contents fn)
(setq hash (sha1 (current-buffer)))
- ;; Check file safety.
+ ;; Check file safety with `custom-safe-themes', prompting the
+ ;; user if necessary.
(when (or (and (memq 'default custom-safe-themes)
(equal (file-name-directory fn)
(expand-file-name "themes/" data-directory)))
(member hash custom-safe-themes)
- ;; If the theme is not in `custom-safe-themes', check
- ;; it with unsafep.
- (progn
- (require 'unsafep)
- (let ((safe-functions
- (append '(provide-theme deftheme
- custom-theme-set-variables
- custom-theme-set-faces)
- safe-functions))
- unsafep form)
- (while (and (setq form (condition-case nil
- (let ((read-circle nil))
- (read (current-buffer)))
- (end-of-file nil)))
- (null (setq unsafep (unsafep form)))))
- (or (null unsafep)
- (custom-theme-load-confirm hash)))))
+ (custom-theme-load-confirm hash))
(let ((custom--inhibit-theme-enable no-enable))
- (eval-buffer))))))
+ (eval-buffer)
+ t)))))
(defun custom-theme-load-confirm (hash)
"Query the user about loading a Custom theme that may not be safe.
@@ -1180,32 +1165,35 @@ query also about adding HASH to `custom-safe-themes'."
(if noninteractive
nil
(let ((exit-chars '(?y ?n ?\s))
- prompt char)
+ window prompt char)
(save-window-excursion
(rename-buffer "*Custom Theme*" t)
(emacs-lisp-mode)
- (display-buffer (current-buffer))
+ (setq window (display-buffer (current-buffer)))
(setq prompt
- (format "This theme is not guaranteed to be safe. Really load? %s"
- (if (< (line-number-at-pos (point-max))
- (window-body-height))
- "(y or n) "
+ (format "Loading a theme can run Lisp code. Really load?%s"
+ (if (and window
+ (< (line-number-at-pos (point-max))
+ (window-body-height)))
+ " (y or n) "
(push ?\C-v exit-chars)
- "Type y or n, or C-v to scroll: ")))
+ "\nType y or n, or C-v to scroll: ")))
(goto-char (point-min))
(while (null char)
(setq char (read-char-choice prompt exit-chars))
(when (eq char ?\C-v)
- (condition-case nil
- (scroll-up)
- (error (goto-char (point-min))))
+ (if window
+ (with-selected-window window
+ (condition-case nil
+ (scroll-up)
+ (error (goto-char (point-min))))))
(setq char nil)))
(when (memq char '(?\s ?y))
- (push 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 for future loads? ")
+ (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)))
t)))))
@@ -1285,7 +1273,8 @@ This does not include the `user' theme, which is set by Customize,
and always takes precedence over other Custom Themes."
:group 'customize
:type '(repeat symbol)
- :set-after '(custom-theme-directory custom-theme-load-path)
+ :set-after '(custom-theme-directory custom-theme-load-path
+ custom-safe-themes)
:risky t
:set (lambda (symbol themes)
;; Avoid an infinite loop when custom-enabled-themes is