diff options
| author | Stefan Monnier | 2011-03-31 00:24:03 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2011-03-31 00:24:03 -0400 |
| commit | 40d83b412f584cc02e68d4eac8fd5e6eb769e2fe (patch) | |
| tree | b56f27a7e6d75a8c1fd27b00179a27b5efea0a32 /lisp/custom.el | |
| parent | f488fb6528738131ef41859e1f04125f2e50efce (diff) | |
| parent | 44f230aa043ebb222aa0876b44d70484d5dd38db (diff) | |
| download | emacs-40d83b412f584cc02e68d4eac8fd5e6eb769e2fe.tar.gz emacs-40d83b412f584cc02e68d4eac8fd5e6eb769e2fe.zip | |
Merge from trunk
Diffstat (limited to 'lisp/custom.el')
| -rw-r--r-- | lisp/custom.el | 128 |
1 files changed, 62 insertions, 66 deletions
diff --git a/lisp/custom.el b/lisp/custom.el index d9bb4f954bc..5b5592698d8 100644 --- a/lisp/custom.el +++ b/lisp/custom.el | |||
| @@ -852,10 +852,10 @@ See `custom-known-themes' for a list of known themes." | |||
| 852 | ;; theme is later disabled. | 852 | ;; theme is later disabled. |
| 853 | (cond ((and (eq prop 'theme-value) | 853 | (cond ((and (eq prop 'theme-value) |
| 854 | (boundp symbol)) | 854 | (boundp symbol)) |
| 855 | (let ((sv (get symbol 'standard-value))) | 855 | (let ((sv (get symbol 'standard-value)) |
| 856 | (unless (and sv | 856 | (val (symbol-value symbol))) |
| 857 | (equal (eval (car sv)) (symbol-value symbol))) | 857 | (unless (and sv (equal (eval (car sv)) val)) |
| 858 | (setq old (list (list 'changed (symbol-value symbol))))))) | 858 | (setq old `((changed ,(custom-quote val))))))) |
| 859 | ((and (facep symbol) | 859 | ((and (facep symbol) |
| 860 | (not (face-attr-match-p | 860 | (not (face-attr-match-p |
| 861 | symbol | 861 | symbol |
| @@ -1084,10 +1084,10 @@ name." | |||
| 1084 | :version "24.1") | 1084 | :version "24.1") |
| 1085 | 1085 | ||
| 1086 | (defvar custom--inhibit-theme-enable nil | 1086 | (defvar custom--inhibit-theme-enable nil |
| 1087 | "If non-nil, loading a theme does not enable it. | 1087 | "Whether the custom-theme-set-* functions act immediately. |
| 1088 | This internal variable is set by `load-theme' when its NO-ENABLE | 1088 | If nil, `custom-theme-set-variables' and `custom-theme-set-faces' |
| 1089 | argument is non-nil, and it affects `custom-theme-set-variables', | 1089 | change the current values of the given variable or face. If |
| 1090 | `custom-theme-set-faces', and `provide-theme'." ) | 1090 | non-nil, they just make a record of the theme settings.") |
| 1091 | 1091 | ||
| 1092 | (defun provide-theme (theme) | 1092 | (defun provide-theme (theme) |
| 1093 | "Indicate that this file provides THEME. | 1093 | "Indicate that this file provides THEME. |
| @@ -1097,15 +1097,7 @@ property `theme-feature' (which is usually a symbol created by | |||
| 1097 | (unless (custom-theme-name-valid-p theme) | 1097 | (unless (custom-theme-name-valid-p theme) |
| 1098 | (error "Custom theme cannot be named %S" theme)) | 1098 | (error "Custom theme cannot be named %S" theme)) |
| 1099 | (custom-check-theme theme) | 1099 | (custom-check-theme theme) |
| 1100 | (provide (get theme 'theme-feature)) | 1100 | (provide (get theme 'theme-feature))) |
| 1101 | (unless custom--inhibit-theme-enable | ||
| 1102 | ;; By default, loading a theme also enables it. | ||
| 1103 | (push theme custom-enabled-themes) | ||
| 1104 | ;; `user' must always be the highest-precedence enabled theme. | ||
| 1105 | ;; Make that remain true. (This has the effect of making user | ||
| 1106 | ;; settings override the ones just loaded, too.) | ||
| 1107 | (let ((custom-enabling-themes t)) | ||
| 1108 | (enable-theme 'user)))) | ||
| 1109 | 1101 | ||
| 1110 | (defcustom custom-safe-themes '(default) | 1102 | (defcustom custom-safe-themes '(default) |
| 1111 | "List of themes that are considered safe to load. | 1103 | "List of themes that are considered safe to load. |
| @@ -1157,9 +1149,11 @@ Return t if THEME was successfully loaded, nil otherwise." | |||
| 1157 | (expand-file-name "themes/" data-directory))) | 1149 | (expand-file-name "themes/" data-directory))) |
| 1158 | (member hash custom-safe-themes) | 1150 | (member hash custom-safe-themes) |
| 1159 | (custom-theme-load-confirm hash)) | 1151 | (custom-theme-load-confirm hash)) |
| 1160 | (let ((custom--inhibit-theme-enable no-enable)) | 1152 | (let ((custom--inhibit-theme-enable t)) |
| 1161 | (eval-buffer) | 1153 | (eval-buffer)) |
| 1162 | t))))) | 1154 | (unless no-enable |
| 1155 | (enable-theme theme)) | ||
| 1156 | t)))) | ||
| 1163 | 1157 | ||
| 1164 | (defun custom-theme-load-confirm (hash) | 1158 | (defun custom-theme-load-confirm (hash) |
| 1165 | "Query the user about loading a Custom theme that may not be safe. | 1159 | "Query the user about loading a Custom theme that may not be safe. |
| @@ -1238,68 +1232,70 @@ NAME should be a symbol." | |||
| 1238 | 1232 | ||
| 1239 | ;;; Enabling and disabling loaded themes. | 1233 | ;;; Enabling and disabling loaded themes. |
| 1240 | 1234 | ||
| 1241 | (defvar custom-enabling-themes nil) | ||
| 1242 | |||
| 1243 | (defun enable-theme (theme) | 1235 | (defun enable-theme (theme) |
| 1244 | "Reenable all variable and face settings defined by THEME. | 1236 | "Reenable all variable and face settings defined by THEME. |
| 1245 | The newly enabled theme gets the highest precedence (after `user'). | 1237 | THEME should be either `user', or a theme loaded via `load-theme'. |
| 1246 | If it is already enabled, just give it highest precedence (after `user'). | 1238 | After this function completes, THEME will have the highest |
| 1247 | 1239 | precedence (after `user')." | |
| 1248 | If THEME does not specify any theme settings, this tries to load | ||
| 1249 | the theme from its theme file, by calling `load-theme'." | ||
| 1250 | (interactive (list (intern | 1240 | (interactive (list (intern |
| 1251 | (completing-read | 1241 | (completing-read |
| 1252 | "Enable custom theme: " | 1242 | "Enable custom theme: " |
| 1253 | obarray (lambda (sym) (get sym 'theme-settings)))))) | 1243 | obarray (lambda (sym) (get sym 'theme-settings)) t)))) |
| 1254 | (if (not (custom-theme-p theme)) | 1244 | (if (not (custom-theme-p theme)) |
| 1255 | (load-theme theme) | 1245 | (error "Undefined Custom theme %s" theme)) |
| 1256 | ;; This could use a bit of optimization -- cyd | 1246 | (let ((settings (get theme 'theme-settings))) |
| 1257 | (let ((settings (get theme 'theme-settings))) | 1247 | ;; Loop through theme settings, recalculating vars/faces. |
| 1258 | (dolist (s settings) | 1248 | (dolist (s settings) |
| 1259 | (let* ((prop (car s)) | 1249 | (let* ((prop (car s)) |
| 1260 | (symbol (cadr s)) | 1250 | (symbol (cadr s)) |
| 1261 | (spec-list (get symbol prop))) | 1251 | (spec-list (get symbol prop))) |
| 1262 | (put symbol prop (cons (cddr s) (assq-delete-all theme spec-list))) | 1252 | (put symbol prop (cons (cddr s) (assq-delete-all theme spec-list))) |
| 1263 | (if (eq prop 'theme-value) | 1253 | (cond |
| 1264 | (custom-theme-recalc-variable symbol) | 1254 | ((eq prop 'theme-face) |
| 1265 | (custom-theme-recalc-face symbol))))) | 1255 | (custom-theme-recalc-face symbol)) |
| 1266 | (unless (eq theme 'user) | 1256 | ((eq prop 'theme-value) |
| 1267 | (setq custom-enabled-themes | 1257 | ;; Don't change `custom-enabled-themes'; that's special. |
| 1268 | (cons theme (delq theme custom-enabled-themes))) | 1258 | (unless (eq symbol 'custom-enabled-themes) |
| 1269 | (unless custom-enabling-themes | 1259 | (custom-theme-recalc-variable symbol))))))) |
| 1270 | (enable-theme 'user))))) | 1260 | (unless (eq theme 'user) |
| 1261 | (setq custom-enabled-themes | ||
| 1262 | (cons theme (delq theme custom-enabled-themes))) | ||
| 1263 | ;; Give the `user' theme the highest priority. | ||
| 1264 | (enable-theme 'user))) | ||
| 1271 | 1265 | ||
| 1272 | (defcustom custom-enabled-themes nil | 1266 | (defcustom custom-enabled-themes nil |
| 1273 | "List of enabled Custom Themes, highest precedence first. | 1267 | "List of enabled Custom Themes, highest precedence first. |
| 1268 | This list does not include the `user' theme, which is set by | ||
| 1269 | Customize and always takes precedence over other Custom Themes. | ||
| 1274 | 1270 | ||
| 1275 | This does not include the `user' theme, which is set by Customize, | 1271 | This variable cannot be defined inside a Custom theme; there, it |
| 1276 | and always takes precedence over other Custom Themes." | 1272 | is simply ignored." |
| 1277 | :group 'customize | 1273 | :group 'customize |
| 1278 | :type '(repeat symbol) | 1274 | :type '(repeat symbol) |
| 1279 | :set-after '(custom-theme-directory custom-theme-load-path | 1275 | :set-after '(custom-theme-directory custom-theme-load-path |
| 1280 | custom-safe-themes) | 1276 | custom-safe-themes) |
| 1281 | :risky t | 1277 | :risky t |
| 1282 | :set (lambda (symbol themes) | 1278 | :set (lambda (symbol themes) |
| 1283 | ;; Avoid an infinite loop when custom-enabled-themes is | 1279 | (let (failures) |
| 1284 | ;; defined in a theme (e.g. `user'). Enabling the theme sets | 1280 | (setq themes (delq 'user (delete-dups themes))) |
| 1285 | ;; custom-enabled-themes, which enables the theme... | 1281 | ;; Disable all themes not in THEMES. |
| 1286 | (unless custom-enabling-themes | 1282 | (if (boundp symbol) |
| 1287 | (let ((custom-enabling-themes t) failures) | 1283 | (dolist (theme (symbol-value symbol)) |
| 1288 | (setq themes (delq 'user (delete-dups themes))) | 1284 | (if (not (memq theme themes)) |
| 1289 | (if (boundp symbol) | 1285 | (disable-theme theme)))) |
| 1290 | (dolist (theme (symbol-value symbol)) | 1286 | ;; Call `enable-theme' or `load-theme' on each of THEMES. |
| 1291 | (if (not (memq theme themes)) | 1287 | (dolist (theme (reverse themes)) |
| 1292 | (disable-theme theme)))) | 1288 | (condition-case nil |
| 1293 | (dolist (theme (reverse themes)) | 1289 | (if (custom-theme-p theme) |
| 1294 | (condition-case nil | 1290 | (enable-theme theme) |
| 1295 | (enable-theme theme) | 1291 | (load-theme theme)) |
| 1296 | (error (progn (push theme failures) | 1292 | (error (setq failures (cons theme failures) |
| 1297 | (setq themes (delq theme themes)))))) | 1293 | themes (delq theme themes))))) |
| 1298 | (enable-theme 'user) | 1294 | (enable-theme 'user) |
| 1299 | (custom-set-default symbol themes) | 1295 | (custom-set-default symbol themes) |
| 1300 | (if failures | 1296 | (if failures |
| 1301 | (message "Failed to enable themes: %s" | 1297 | (message "Failed to enable theme: %s" |
| 1302 | (mapconcat 'symbol-name failures " "))))))) | 1298 | (mapconcat 'symbol-name failures ", ")))))) |
| 1303 | 1299 | ||
| 1304 | (defsubst custom-theme-enabled-p (theme) | 1300 | (defsubst custom-theme-enabled-p (theme) |
| 1305 | "Return non-nil if THEME is enabled." | 1301 | "Return non-nil if THEME is enabled." |