core: add support for :location keyword in dotspacemacs-themes
New functions: - configuration-layer/get-location-directory which return the location on disk given a location - spacemacs//get-theme-directory which returns the location on disk of the theme Add note in documentation to warn about the directory name when :location local is used, the directory name is the package name not the theme name.
This commit is contained in:
parent
be7ba7f920
commit
252547aa81
|
@ -1576,25 +1576,12 @@ wether the declared layer is an used one or not."
|
|||
(spacemacs-buffer/message (format "%S is toggled off." pkg-name)))
|
||||
(t
|
||||
;; load-path
|
||||
(let ((location (oref pkg :location)))
|
||||
(cond
|
||||
((stringp location)
|
||||
(if (file-directory-p location)
|
||||
(push (file-name-as-directory location) load-path)
|
||||
(configuration-layer//warning
|
||||
"Location path for package %S does not exists (value: %s)."
|
||||
pkg location)))
|
||||
((and (eq 'local location)
|
||||
(eq 'dotfile (car (oref pkg :owners))))
|
||||
(push (file-name-as-directory
|
||||
(concat configuration-layer-private-directory "local/"
|
||||
(symbol-name (oref pkg :name))))
|
||||
load-path))
|
||||
((eq 'local location)
|
||||
(let* ((owner (configuration-layer/get-layer
|
||||
(car (oref pkg :owners))))
|
||||
(dir (when owner (oref owner :dir))))
|
||||
(push (format "%slocal/%S/" dir pkg-name) load-path)))))
|
||||
(let ((dir (configuration-layer/get-location-directory
|
||||
pkg-name
|
||||
(oref pkg :location)
|
||||
(car (oref pkg :owners)))))
|
||||
(when dir
|
||||
(add-to-list 'load-path dir)))
|
||||
;; configuration
|
||||
(unless (memq (oref pkg :location) '(local site built-in))
|
||||
(configuration-layer//activate-package pkg-name))
|
||||
|
@ -1605,6 +1592,27 @@ wether the declared layer is an used one or not."
|
|||
(t
|
||||
(configuration-layer//configure-package pkg))))))))
|
||||
|
||||
(defun configuration-layer/get-location-directory (pkg-name location owner)
|
||||
"Return the location on disk for PKG."
|
||||
(cond
|
||||
((stringp location)
|
||||
(if (file-directory-p location)
|
||||
(file-name-as-directory location)
|
||||
(configuration-layer//warning
|
||||
"Location path for package %S does not exists (value: %s)."
|
||||
pkg-name location)
|
||||
nil))
|
||||
((eq 'local location)
|
||||
(let ((dir (if (eq 'dotfile owner)
|
||||
configuration-layer-private-directory
|
||||
(let* ((owner (configuration-layer/get-layer owner)))
|
||||
(when owner (oref owner :dir))))))
|
||||
(if dir
|
||||
(file-name-as-directory (format "%slocal/%S/" dir pkg-name))
|
||||
(configuration-layer//warning
|
||||
"Cannot find path location path for package %S." pkg-name)
|
||||
nil)))))
|
||||
|
||||
(defun configuration-layer//package-enabled-p (pkg layer)
|
||||
"Returns true if PKG should be configured for LAYER.
|
||||
LAYER must not be the owner of PKG."
|
||||
|
|
|
@ -184,6 +184,20 @@ package name does not match theme name + `-theme' suffix.")
|
|||
(car theme)
|
||||
theme))
|
||||
|
||||
(defun spacemacs//get-theme-package-directory (theme)
|
||||
"Return the THEME location on disk."
|
||||
(let* ((theme-name (spacemacs//get-theme-name theme))
|
||||
(pkg-name (spacemacs/get-theme-package-name theme-name))
|
||||
(dir (configuration-layer/get-location-directory
|
||||
pkg-name
|
||||
(plist-get (cdr theme) :location)
|
||||
'dotfile)))
|
||||
(unless dir
|
||||
;; fallback to elpa directory
|
||||
(setq dir (configuration-layer/get-elpa-package-install-directory
|
||||
pkg-name)))
|
||||
dir))
|
||||
|
||||
(defun spacemacs/load-default-theme (&optional fallback-theme)
|
||||
"Load default theme.
|
||||
Default theme is the car of `dotspacemacs-themes'.
|
||||
|
@ -203,16 +217,11 @@ THEME."
|
|||
;; 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))))
|
||||
;; add theme package directory to load-path since `package.el' may
|
||||
;; not be initialized when theme is applied
|
||||
(let ((pkg-dir (spacemacs//get-theme-package-directory theme)))
|
||||
(when pkg-dir
|
||||
(add-to-list 'custom-theme-load-path pkg-dir)
|
||||
(add-to-list 'load-path pkg-dir)
|
||||
;; do we still need this particual case for moe theme?
|
||||
(when (or (eq 'moe-light theme-name)
|
||||
(eq 'moe-dark theme-name))
|
||||
(load-file (concat pkg-dir "moe-light-theme.el"))
|
||||
|
|
|
@ -1026,6 +1026,13 @@ declaration:
|
|||
))
|
||||
#+END_SRC
|
||||
|
||||
*Important note:* If you use =:location local= then you have to put your theme
|
||||
in the directory =private/local/<theme-package-name>/= with =theme-package-name=
|
||||
being the name of your package suffixed with =-theme= as mentioned in the Emacs
|
||||
conventions.
|
||||
For instance if your theme is =foo= then you have to put our theme
|
||||
files in the directory =private/local/foo-theme=.
|
||||
|
||||
You can cycle between the themes declared in =dotspacemacs-themes= with
|
||||
~SPC T n~ and select an installed theme with ~SPC T s~.
|
||||
|
||||
|
|
Loading…
Reference in New Issue