diff options
| -rw-r--r-- | lisp/ChangeLog | 15 | ||||
| -rw-r--r-- | lisp/custom.el | 120 |
2 files changed, 70 insertions, 65 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3a4b3feeec6..954c68c0d2f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,6 +1,15 @@ | |||
| 1 | 2011-03-21 Chong Yidong <cyd@stupidchicken.com> | 1 | 2011-03-22 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 2 | ||
| 3 | * custom.el (custom-push-theme): Quote "changed" custom var entry. | 3 | * custom.el (custom--inhibit-theme-enable): Make it affect only |
| 4 | custom-theme-set-variables and custom-theme-set-faces. | ||
| 5 | (provide-theme): Ignore custom--inhibit-theme-enable. | ||
| 6 | (load-theme): Enable the theme explicitly if NO-ENABLE is non-nil. | ||
| 7 | (custom-enabling-themes): Delete variable. | ||
| 8 | (enable-theme): Accept only loaded themes as arguments. Ignore | ||
| 9 | the special custom-enabled-themes variable. | ||
| 10 | (custom-enabled-themes): Forbid themes from setting this. | ||
| 11 | Eliminate use of custom-enabling-themes. | ||
| 12 | (custom-push-theme): Quote "changed" custom var entry. | ||
| 4 | 13 | ||
| 5 | 2011-03-21 Leo Liu <sdl.web@gmail.com> | 14 | 2011-03-21 Leo Liu <sdl.web@gmail.com> |
| 6 | 15 | ||
diff --git a/lisp/custom.el b/lisp/custom.el index 4f7826093e8..e837c501438 100644 --- a/lisp/custom.el +++ b/lisp/custom.el | |||
| @@ -1081,10 +1081,10 @@ name." | |||
| 1081 | :version "24.1") | 1081 | :version "24.1") |
| 1082 | 1082 | ||
| 1083 | (defvar custom--inhibit-theme-enable nil | 1083 | (defvar custom--inhibit-theme-enable nil |
| 1084 | "If non-nil, loading a theme does not enable it. | 1084 | "Whether the custom-theme-set-* functions act immediately. |
| 1085 | This internal variable is set by `load-theme' when its NO-ENABLE | 1085 | If nil, `custom-theme-set-variables' and `custom-theme-set-faces' |
| 1086 | argument is non-nil, and it affects `custom-theme-set-variables', | 1086 | change the current values of the given variable or face. If |
| 1087 | `custom-theme-set-faces', and `provide-theme'." ) | 1087 | non-nil, they just make a record of the theme settings.") |
| 1088 | 1088 | ||
| 1089 | (defun provide-theme (theme) | 1089 | (defun provide-theme (theme) |
| 1090 | "Indicate that this file provides THEME. | 1090 | "Indicate that this file provides THEME. |
| @@ -1094,15 +1094,7 @@ property `theme-feature' (which is usually a symbol created by | |||
| 1094 | (unless (custom-theme-name-valid-p theme) | 1094 | (unless (custom-theme-name-valid-p theme) |
| 1095 | (error "Custom theme cannot be named %S" theme)) | 1095 | (error "Custom theme cannot be named %S" theme)) |
| 1096 | (custom-check-theme theme) | 1096 | (custom-check-theme theme) |
| 1097 | (provide (get theme 'theme-feature)) | 1097 | (provide (get theme 'theme-feature))) |
| 1098 | (unless custom--inhibit-theme-enable | ||
| 1099 | ;; By default, loading a theme also enables it. | ||
| 1100 | (push theme custom-enabled-themes) | ||
| 1101 | ;; `user' must always be the highest-precedence enabled theme. | ||
| 1102 | ;; Make that remain true. (This has the effect of making user | ||
| 1103 | ;; settings override the ones just loaded, too.) | ||
| 1104 | (let ((custom-enabling-themes t)) | ||
| 1105 | (enable-theme 'user)))) | ||
| 1106 | 1098 | ||
| 1107 | (defcustom custom-safe-themes '(default) | 1099 | (defcustom custom-safe-themes '(default) |
| 1108 | "List of themes that are considered safe to load. | 1100 | "List of themes that are considered safe to load. |
| @@ -1154,9 +1146,11 @@ Return t if THEME was successfully loaded, nil otherwise." | |||
| 1154 | (expand-file-name "themes/" data-directory))) | 1146 | (expand-file-name "themes/" data-directory))) |
| 1155 | (member hash custom-safe-themes) | 1147 | (member hash custom-safe-themes) |
| 1156 | (custom-theme-load-confirm hash)) | 1148 | (custom-theme-load-confirm hash)) |
| 1157 | (let ((custom--inhibit-theme-enable no-enable)) | 1149 | (let ((custom--inhibit-theme-enable t)) |
| 1158 | (eval-buffer) | 1150 | (eval-buffer)) |
| 1159 | t))))) | 1151 | (unless no-enable |
| 1152 | (enable-theme theme)) | ||
| 1153 | t)))) | ||
| 1160 | 1154 | ||
| 1161 | (defun custom-theme-load-confirm (hash) | 1155 | (defun custom-theme-load-confirm (hash) |
| 1162 | "Query the user about loading a Custom theme that may not be safe. | 1156 | "Query the user about loading a Custom theme that may not be safe. |
| @@ -1235,68 +1229,70 @@ NAME should be a symbol." | |||
| 1235 | 1229 | ||
| 1236 | ;;; Enabling and disabling loaded themes. | 1230 | ;;; Enabling and disabling loaded themes. |
| 1237 | 1231 | ||
| 1238 | (defvar custom-enabling-themes nil) | ||
| 1239 | |||
| 1240 | (defun enable-theme (theme) | 1232 | (defun enable-theme (theme) |
| 1241 | "Reenable all variable and face settings defined by THEME. | 1233 | "Reenable all variable and face settings defined by THEME. |
| 1242 | The newly enabled theme gets the highest precedence (after `user'). | 1234 | THEME should be either `user', or a theme loaded via `load-theme'. |
| 1243 | If it is already enabled, just give it highest precedence (after `user'). | 1235 | After this function completes, THEME will have the highest |
| 1244 | 1236 | precedence (after `user')." | |
| 1245 | If THEME does not specify any theme settings, this tries to load | ||
| 1246 | the theme from its theme file, by calling `load-theme'." | ||
| 1247 | (interactive (list (intern | 1237 | (interactive (list (intern |
| 1248 | (completing-read | 1238 | (completing-read |
| 1249 | "Enable custom theme: " | 1239 | "Enable custom theme: " |
| 1250 | obarray (lambda (sym) (get sym 'theme-settings)))))) | 1240 | obarray (lambda (sym) (get sym 'theme-settings)) t)))) |
| 1251 | (if (not (custom-theme-p theme)) | 1241 | (if (not (custom-theme-p theme)) |
| 1252 | (load-theme theme) | 1242 | (error "Undefined Custom theme %s" theme)) |
| 1253 | ;; This could use a bit of optimization -- cyd | 1243 | (let ((settings (get theme 'theme-settings))) |
| 1254 | (let ((settings (get theme 'theme-settings))) | 1244 | ;; Loop through theme settings, recalculating vars/faces. |
| 1255 | (dolist (s settings) | 1245 | (dolist (s settings) |
| 1256 | (let* ((prop (car s)) | 1246 | (let* ((prop (car s)) |
| 1257 | (symbol (cadr s)) | 1247 | (symbol (cadr s)) |
| 1258 | (spec-list (get symbol prop))) | 1248 | (spec-list (get symbol prop))) |
| 1259 | (put symbol prop (cons (cddr s) (assq-delete-all theme spec-list))) | 1249 | (put symbol prop (cons (cddr s) (assq-delete-all theme spec-list))) |
| 1260 | (if (eq prop 'theme-value) | 1250 | (cond |
| 1261 | (custom-theme-recalc-variable symbol) | 1251 | ((eq prop 'theme-face) |
| 1262 | (custom-theme-recalc-face symbol))))) | 1252 | (custom-theme-recalc-face symbol)) |
| 1263 | (unless (eq theme 'user) | 1253 | ((eq prop 'theme-value) |
| 1264 | (setq custom-enabled-themes | 1254 | ;; Don't change `custom-enabled-themes'; that's special. |
| 1265 | (cons theme (delq theme custom-enabled-themes))) | 1255 | (unless (eq symbol 'custom-enabled-themes) |
| 1266 | (unless custom-enabling-themes | 1256 | (custom-theme-recalc-variable symbol))))))) |
| 1267 | (enable-theme 'user))))) | 1257 | (unless (eq theme 'user) |
| 1258 | (setq custom-enabled-themes | ||
| 1259 | (cons theme (delq theme custom-enabled-themes))) | ||
| 1260 | ;; Give the `user' theme the highest priority. | ||
| 1261 | (enable-theme 'user))) | ||
| 1268 | 1262 | ||
| 1269 | (defcustom custom-enabled-themes nil | 1263 | (defcustom custom-enabled-themes nil |
| 1270 | "List of enabled Custom Themes, highest precedence first. | 1264 | "List of enabled Custom Themes, highest precedence first. |
| 1265 | This list does not include the `user' theme, which is set by | ||
| 1266 | Customize and always takes precedence over other Custom Themes. | ||
| 1271 | 1267 | ||
| 1272 | This does not include the `user' theme, which is set by Customize, | 1268 | This variable cannot be defined inside a Custom theme; there, it |
| 1273 | and always takes precedence over other Custom Themes." | 1269 | is simply ignored." |
| 1274 | :group 'customize | 1270 | :group 'customize |
| 1275 | :type '(repeat symbol) | 1271 | :type '(repeat symbol) |
| 1276 | :set-after '(custom-theme-directory custom-theme-load-path | 1272 | :set-after '(custom-theme-directory custom-theme-load-path |
| 1277 | custom-safe-themes) | 1273 | custom-safe-themes) |
| 1278 | :risky t | 1274 | :risky t |
| 1279 | :set (lambda (symbol themes) | 1275 | :set (lambda (symbol themes) |
| 1280 | ;; Avoid an infinite loop when custom-enabled-themes is | 1276 | (let (failures) |
| 1281 | ;; defined in a theme (e.g. `user'). Enabling the theme sets | 1277 | (setq themes (delq 'user (delete-dups themes))) |
| 1282 | ;; custom-enabled-themes, which enables the theme... | 1278 | ;; Disable all themes not in THEMES. |
| 1283 | (unless custom-enabling-themes | 1279 | (if (boundp symbol) |
| 1284 | (let ((custom-enabling-themes t) failures) | 1280 | (dolist (theme (symbol-value symbol)) |
| 1285 | (setq themes (delq 'user (delete-dups themes))) | 1281 | (if (not (memq theme themes)) |
| 1286 | (if (boundp symbol) | 1282 | (disable-theme theme)))) |
| 1287 | (dolist (theme (symbol-value symbol)) | 1283 | ;; Call `enable-theme' or `load-theme' on each of THEMES. |
| 1288 | (if (not (memq theme themes)) | 1284 | (dolist (theme (reverse themes)) |
| 1289 | (disable-theme theme)))) | 1285 | (condition-case nil |
| 1290 | (dolist (theme (reverse themes)) | 1286 | (if (custom-theme-p theme) |
| 1291 | (condition-case nil | 1287 | (enable-theme theme) |
| 1292 | (enable-theme theme) | 1288 | (load-theme theme)) |
| 1293 | (error (progn (push theme failures) | 1289 | (error (setq failures (cons theme failures) |
| 1294 | (setq themes (delq theme themes)))))) | 1290 | themes (delq theme themes))))) |
| 1295 | (enable-theme 'user) | 1291 | (enable-theme 'user) |
| 1296 | (custom-set-default symbol themes) | 1292 | (custom-set-default symbol themes) |
| 1297 | (if failures | 1293 | (if failures |
| 1298 | (message "Failed to enable themes: %s" | 1294 | (message "Failed to enable theme: %s" |
| 1299 | (mapconcat 'symbol-name failures " "))))))) | 1295 | (mapconcat 'symbol-name failures ", ")))))) |
| 1300 | 1296 | ||
| 1301 | (defsubst custom-theme-enabled-p (theme) | 1297 | (defsubst custom-theme-enabled-p (theme) |
| 1302 | "Return non-nil if THEME is enabled." | 1298 | "Return non-nil if THEME is enabled." |