Better theme support, easier to maintain

Resolves #388 #367
This commit is contained in:
syl20bnr 2015-01-13 22:14:48 -05:00
parent 891576a337
commit acaf2c1c83
2 changed files with 57 additions and 25 deletions

View File

@ -3,6 +3,7 @@
(require 'subr-x nil 'noerror)
(require 'emacs-backports)
(require 'themes-support)
(defconst spacemacs-version "0.46.1"
"Spacemacs version.")
@ -82,31 +83,9 @@
(setq cursor-type nil)
;; no welcome buffer
(setq inhibit-startup-screen t)
;; Unless Emacs stock themes
(unless (memq dotspacemacs-default-theme (custom-available-themes))
(cond
;; Spacemacs default theme
((or (eq 'solarized-light dotspacemacs-default-theme)
(eq 'solarized-dark dotspacemacs-default-theme))
(add-to-list 'load-path (concat spacemacs-directory
"extensions/solarized-theme/"))
;; solarized dependency
(spacemacs/load-or-install-package 'dash)
(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
((string-match "base16" (symbol-name dotspacemacs-default-theme))
(let ((pkg-dir (spacemacs/load-or-install-package 'base16-theme)))
(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))))
(spacemacs/load-or-install-package (intern pkg))))))
(load-theme dotspacemacs-default-theme t)
(setq-default spacemacs-cur-theme dotspacemacs-default-theme)
;; remove GUI elements if supported
(when window-system
;; those unless tests are for the case when the user has a ~/.emacs file
@ -126,6 +105,7 @@
(spacemacs/message (concat "No graphical support detected, you won't be"
"able to launch a graphical instance of Emacs"
"with this build.")))
(spacemacs/load-default-theme)
;; font
;; Dynamic font size depending on the system
(let ((font "Source Code Pro"))

52
core/themes-support.el Normal file
View File

@ -0,0 +1,52 @@
(defconst spacemacs-themes
'(
(base16-chalk . base16-theme)
(base16-default . base16-theme)
(base16-eighties . base16-theme)
(base16-greenscreen . base16-theme)
(base16-mocha . base16-theme)
(base16-monokai . base16-theme)
(base16-ocean . base16-theme)
(base16-railscasts . base16-theme)
(base16-solarized . base16-theme)
(base16-tomorrow . base16-theme)
(sanityinc-solarized-dark . color-theme-sanityinc-solarized)
(sanityinc-solarized-light . color-theme-sanityinc-solarized)
(sanityinc-tomorrow-blue . color-theme-sanityinc-tomorrow)
(sanityinc-tomorrow-bright . color-theme-sanityinc-tomorrow)
(sanityinc-tomorrow-day . color-theme-sanityinc-tomorrow)
(sanityinc-tomorrow-eighties . color-theme-sanityinc-tomorrow)
(sanityinc-tomorrow-night . color-theme-sanityinc-tomorrow)
)
"alist matching theme name with its package name.")
(defun spacemacs/load-default-theme ()
"Load the default theme defined in `dotspacemacs-default-theme'"
;; Unless Emacs stock themes
(unless (memq dotspacemacs-default-theme (custom-available-themes))
(cond
;; Spacemacs default theme
((or (eq 'solarized-light dotspacemacs-default-theme)
(eq 'solarized-dark dotspacemacs-default-theme))
(add-to-list 'load-path (concat spacemacs-directory
"extensions/solarized-theme/"))
;; solarized dependency
(spacemacs/load-or-install-package 'dash)
(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)))
(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))))
(spacemacs/load-or-install-package (intern pkg))))))
(load-theme dotspacemacs-default-theme t)
(setq-default spacemacs-cur-theme dotspacemacs-default-theme))
(provide 'themes-support)