diff options
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/cus-theme.el | 15 | ||||
| -rw-r--r-- | lisp/custom.el | 69 |
3 files changed, 47 insertions, 47 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d482991e7c4..f018b43b44b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2011-02-01 Chong Yidong <cyd@stupidchicken.com> | ||
| 2 | |||
| 3 | * custom.el (load-theme): Define return value. Drop use of | ||
| 4 | unsafep; call custom-theme-load-confirm for non-known-safe themes. | ||
| 5 | (custom-theme-load-confirm): Scroll in the correct window. | ||
| 6 | (custom-enabled-themes): Add custom-safe-themes to :set-after. | ||
| 7 | |||
| 8 | * cus-theme.el (custom-theme-checkbox-toggle): Don't activate the | ||
| 9 | checkbox if load-theme fails. | ||
| 10 | |||
| 1 | 2011-02-01 Stefan Monnier <monnier@iro.umontreal.ca> | 11 | 2011-02-01 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 12 | ||
| 3 | * progmodes/compile.el (compilation-next-error): Check there's | 13 | * progmodes/compile.el (compilation-next-error): Check there's |
diff --git a/lisp/cus-theme.el b/lisp/cus-theme.el index f29dd9eb213..cdc066aa91a 100644 --- a/lisp/cus-theme.el +++ b/lisp/cus-theme.el | |||
| @@ -621,7 +621,9 @@ Theme files are named *-theme.el in `")) | |||
| 621 | (let ((this-theme (widget-get widget :theme-name))) | 621 | (let ((this-theme (widget-get widget :theme-name))) |
| 622 | (if (widget-value widget) | 622 | (if (widget-value widget) |
| 623 | ;; Disable the theme. | 623 | ;; Disable the theme. |
| 624 | (disable-theme this-theme) | 624 | (progn |
| 625 | (disable-theme this-theme) | ||
| 626 | (widget-toggle-action widget event)) | ||
| 625 | ;; Enable the theme. | 627 | ;; Enable the theme. |
| 626 | (unless custom-theme-allow-multiple-selections | 628 | (unless custom-theme-allow-multiple-selections |
| 627 | ;; If only one theme is allowed, disable all other themes and | 629 | ;; If only one theme is allowed, disable all other themes and |
| @@ -634,12 +636,11 @@ Theme files are named *-theme.el in `")) | |||
| 634 | (unless (eq (car theme) this-theme) | 636 | (unless (eq (car theme) this-theme) |
| 635 | (widget-value-set (cdr theme) nil) | 637 | (widget-value-set (cdr theme) nil) |
| 636 | (widget-apply (cdr theme) :notify (cdr theme) event)))) | 638 | (widget-apply (cdr theme) :notify (cdr theme) event)))) |
| 637 | (load-theme this-theme))) | 639 | (when (load-theme this-theme) |
| 638 | ;; Mark `custom-enabled-themes' as "set for current session". | 640 | (widget-toggle-action widget event))) |
| 639 | (put 'custom-enabled-themes 'customized-value | 641 | ;; Mark `custom-enabled-themes' as "set for current session". |
| 640 | (list (custom-quote custom-enabled-themes))) | 642 | (put 'custom-enabled-themes 'customized-value |
| 641 | ;; Check/uncheck the widget. | 643 | (list (custom-quote custom-enabled-themes))))) |
| 642 | (widget-toggle-action widget event)) | ||
| 643 | 644 | ||
| 644 | (defun custom-describe-theme () | 645 | (defun custom-describe-theme () |
| 645 | "Describe the Custom theme on the current line." | 646 | "Describe the Custom theme on the current line." |
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 | |||
| 1116 | :risky t | 1116 | :risky t |
| 1117 | :version "24.1") | 1117 | :version "24.1") |
| 1118 | 1118 | ||
| 1119 | (defvar safe-functions) ; From unsafep.el | ||
| 1120 | |||
| 1121 | (defun load-theme (theme &optional no-enable) | 1119 | (defun load-theme (theme &optional no-enable) |
| 1122 | "Load a theme's settings from its file. | 1120 | "Load Custom theme named THEME from its file. |
| 1123 | Normally, this also enables the theme; use `disable-theme' to | 1121 | Normally, this also enables THEME. If optional arg NO-ENABLE is |
| 1124 | disable it. If optional arg NO-ENABLE is non-nil, don't enable | 1122 | non-nil, load THEME but don't enable it. |
| 1125 | the theme. | 1123 | |
| 1124 | The theme file is named THEME-theme.el, in one of the directories | ||
| 1125 | specified by `custom-theme-load-path'. | ||
| 1126 | 1126 | ||
| 1127 | A theme file is named THEME-theme.el, where THEME is the theme name, | 1127 | Return t if THEME was successfully loaded, nil otherwise." |
| 1128 | in one of the directories specified by `custom-theme-load-path'." | ||
| 1129 | (interactive | 1128 | (interactive |
| 1130 | (list | 1129 | (list |
| 1131 | (intern (completing-read "Load custom theme: " | 1130 | (intern (completing-read "Load custom theme: " |
| @@ -1148,30 +1147,16 @@ in one of the directories specified by `custom-theme-load-path'." | |||
| 1148 | (with-temp-buffer | 1147 | (with-temp-buffer |
| 1149 | (insert-file-contents fn) | 1148 | (insert-file-contents fn) |
| 1150 | (setq hash (sha1 (current-buffer))) | 1149 | (setq hash (sha1 (current-buffer))) |
| 1151 | ;; Check file safety. | 1150 | ;; Check file safety with `custom-safe-themes', prompting the |
| 1151 | ;; user if necessary. | ||
| 1152 | (when (or (and (memq 'default custom-safe-themes) | 1152 | (when (or (and (memq 'default custom-safe-themes) |
| 1153 | (equal (file-name-directory fn) | 1153 | (equal (file-name-directory fn) |
| 1154 | (expand-file-name "themes/" data-directory))) | 1154 | (expand-file-name "themes/" data-directory))) |
| 1155 | (member hash custom-safe-themes) | 1155 | (member hash custom-safe-themes) |
| 1156 | ;; If the theme is not in `custom-safe-themes', check | 1156 | (custom-theme-load-confirm hash)) |
| 1157 | ;; it with unsafep. | ||
| 1158 | (progn | ||
| 1159 | (require 'unsafep) | ||
| 1160 | (let ((safe-functions | ||
| 1161 | (append '(provide-theme deftheme | ||
| 1162 | custom-theme-set-variables | ||
| 1163 | custom-theme-set-faces) | ||
| 1164 | safe-functions)) | ||
| 1165 | unsafep form) | ||
| 1166 | (while (and (setq form (condition-case nil | ||
| 1167 | (let ((read-circle nil)) | ||
| 1168 | (read (current-buffer))) | ||
| 1169 | (end-of-file nil))) | ||
| 1170 | (null (setq unsafep (unsafep form))))) | ||
| 1171 | (or (null unsafep) | ||
| 1172 | (custom-theme-load-confirm hash))))) | ||
| 1173 | (let ((custom--inhibit-theme-enable no-enable)) | 1157 | (let ((custom--inhibit-theme-enable no-enable)) |
| 1174 | (eval-buffer)))))) | 1158 | (eval-buffer) |
| 1159 | t))))) | ||
| 1175 | 1160 | ||
| 1176 | (defun custom-theme-load-confirm (hash) | 1161 | (defun custom-theme-load-confirm (hash) |
| 1177 | "Query the user about loading a Custom theme that may not be safe. | 1162 | "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'." | |||
| 1180 | (if noninteractive | 1165 | (if noninteractive |
| 1181 | nil | 1166 | nil |
| 1182 | (let ((exit-chars '(?y ?n ?\s)) | 1167 | (let ((exit-chars '(?y ?n ?\s)) |
| 1183 | prompt char) | 1168 | window prompt char) |
| 1184 | (save-window-excursion | 1169 | (save-window-excursion |
| 1185 | (rename-buffer "*Custom Theme*" t) | 1170 | (rename-buffer "*Custom Theme*" t) |
| 1186 | (emacs-lisp-mode) | 1171 | (emacs-lisp-mode) |
| 1187 | (display-buffer (current-buffer)) | 1172 | (setq window (display-buffer (current-buffer))) |
| 1188 | (setq prompt | 1173 | (setq prompt |
| 1189 | (format "This theme is not guaranteed to be safe. Really load? %s" | 1174 | (format "Loading a theme can run Lisp code. Really load?%s" |
| 1190 | (if (< (line-number-at-pos (point-max)) | 1175 | (if (and window |
| 1191 | (window-body-height)) | 1176 | (< (line-number-at-pos (point-max)) |
| 1192 | "(y or n) " | 1177 | (window-body-height))) |
| 1178 | " (y or n) " | ||
| 1193 | (push ?\C-v exit-chars) | 1179 | (push ?\C-v exit-chars) |
| 1194 | "Type y or n, or C-v to scroll: "))) | 1180 | "\nType y or n, or C-v to scroll: "))) |
| 1195 | (goto-char (point-min)) | 1181 | (goto-char (point-min)) |
| 1196 | (while (null char) | 1182 | (while (null char) |
| 1197 | (setq char (read-char-choice prompt exit-chars)) | 1183 | (setq char (read-char-choice prompt exit-chars)) |
| 1198 | (when (eq char ?\C-v) | 1184 | (when (eq char ?\C-v) |
| 1199 | (condition-case nil | 1185 | (if window |
| 1200 | (scroll-up) | 1186 | (with-selected-window window |
| 1201 | (error (goto-char (point-min)))) | 1187 | (condition-case nil |
| 1188 | (scroll-up) | ||
| 1189 | (error (goto-char (point-min)))))) | ||
| 1202 | (setq char nil))) | 1190 | (setq char nil))) |
| 1203 | (when (memq char '(?\s ?y)) | 1191 | (when (memq char '(?\s ?y)) |
| 1204 | (push hash custom-safe-themes) | ||
| 1205 | ;; Offer to save to `custom-safe-themes'. | 1192 | ;; Offer to save to `custom-safe-themes'. |
| 1206 | (and (or custom-file user-init-file) | 1193 | (and (or custom-file user-init-file) |
| 1207 | (y-or-n-p "Treat this theme as safe for future loads? ") | 1194 | (y-or-n-p "Treat this theme as safe in future sessions? ") |
| 1208 | (let ((coding-system-for-read nil)) | 1195 | (let ((coding-system-for-read nil)) |
| 1196 | (push hash custom-safe-themes) | ||
| 1209 | (customize-save-variable 'custom-safe-themes | 1197 | (customize-save-variable 'custom-safe-themes |
| 1210 | custom-safe-themes))) | 1198 | custom-safe-themes))) |
| 1211 | t))))) | 1199 | t))))) |
| @@ -1285,7 +1273,8 @@ This does not include the `user' theme, which is set by Customize, | |||
| 1285 | and always takes precedence over other Custom Themes." | 1273 | and always takes precedence over other Custom Themes." |
| 1286 | :group 'customize | 1274 | :group 'customize |
| 1287 | :type '(repeat symbol) | 1275 | :type '(repeat symbol) |
| 1288 | :set-after '(custom-theme-directory custom-theme-load-path) | 1276 | :set-after '(custom-theme-directory custom-theme-load-path |
| 1277 | custom-safe-themes) | ||
| 1289 | :risky t | 1278 | :risky t |
| 1290 | :set (lambda (symbol themes) | 1279 | :set (lambda (symbol themes) |
| 1291 | ;; Avoid an infinite loop when custom-enabled-themes is | 1280 | ;; Avoid an infinite loop when custom-enabled-themes is |