diff options
| author | Chong Yidong | 2011-02-01 12:34:07 -0500 |
|---|---|---|
| committer | Chong Yidong | 2011-02-01 12:34:07 -0500 |
| commit | 928f4e732d8b605b682cb6d41c9452028083047a (patch) | |
| tree | b39b90a80e1af3ac24fccdc675a1293c53710ca4 /lisp/custom.el | |
| parent | 7d1166478188fe1fe014d3b64c22641c4fac6a25 (diff) | |
| download | emacs-928f4e732d8b605b682cb6d41c9452028083047a.tar.gz emacs-928f4e732d8b605b682cb6d41c9452028083047a.zip | |
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.el | 69 |
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 | |||
| 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 |