core: dotspacemacs-themes entries now accept package properties

It is now possible to use package properties like :location in
dotspacemacs-themes.

Added hooks ran at the beginning and end of configuration-layer/sync:
- configuration-layer-pre-sync-hook
- configuration-layer-post-sync-hook

configuration-layer-pre-sync-hook is used to hook the new function
spacemacs//add-theme-packages-to-additional-packages. This new function updates
dotspacemacs--additional-theme-packages variables.

Update documentation to mention the new feature.
This commit is contained in:
syl20bnr 2017-02-01 22:59:03 -05:00
parent 36044870cb
commit 415b29b140
5 changed files with 129 additions and 74 deletions

View File

@ -69,6 +69,12 @@ ROOT is returned."
(dir (car (directory-files elpa-dir 'full pkg-match))))
(when dir (file-name-as-directory dir))))))
(defvar configuration-layer-pre-sync-hook nil
"Hook executed at the beginning of configuration synchronization.")
(defvar configuration-layer-post-sync-hook nil
"Hook executed at the end of configuration synchronization.")
(defvar configuration-layer-rollback-directory
(concat spacemacs-cache-directory ".rollback/")
"Spacemacs rollback directory.")
@ -407,6 +413,7 @@ refreshed during the current session."
(defun configuration-layer/sync (&optional no-install)
"Synchronize declared layers in dotfile with spacemacs.
If NO-INSTALL is non nil then install steps are skipped."
(run-hooks 'configuration-layer-pre-sync-hook)
(dotspacemacs|call-func dotspacemacs/layers "Calling dotfile layers...")
(setq dotspacemacs--configuration-layers-saved
dotspacemacs-configuration-layers)
@ -462,7 +469,8 @@ If NO-INSTALL is non nil then install steps are skipped."
;; configure used packages
(configuration-layer//configure-packages configuration-layer--used-packages)
(configuration-layer//load-layers-files configuration-layer--used-layers
'("keybindings.el")))
'("keybindings.el"))
(run-hooks 'configuration-layer-post-sync-hook))
(defun configuration-layer/load-auto-layer-file ()
"Load `auto-layer.el' file"
@ -952,7 +960,7 @@ variable as well."
"Read the additonal packages declared in the dotfile and create packages.
USEDP if non-nil indicates that made packages are used packages."
(dolist (pkg (append dotspacemacs-additional-packages
dotspacemacs--additional-packages))
dotspacemacs--additional-theme-packages))
(let* ((pkg-name (if (listp pkg) (car pkg) pkg))
(obj (configuration-layer/get-package pkg-name)))
(if obj

View File

@ -100,9 +100,9 @@ wrapped in a layer. If you need some configuration for these
packages then consider to create a layer, you can also put the
configuration in `dotspacemacs/user-config'.")
(defvar dotspacemacs--additional-packages '()
"Same as `dotspacemacs-additonal-packages' but reserved for Spacemacs
internals.")
(defvar dotspacemacs--additional-theme-packages '()
"Same as `dotspacemacs-additonal-packages' but reserved for themes declared
in `dotspacemacs-themes'.")
(defvar dotspacemacs-editing-style 'vim
"One of `vim', `emacs' or `hybrid'.

View File

@ -104,8 +104,7 @@ the final step of executing code in `emacs-startup-hook'.")
dotspacemacs-editing-style))
(configuration-layer/initialize)
;; theme
(spacemacs/load-theme (car dotspacemacs-themes)
spacemacs--fallback-theme)
(spacemacs/load-default-theme spacemacs--fallback-theme)
;; font
(spacemacs|do-after-display-system-init
;; If you are thinking to remove this call to `message', think twice. You'll

View File

@ -167,7 +167,7 @@ package name does not match theme name + `-theme' suffix.")
(defvar spacemacs-post-theme-change-hook nil
"Hook run after theme has changed.")
(defun spacemacs/get-theme-package (theme)
(defun spacemacs/get-theme-package-name (theme)
"Returns the package theme for the given THEME name."
(cond
;; built-in
@ -178,63 +178,79 @@ package name does not match theme name + `-theme' suffix.")
;; fallback to <name>-theme
(t (intern (format "%S-theme" theme)))))
(defun spacemacs//get-theme-name (theme)
"Return the name of THEME."
(if (listp theme)
(car theme)
theme))
(defun spacemacs/load-default-theme (&optional fallback-theme)
"Load default theme.
Default theme is the car of `dotspacemacs-themes'.
If FALLBACK-THEME is non-nil it must be a package name which will be loaded if
THEME cannot be applied."
(spacemacs/load-theme (car dotspacemacs-themes) fallback-theme))
(defun spacemacs/load-theme (theme &optional fallback-theme disable)
"Apply user theme.
If FALLBACK-THEME is non-nil it must be a package name which will be loaded if
THEME cannot be applied.
If DISABLE is non-nil then disable all previously applied themes before applying
THEME."
(spacemacs//add-themes-to-additional-packages dotspacemacs-themes)
(condition-case err
(progn
;; Load theme
(unless (or (memq theme (custom-available-themes))
(eq 'default theme))
(let* ((pkg (spacemacs/get-theme-package theme))
(pkg-dir
(when pkg
(configuration-layer/get-elpa-package-install-directory
pkg))))
(when pkg-dir
(add-to-list 'custom-theme-load-path pkg-dir)
(when (or (eq 'moe-light theme)
(eq 'moe-dark theme))
(load-file (concat pkg-dir "moe-light-theme.el"))
(load-file (concat pkg-dir "moe-dark-theme.el"))))))
(when disable
(mapc 'disable-theme custom-enabled-themes))
(eval `(spacemacs|do-after-display-system-init
(load-theme ',theme t)))
(setq-default spacemacs--cur-theme theme)
(setq-default spacemacs--cycle-themes (cdr dotspacemacs-themes)))
('error
(if fallback-theme
;; fallback to Spacemacs default theme
(progn
(setq spacemacs--delayed-user-theme theme)
(spacemacs/load-fallback-theme fallback-theme disable))
;; no fallback theme was specified, so we log explicit warning
(spacemacs-buffer/warning
(concat "An error occurred while applying "
"the theme \"%s\", fallback on theme \"%s\". \n"
"Error was: %s") theme spacemacs--fallback-theme err)
(spacemacs-buffer/warning
(concat "Please check the value of \"dotspacemacs-themes\" in your "
"dotfile or open an issue \n"
"so we can add support for the theme \"%s\".") theme)))))
(let ((theme-name (spacemacs//get-theme-name theme)))
(condition-case err
(progn
;; Load theme
(unless (or (memq theme-name (custom-available-themes))
(eq 'default theme-name))
(let* ((pkg-name (spacemacs/get-theme-package-name theme-name))
(pkg-dir
(when pkg-name
(configuration-layer/get-elpa-package-install-directory
pkg-name))))
(when pkg-dir
(add-to-list 'custom-theme-load-path pkg-dir)
(when (or (eq 'moe-light theme-name)
(eq 'moe-dark theme-name))
(load-file (concat pkg-dir "moe-light-theme.el"))
(load-file (concat pkg-dir "moe-dark-theme.el"))))))
(when disable
(mapc 'disable-theme custom-enabled-themes))
(eval `(spacemacs|do-after-display-system-init
(load-theme ',theme-name t)))
(setq-default spacemacs--cur-theme theme-name)
(setq-default spacemacs--cycle-themes (cdr dotspacemacs-themes)))
('error
(if fallback-theme
;; fallback to Spacemacs default theme
(progn
(setq spacemacs--delayed-user-theme theme-name)
(spacemacs/load-fallback-theme fallback-theme disable))
;; no fallback theme was specified, so we log explicit warning
(spacemacs-buffer/warning
(concat "An error occurred while applying "
"the theme \"%s\", fallback on theme \"%s\". \n"
"Error was: %s")
theme-name spacemacs--fallback-theme err)
(spacemacs-buffer/warning
(concat "Please check the value of \"dotspacemacs-themes\" in your "
"dotfile or open an issue \n"
"so we can add support for the theme \"%s\".")
theme-name))))))
(defun spacemacs/load-fallback-theme (theme &optional disable)
"Apply the fallback theme.
If DISABLE is non-nil then disable all previously applied themes before applying
THEME."
;; pop up fallback theme to the top of the list
(setq spacemacs--cur-theme theme)
(setq dotspacemacs-themes (delq theme dotspacemacs-themes))
(add-to-list 'dotspacemacs-themes theme)
(when disable
(mapc 'disable-theme custom-enabled-themes))
(eval `(spacemacs|do-after-display-system-init
(load-theme ',theme t))))
(let ((theme-name (spacemacs//get-theme-name theme)))
;; pop up fallback theme to the top of the list
(setq spacemacs--cur-theme theme-name)
(setq dotspacemacs-themes (delq theme-name dotspacemacs-themes))
(add-to-list 'dotspacemacs-themes theme-name)
(when disable
(mapc 'disable-theme custom-enabled-themes))
(eval `(spacemacs|do-after-display-system-init
(load-theme ',theme-name t)))))
(defun spacemacs/cycle-spacemacs-theme ()
"Cycle through themes defined in `dotspacemacs-themes.'"
@ -267,11 +283,19 @@ has been changed to THEME."
(interactive)
(run-hooks 'spacemacs-post-theme-change-hook))
(defun spacemacs//add-themes-to-additional-packages (themes)
"Add the THEMES packages to `dotspacemacs-additional-packages'."
(dolist (theme themes)
(let ((pkg (spacemacs/get-theme-package theme)))
(when pkg
(add-to-list 'dotspacemacs--additional-packages pkg)))))
(defun spacemacs//add-theme-packages-to-additional-packages ()
"Add all theme packages from `dotspacemacs-themes' to packages to install."
(setq dotspacemacs--additional-theme-packages nil)
(dolist (theme dotspacemacs-themes)
(let* ((theme-name (spacemacs//get-theme-name theme))
(pkg-name (spacemacs/get-theme-package-name theme-name))
(theme2 (copy-tree theme)))
(when pkg-name
(if (listp theme2)
(setcar theme2 pkg-name)
(setq theme2 pkg-name))
(add-to-list 'dotspacemacs--additional-theme-packages theme2)))))
(add-hook 'configuration-layer-pre-sync-hook
'spacemacs//add-theme-packages-to-additional-packages)
(provide 'core-themes-support)

View File

@ -62,6 +62,10 @@
- [[#binding-keys][Binding keys]]
- [[#gui-elements][GUI Elements]]
- [[#color-themes][Color themes]]
- [[#default-theme][Default theme]]
- [[#choosing-themes][Choosing themes]]
- [[#browsing-themes][Browsing themes]]
- [[#notes][Notes]]
- [[#font][Font]]
- [[#gui-toggles][GUI Toggles]]
- [[#global-line-numbers][Global line numbers]]
@ -987,6 +991,7 @@ Spacemacs has a minimalistic and distraction free graphical UI:
- [[Errors handling][custom fringe bitmaps]] and error feedbacks for [[https://github.com/flycheck/flycheck][Flycheck]]
** Color themes
*** Default theme
The official Spacemacs theme is [[https://github.com/nashamri/spacemacs-theme][spacemacs-dark]] and it is the default theme
installed when you first started Spacemacs. There are two variants of the
theme, a dark one and a light one. Some aspects of these themes can be customized
@ -994,6 +999,7 @@ in the function =dotspacemacs/user-init= of your =~/.spacemacs=:
- the comment background with the boolean =spacemacs-theme-comment-bg=
- the height of org section titles with =spacemacs-theme-org-height=
*** Choosing themes
It is possible to define your default themes in your =~/.spacemacs= with the
variable =dotspacemacs-themes=. For instance, to specify =spacemacs-light=,
=leuven= and =zenburn=:
@ -1002,26 +1008,44 @@ variable =dotspacemacs-themes=. For instance, to specify =spacemacs-light=,
(setq-default dotspacemacs-themes '(spacemacs-light leuven zenburn))
#+END_SRC
=dotspacemacs-themes= entries accept the same properties as packages listed
in layers package lists or in =dotspacemacs-addtional-packages=. So it is
possible to fetch a package from a specific location. For example, you could
fetch =zenburn= theme directly from the GitHub repository with the following
declaration:
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-themes
'(spacemacs-light
leuven
(zenburn :location (recipe :fetcher github
:repo "bbatsov/zenburn-emacs"))
))
#+END_SRC
You can cycle between the themes declared in =dotspacemacs-themes= with
~SPC T n~ and select an installed theme with ~SPC T s~.
| Key Binding | Description |
|-------------+-------------------------------------------------------|
| ~SPC T n~ | switch to next theme listed in =dotspacemacs-themes=. |
| ~SPC T s~ | select a theme using a =helm= buffer. |
You can see samples of all included themes in this [[http://themegallery.robdor.com][theme gallery]] from [[http://www.twitter.com/robmerrell][Rob Merrell]].
*** Browsing themes
You can see samples of all themes included in the =themes-megapack= layer
in this [[http://themegallery.robdor.com][theme gallery]] from [[http://www.twitter.com/robmerrell][Rob Merrell]].
*Note*:
- You don't need to explicitly list in a layer the theme packages you are
defining in =dotspacemacs-themes=, Spacemacs is smart enough to remove those
packages from the list of orphans.
- 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.
- In the terminal version of Emacs, color themes will not render correctly as
colors are rendered by the terminal and not by emacs. You will probably have
to change your terminal color palette. More explanations can be found on
[[https://github.com/sellout/emacs-color-theme-solarized#important-note-for-terminal-users][emacs-color-theme-solarized webpage]].
*Hint*: If you are an =Org= user, [[https://github.com/fniessen/emacs-leuven-theme][leuven-theme]] is amazing ;-)
*** Notes
- You don't need to explicitly list in a layer the theme packages you are
defining in =dotspacemacs-themes=, Spacemacs is smart enough to remove those
packages from the list of orphans.
- 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.
- In the terminal version of Emacs, color themes will not render correctly as
colors are rendered by the terminal and not by emacs. You will probably have
to change your terminal color palette. More explanations can be found on
[[https://github.com/sellout/emacs-color-theme-solarized#important-note-for-terminal-users][emacs-color-theme-solarized webpage]].
** Font
The default font used by Spacemacs is [[https://github.com/adobe-fonts/source-code-pro][Source Code Pro]] by Adobe. It is