Skip to content

Commit e1eed07

Browse files
justbursyl20bnr
authored andcommitted
Add option for .spacemacs.d/init.el .spacemacs file
Setting SPACEMACSDIR overrides location of .spacemacs.d Add dotspacemacs-directory variable Add dotspacemacs-directory to layer search path
1 parent 7b47699 commit e1eed07

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

‎core/core-configuration-layer.el‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,13 @@ Returns nil if the directory is not a category."
208208
(defun configuration-layer//discover-layers ()
209209
"Return a hash table where the key is the layer symbol and the value is its
210210
path."
211-
;; load private layers at the end on purpose
212-
;; we asume that the user layers must have the final word
213-
;; on configuration choices.
211+
;; load private layers at the end on purpose we asume that the user layers
212+
;; must have the final word on configuration choices. Let
213+
;; `dotspacemacs-directory' override the private directory if it exists.
214214
(let ((search-paths (append (list configuration-layer-contrib-directory)
215215
dotspacemacs-configuration-layer-path
216-
(list configuration-layer-private-directory)))
216+
(list configuration-layer-private-directory)
217+
(list dotspacemacs-directory)))
217218
(discovered '())
218219
(result (make-hash-table :size 256)))
219220
;; depth-first search of subdirectories

‎core/core-dotspacemacs.el‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,38 @@
1313
(expand-file-name (concat spacemacs-core-directory "templates/"))
1414
"Templates directory.")
1515

16+
(defconst dotspacemacs-directory
17+
(let* ((env (getenv "SPACEMACSDIR"))
18+
(env-dir (if env (expand-file-name (concat env "/"))))
19+
(no-env-dir-default (expand-file-name
20+
(concat user-home-directory
21+
".spacemacs.d/"))))
22+
(cond
23+
((and env (file-exists-p env-dir))
24+
env-dir)
25+
((file-exists-p no-env-dir-default)
26+
no-env-dir-default)
27+
(t
28+
nil)))
29+
"Optional spacemacs directory, which defaults to
30+
~/.spacemacs.d. This setting can be overridden using the
31+
SPACEMACSDIR environment variable. If neither of these
32+
directories exist, this variable will be nil.")
33+
1634
(defconst dotspacemacs-filepath
17-
(concat user-home-directory ".spacemacs")
18-
"Filepath to the installed dotfile.")
35+
(let* ((default (concat user-home-directory ".spacemacs"))
36+
(spacemacs-dir-init (if dotspacemacs-directory
37+
(concat dotspacemacs-directory
38+
"init.el"))))
39+
(if (and (not (file-exists-p default))
40+
dotspacemacs-directory
41+
(file-exists-p spacemacs-dir-init))
42+
spacemacs-dir-init
43+
default))
44+
"Filepath to the installed dotfile. If ~/.spacemacs exists,
45+
then this is used. If ~/.spacemacs does not exist, then check
46+
for init.el in dotspacemacs-directory and use this if it
47+
exists. Otherwise, fallback to ~/.spacemacs")
1948

2049
(defvar dotspacemacs-verbose-loading nil
2150
"If non nil output loading progess in `*Messages*' buffer.")

0 commit comments

Comments
 (0)