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)))) (dir (car (directory-files elpa-dir 'full pkg-match))))
(when dir (file-name-as-directory dir)))))) (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 (defvar configuration-layer-rollback-directory
(concat spacemacs-cache-directory ".rollback/") (concat spacemacs-cache-directory ".rollback/")
"Spacemacs rollback directory.") "Spacemacs rollback directory.")
@ -407,6 +413,7 @@ refreshed during the current session."
(defun configuration-layer/sync (&optional no-install) (defun configuration-layer/sync (&optional no-install)
"Synchronize declared layers in dotfile with spacemacs. "Synchronize declared layers in dotfile with spacemacs.
If NO-INSTALL is non nil then install steps are skipped." 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...") (dotspacemacs|call-func dotspacemacs/layers "Calling dotfile layers...")
(setq dotspacemacs--configuration-layers-saved (setq dotspacemacs--configuration-layers-saved
dotspacemacs-configuration-layers) dotspacemacs-configuration-layers)
@ -462,7 +469,8 @@ If NO-INSTALL is non nil then install steps are skipped."
;; configure used packages ;; configure used packages
(configuration-layer//configure-packages configuration-layer--used-packages) (configuration-layer//configure-packages configuration-layer--used-packages)
(configuration-layer//load-layers-files configuration-layer--used-layers (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 () (defun configuration-layer/load-auto-layer-file ()
"Load `auto-layer.el' file" "Load `auto-layer.el' file"
@ -952,7 +960,7 @@ variable as well."
"Read the additonal packages declared in the dotfile and create packages. "Read the additonal packages declared in the dotfile and create packages.
USEDP if non-nil indicates that made packages are used packages." USEDP if non-nil indicates that made packages are used packages."
(dolist (pkg (append dotspacemacs-additional-packages (dolist (pkg (append dotspacemacs-additional-packages
dotspacemacs--additional-packages)) dotspacemacs--additional-theme-packages))
(let* ((pkg-name (if (listp pkg) (car pkg) pkg)) (let* ((pkg-name (if (listp pkg) (car pkg) pkg))
(obj (configuration-layer/get-package pkg-name))) (obj (configuration-layer/get-package pkg-name)))
(if obj (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 packages then consider to create a layer, you can also put the
configuration in `dotspacemacs/user-config'.") configuration in `dotspacemacs/user-config'.")
(defvar dotspacemacs--additional-packages '() (defvar dotspacemacs--additional-theme-packages '()
"Same as `dotspacemacs-additonal-packages' but reserved for Spacemacs "Same as `dotspacemacs-additonal-packages' but reserved for themes declared
internals.") in `dotspacemacs-themes'.")
(defvar dotspacemacs-editing-style 'vim (defvar dotspacemacs-editing-style 'vim
"One of `vim', `emacs' or `hybrid'. "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)) dotspacemacs-editing-style))
(configuration-layer/initialize) (configuration-layer/initialize)
;; theme ;; theme
(spacemacs/load-theme (car dotspacemacs-themes) (spacemacs/load-default-theme spacemacs--fallback-theme)
spacemacs--fallback-theme)
;; font ;; font
(spacemacs|do-after-display-system-init (spacemacs|do-after-display-system-init
;; If you are thinking to remove this call to `message', think twice. You'll ;; 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 (defvar spacemacs-post-theme-change-hook nil
"Hook run after theme has changed.") "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." "Returns the package theme for the given THEME name."
(cond (cond
;; built-in ;; built-in
@ -178,63 +178,79 @@ package name does not match theme name + `-theme' suffix.")
;; fallback to <name>-theme ;; fallback to <name>-theme
(t (intern (format "%S-theme" 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) (defun spacemacs/load-theme (theme &optional fallback-theme disable)
"Apply user theme. "Apply user theme.
If FALLBACK-THEME is non-nil it must be a package name which will be loaded if If FALLBACK-THEME is non-nil it must be a package name which will be loaded if
THEME cannot be applied. THEME cannot be applied.
If DISABLE is non-nil then disable all previously applied themes before applying If DISABLE is non-nil then disable all previously applied themes before applying
THEME." THEME."
(spacemacs//add-themes-to-additional-packages dotspacemacs-themes) (let ((theme-name (spacemacs//get-theme-name theme)))
(condition-case err (condition-case err
(progn (progn
;; Load theme ;; Load theme
(unless (or (memq theme (custom-available-themes)) (unless (or (memq theme-name (custom-available-themes))
(eq 'default theme)) (eq 'default theme-name))
(let* ((pkg (spacemacs/get-theme-package theme)) (let* ((pkg-name (spacemacs/get-theme-package-name theme-name))
(pkg-dir (pkg-dir
(when pkg (when pkg-name
(configuration-layer/get-elpa-package-install-directory (configuration-layer/get-elpa-package-install-directory
pkg)))) pkg-name))))
(when pkg-dir (when pkg-dir
(add-to-list 'custom-theme-load-path pkg-dir) (add-to-list 'custom-theme-load-path pkg-dir)
(when (or (eq 'moe-light theme) (when (or (eq 'moe-light theme-name)
(eq 'moe-dark theme)) (eq 'moe-dark theme-name))
(load-file (concat pkg-dir "moe-light-theme.el")) (load-file (concat pkg-dir "moe-light-theme.el"))
(load-file (concat pkg-dir "moe-dark-theme.el")))))) (load-file (concat pkg-dir "moe-dark-theme.el"))))))
(when disable (when disable
(mapc 'disable-theme custom-enabled-themes)) (mapc 'disable-theme custom-enabled-themes))
(eval `(spacemacs|do-after-display-system-init (eval `(spacemacs|do-after-display-system-init
(load-theme ',theme t))) (load-theme ',theme-name t)))
(setq-default spacemacs--cur-theme theme) (setq-default spacemacs--cur-theme theme-name)
(setq-default spacemacs--cycle-themes (cdr dotspacemacs-themes))) (setq-default spacemacs--cycle-themes (cdr dotspacemacs-themes)))
('error ('error
(if fallback-theme (if fallback-theme
;; fallback to Spacemacs default theme ;; fallback to Spacemacs default theme
(progn (progn
(setq spacemacs--delayed-user-theme theme) (setq spacemacs--delayed-user-theme theme-name)
(spacemacs/load-fallback-theme fallback-theme disable)) (spacemacs/load-fallback-theme fallback-theme disable))
;; no fallback theme was specified, so we log explicit warning ;; no fallback theme was specified, so we log explicit warning
(spacemacs-buffer/warning (spacemacs-buffer/warning
(concat "An error occurred while applying " (concat "An error occurred while applying "
"the theme \"%s\", fallback on theme \"%s\". \n" "the theme \"%s\", fallback on theme \"%s\". \n"
"Error was: %s") theme spacemacs--fallback-theme err) "Error was: %s")
(spacemacs-buffer/warning theme-name spacemacs--fallback-theme err)
(concat "Please check the value of \"dotspacemacs-themes\" in your " (spacemacs-buffer/warning
"dotfile or open an issue \n" (concat "Please check the value of \"dotspacemacs-themes\" in your "
"so we can add support for the theme \"%s\".") theme))))) "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) (defun spacemacs/load-fallback-theme (theme &optional disable)
"Apply the fallback theme. "Apply the fallback theme.
If DISABLE is non-nil then disable all previously applied themes before applying If DISABLE is non-nil then disable all previously applied themes before applying
THEME." THEME."
;; pop up fallback theme to the top of the list (let ((theme-name (spacemacs//get-theme-name theme)))
(setq spacemacs--cur-theme theme) ;; pop up fallback theme to the top of the list
(setq dotspacemacs-themes (delq theme dotspacemacs-themes)) (setq spacemacs--cur-theme theme-name)
(add-to-list 'dotspacemacs-themes theme) (setq dotspacemacs-themes (delq theme-name dotspacemacs-themes))
(when disable (add-to-list 'dotspacemacs-themes theme-name)
(mapc 'disable-theme custom-enabled-themes)) (when disable
(eval `(spacemacs|do-after-display-system-init (mapc 'disable-theme custom-enabled-themes))
(load-theme ',theme t)))) (eval `(spacemacs|do-after-display-system-init
(load-theme ',theme-name t)))))
(defun spacemacs/cycle-spacemacs-theme () (defun spacemacs/cycle-spacemacs-theme ()
"Cycle through themes defined in `dotspacemacs-themes.'" "Cycle through themes defined in `dotspacemacs-themes.'"
@ -267,11 +283,19 @@ has been changed to THEME."
(interactive) (interactive)
(run-hooks 'spacemacs-post-theme-change-hook)) (run-hooks 'spacemacs-post-theme-change-hook))
(defun spacemacs//add-themes-to-additional-packages (themes) (defun spacemacs//add-theme-packages-to-additional-packages ()
"Add the THEMES packages to `dotspacemacs-additional-packages'." "Add all theme packages from `dotspacemacs-themes' to packages to install."
(dolist (theme themes) (setq dotspacemacs--additional-theme-packages nil)
(let ((pkg (spacemacs/get-theme-package theme))) (dolist (theme dotspacemacs-themes)
(when pkg (let* ((theme-name (spacemacs//get-theme-name theme))
(add-to-list 'dotspacemacs--additional-packages pkg))))) (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) (provide 'core-themes-support)

View File

@ -62,6 +62,10 @@
- [[#binding-keys][Binding keys]] - [[#binding-keys][Binding keys]]
- [[#gui-elements][GUI Elements]] - [[#gui-elements][GUI Elements]]
- [[#color-themes][Color themes]] - [[#color-themes][Color themes]]
- [[#default-theme][Default theme]]
- [[#choosing-themes][Choosing themes]]
- [[#browsing-themes][Browsing themes]]
- [[#notes][Notes]]
- [[#font][Font]] - [[#font][Font]]
- [[#gui-toggles][GUI Toggles]] - [[#gui-toggles][GUI Toggles]]
- [[#global-line-numbers][Global line numbers]] - [[#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]] - [[Errors handling][custom fringe bitmaps]] and error feedbacks for [[https://github.com/flycheck/flycheck][Flycheck]]
** Color themes ** Color themes
*** Default theme
The official Spacemacs theme is [[https://github.com/nashamri/spacemacs-theme][spacemacs-dark]] and it is the 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 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 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 comment background with the boolean =spacemacs-theme-comment-bg=
- the height of org section titles with =spacemacs-theme-org-height= - 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 It is possible to define your default themes in your =~/.spacemacs= with the
variable =dotspacemacs-themes=. For instance, to specify =spacemacs-light=, variable =dotspacemacs-themes=. For instance, to specify =spacemacs-light=,
=leuven= and =zenburn=: =leuven= and =zenburn=:
@ -1002,26 +1008,44 @@ variable =dotspacemacs-themes=. For instance, to specify =spacemacs-light=,
(setq-default dotspacemacs-themes '(spacemacs-light leuven zenburn)) (setq-default dotspacemacs-themes '(spacemacs-light leuven zenburn))
#+END_SRC #+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 | | Key Binding | Description |
|-------------+-------------------------------------------------------| |-------------+-------------------------------------------------------|
| ~SPC T n~ | switch to next theme listed in =dotspacemacs-themes=. | | ~SPC T n~ | switch to next theme listed in =dotspacemacs-themes=. |
| ~SPC T s~ | select a theme using a =helm= buffer. | | ~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*: *** Notes
- You don't need to explicitly list in a layer the theme packages you are - 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 defining in =dotspacemacs-themes=, Spacemacs is smart enough to remove those
packages from the list of orphans. packages from the list of orphans.
- Due to the inner working of themes in Emacs, switching theme during the same - 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 session may have some weird side effects. Although these side effects should
be pretty rare. be pretty rare.
- In the terminal version of Emacs, color themes will not render correctly as - 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 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 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]]. [[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 ;-)
** Font ** Font
The default font used by Spacemacs is [[https://github.com/adobe-fonts/source-code-pro][Source Code Pro]] by Adobe. It is The default font used by Spacemacs is [[https://github.com/adobe-fonts/source-code-pro][Source Code Pro]] by Adobe. It is