dotspacemacs-default-theme --> dotspacemacs-themes

It is not possible to declare several themes in .spacemacs
with the variable `dotspacemacs-themes`
Cycle through these themes with `<SPC> T n`

Resolves #472
This commit is contained in:
syl20bnr 2015-01-23 22:02:08 -05:00
parent 7f452c8294
commit 053b9b0e3e
7 changed files with 69 additions and 83 deletions

View File

@ -87,11 +87,11 @@ disabling some faces in order to make colored identifiers stand out."
(face-all-attributes font-lock-keyword-face frame)))
;; tweak the font locks
(colors//tweak-theme-colors-font-lock)))
(colors//tweak-theme-colors spacemacs-cur-theme)
(colors//tweak-theme-colors spacemacs--cur-theme)
(defadvice spacemacs/post-theme-init (after colors/post-theme-init activate)
"Adjust lightness and brightness of rainbow-identifiers on post theme init."
(colors//tweak-theme-colors spacemacs-cur-theme))
(colors//tweak-theme-colors spacemacs--cur-theme))
:config
(progn

View File

@ -29,8 +29,10 @@ the value is nil then no banner is displayed.")
"list of contribution to load."
)
(defvar dotspacemacs-default-theme 'solarized-light
"Default theme used to start Spacemacs.")
(defvar dotspacemacs-themes '(solarized-light solarized-dark)
"List of themes, the first of the list is loaded when spacemacs starts.
Press <SPC> T n to cycle to the next theme in the list (works great
with 2 themes variants, one dark and one light")
(defvar dotspacemacs-leader-key "SPC"
"The leader key.")

View File

@ -90,8 +90,11 @@
(setq cursor-type nil)
;; no welcome buffer
(setq inhibit-startup-screen t)
;; theme
(spacemacs/load-default-theme)
;; default theme
(let ((default-theme (car dotspacemacs-themes)))
(spacemacs/load-theme default-theme)
(setq-default spacemacs--cur-theme default-theme)
(setq-default spacemacs--cycle-themes (cdr dotspacemacs-themes)))
;; remove GUI elements if supported
(when window-system
;; those unless tests are for the case when the user has a ~/.emacs file

View File

@ -24,8 +24,10 @@
;; then the banner is chosen randomly among the available banners, if
;; the value is nil then no banner is displayed.
dotspacemacs-startup-banner 'random
;; Default theme applied at startup
dotspacemacs-default-theme 'solarized-light
;; List of themes, the first of the list is loaded when spacemacs starts.
;; Press <SPC> T n to cycle to the next theme in the list (works great
;; with 2 themes variants, one dark and one light)
dotspacemacs-themes '(solarized-light solarized-dark)
;; The leader key
dotspacemacs-leader-key "SPC"
;; Major mode leader key is a shortcut key which is the equivalent of

View File

@ -10,7 +10,7 @@
;;
;;; License: GPLv3
(defconst spacemacs-themes
(defconst spacemacs-theme-name-to-package
'(
(base16-chalk . base16-theme)
(base16-default . base16-theme)
@ -30,16 +30,17 @@
(sanityinc-tomorrow-eighties . color-theme-sanityinc-tomorrow)
(sanityinc-tomorrow-night . color-theme-sanityinc-tomorrow)
)
"alist matching theme name with its package name.")
"alist matching a theme name with its package name, required when
package name does not match theme name + `-theme' suffix.")
(defun spacemacs/load-default-theme ()
"Load the default theme defined in `dotspacemacs-default-theme'"
(defun spacemacs/load-theme (theme)
"Load THEME."
;; Unless Emacs stock themes
(unless (memq dotspacemacs-default-theme (custom-available-themes))
(unless (memq theme (custom-available-themes))
(cond
;; Spacemacs default theme
((or (eq 'solarized-light dotspacemacs-default-theme)
(eq 'solarized-dark dotspacemacs-default-theme))
;; solarized theme, official spacemacs theme
((or (eq 'solarized-light theme)
(eq 'solarized-dark theme))
(add-to-list 'load-path (concat spacemacs-directory
"extensions/solarized-theme/"))
;; solarized dependency
@ -47,18 +48,48 @@
(require 'solarized)
(deftheme solarized-dark "The dark variant of the Solarized colour theme")
(deftheme solarized-light "The light variant of the Solarized colour theme"))
;; Support for all base16 themes
((assq dotspacemacs-default-theme spacemacs-themes)
(let* ((pkg (cdr (assq dotspacemacs-default-theme spacemacs-themes)))
;; themes with explicitly declared package names
((assq theme spacemacs-theme-name-to-package)
(let* ((pkg (cdr (assq theme spacemacs-theme-name-to-package)))
(pkg-dir (spacemacs/load-or-install-package pkg)))
(add-to-list 'custom-theme-load-path pkg-dir)))
(t
;; other themes
;; we assume that the package name is suffixed with `-theme'
;; if not we will handle the special themes as we get issues in the tracker.
(let ((pkg (format "%s-theme" (symbol-name dotspacemacs-default-theme))))
(let ((pkg (format "%s-theme" (symbol-name theme))))
(spacemacs/load-or-install-package (intern pkg))))))
(load-theme dotspacemacs-default-theme t)
(setq-default spacemacs-cur-theme dotspacemacs-default-theme))
(load-theme theme t))
(defun spacemacs/cycle-spacemacs-theme ()
"Cycle through themes defined in `dotspacemacs-themes.'"
(interactive)
(when spacemacs--cur-theme
(disable-theme spacemacs--cur-theme)
(setq spacemacs--cycle-themes
(append spacemacs--cycle-themes (list spacemacs--cur-theme))))
(setq spacemacs--cur-theme (pop spacemacs--cycle-themes))
(message "Loading theme %s..." spacemacs--cur-theme)
(spacemacs/load-theme spacemacs--cur-theme))
(defadvice load-theme (after spacemacs/load-theme-adv activate)
"Perform post load processing."
(let ((theme (ad-get-arg 0)))
(setq spacemacs--cur-theme theme)
(spacemacs/post-theme-init theme)))
(defun spacemacs/post-theme-init (theme)
" Some processing that needs to be done when the current theme has been
changed to THEME."
(interactive)
;; Define a face for each state
(if (fboundp 'spacemacs/set-state-faces)
(spacemacs/set-state-faces))
(if (fboundp 'spacemacs/set-flycheck-mode-line-faces)
(spacemacs/set-flycheck-mode-line-faces))
(if (fboundp 'spacemacs/set-new-version-lighter-mode-line-faces)
(spacemacs/set-new-version-lighter-mode-line-faces))
(if (fboundp 'powerline-reset)
(powerline-reset)))
(provide 'themes-support)

View File

@ -633,38 +633,28 @@ your `~/.spacemacs`):
[evil-jumper][] | jump list emulation
[NeoTree][neotree] | mimic [NERD Tree][nerdtree]
# Color theme
# Color themes
By default, `Spacemacs` uses the theme [solarized-light][solarized-theme].
It is possible to define your default theme in your `~/.spacemacs` with
the variable `dotspacemacs-default-theme`. For instance, to specify `zenburn`:
It is possible to define your default themes in your `~/.spacemacs` with
the variable `dotspacemacs-themes`. For instance, to specify `leuven` and
`zenburn` (high contract theme and low contrast theme):
```elisp
(setq-default
;; Default theme applied at startup
dotspacemacs-default-theme 'zenburn)
(setq-default dotspacemacs-themes '(leuven zenburn))
```
Some themes are supported by `Spacemacs`:
- [Solarized][solarized-theme]
- [Leuven][leuven-theme]
- [Monokai][monokai-theme]
- [Zenburn][zenburn-theme]
It is possible to set any other themes but their compatibility with `Spacemacs`
is not guaranteed (i.e. there may be some missing faces etc...).
Key Binding | Description
---------------------|------------------------------------------------------------
<kbd>SPC T n</kbd> | switch to next theme supported by `Spacemacs`.
<kbd>SPC h t</kbd> | select a theme using a `helm` buffer.
<kbd>SPC T n</kbd> | switch to next theme listed in `dotspacemacs-themes`.
<kbd>SPC T h</kbd> | select a theme using `helm`.
**Note:** Due to the inner working of themes in Emacs, switching theme during
the same session may have some weird side effects. Although these side effects
should be pretty rare (especially when switching to a supported theme).
should be pretty rare.
**Hint** If you are an `Org` user, [leuven-theme][] is amazing.
**Hint** If you are an `Org` user, [leuven-theme][] is amazing ;-)
# UI elements

View File

@ -114,17 +114,6 @@ bindings contained in BODY."
"y" 'evil-yank
,@body))
;; From http://stackoverflow.com/a/18796138
;; Cycle through this set of themes
(defvar spacemacs-themes '(solarized-light
solarized-dark
leuven
monokai
zenburn)
"Themes officially supported by spacemacs.")
(defvar spacemacs-cur-theme (pop spacemacs-themes)
"Current spacemacs theme.")
(defun spacemacs/split-and-new-line ()
"Split a quoted string or s-expression and insert a new line with
auto-indent."
@ -144,37 +133,6 @@ auto-indent."
(push-mark (point))
(evil-end-of-line))
(defun spacemacs/cycle-spacemacs-theme ()
"Cycle through themes defined in spacemacs-themes."
(interactive)
(when spacemacs-cur-theme
(disable-theme spacemacs-cur-theme)
(setq spacemacs-themes (append spacemacs-themes
(list spacemacs-cur-theme))))
(setq spacemacs-cur-theme (pop spacemacs-themes))
(message "Loading theme %s..." spacemacs-cur-theme)
(load-theme spacemacs-cur-theme t))
(defadvice load-theme (after spacemacs/load-theme-adv activate)
"Perform post load processing."
(let ((theme (ad-get-arg 0)))
(setq spacemacs-cur-theme theme)
(spacemacs/post-theme-init theme)))
(defun spacemacs/post-theme-init (theme)
" Some processing that needs to be done when the current theme has been
changed to THEME."
(interactive)
;; Define a face for each state
(if (fboundp 'spacemacs/set-state-faces)
(spacemacs/set-state-faces))
(if (fboundp 'spacemacs/set-flycheck-mode-line-faces)
(spacemacs/set-flycheck-mode-line-faces))
(if (fboundp 'spacemacs/set-new-version-lighter-mode-line-faces)
(spacemacs/set-new-version-lighter-mode-line-faces))
(if (fboundp 'powerline-reset)
(powerline-reset)))
;; insert one or several line below without changing current evil state
(defun evil-insert-line-below (count)
"Insert one of several lines below the current point's line without changing