8
8
; ; This file is not part of GNU Emacs.
9
9
; ;
10
10
; ;; License: GPLv3
11
- ; ;
12
- ; ;; Commentary:
13
- ; ;
14
- ; ;; Code:
15
11
16
12
(require 'cl-lib )
17
13
(require 'eieio )
@@ -281,26 +277,40 @@ refreshed during the current session."
281
277
(package-read-all-archive-contents )
282
278
(unless quiet (spacemacs-buffer/append " \n " )))))
283
279
284
- (defun configuration-layer/sync ()
285
- " Synchronize declared layers in dotfile with spacemacs."
280
+ (defun configuration-layer/sync (&optional no-install )
281
+ " Synchronize declared layers in dotfile with spacemacs.
282
+ If NO-INSTALL is non nil then install steps are skipped."
286
283
(dotspacemacs|call-func dotspacemacs/layers " Calling dotfile layers..." )
287
284
(when (spacemacs-buffer//choose-banner)
288
285
(spacemacs-buffer//inject-version t ))
289
286
; ; layers
290
287
(setq configuration-layer--layers (configuration-layer//declare-layers))
291
288
(configuration-layer//configure-layers configuration-layer--layers)
289
+ (when dotspacemacs-enable-lazy-installation
290
+ (configuration-layer/load-auto-layer-file))
292
291
; ; packages
293
292
(setq configuration-layer--packages (configuration-layer//declare-packages
294
293
configuration-layer--layers))
295
294
(setq configuration-layer--used-distant-packages
296
295
(configuration-layer//get-distant-used-packages
297
296
configuration-layer--packages))
298
- (configuration-layer//install-packages
299
- (configuration-layer/filter-objects configuration-layer--used-distant-packages
300
- (lambda (x ) (not (oref x :lazy-install )))))
301
- (configuration-layer//configure-packages configuration-layer--packages)
302
- (when dotspacemacs-delete-orphan-packages
303
- (configuration-layer/delete-orphan-packages configuration-layer--packages)))
297
+ (unless no-install
298
+ (configuration-layer//install-packages
299
+ (configuration-layer/filter-objects
300
+ configuration-layer--used-distant-packages
301
+ (lambda (x )
302
+ (not (oref x :lazy-install )))))
303
+ (configuration-layer//configure-packages configuration-layer--packages)
304
+ (when dotspacemacs-delete-orphan-packages
305
+ (configuration-layer/delete-orphan-packages
306
+ configuration-layer--packages))))
307
+
308
+ (defun configuration-layer/load-auto-layer-file ()
309
+ " Load `auto-layer.el' file"
310
+ (let ((file (concat configuration-layer-directory " auto-layer.el" )))
311
+ (when (file-exists-p file)
312
+ (spacemacs-buffer/message " Loading auto-layer file..." )
313
+ (load-file file))))
304
314
305
315
(defun configuration-layer/create-layer ()
306
316
" Ask the user for a configuration layer name and the layer
@@ -369,17 +379,18 @@ layer directory."
369
379
" Make `cfgl-layer' objects from the passed layer SYMBOLS."
370
380
(delq nil (mapcar 'configuration-layer/make-layer symbols)))
371
381
372
- (defun configuration-layer/make-package (pkg &optional obj )
382
+ (defun configuration-layer/make-package (pkg &optional obj togglep )
373
383
" Return a `cfgl-package' object based on PKG.
374
384
If OBJ is non nil then copy PKG properties into OBJ, otherwise create
375
385
a new object.
376
- Properties that can be copied are `:location' , `:step' and `:excluded' ."
386
+ Properties that can be copied are `:location' , `:step' and `:excluded' .
387
+ If TOGGLEP is non nil then `:toggle' parameter is ignored."
377
388
(let* ((name-sym (if (listp pkg) (car pkg) pkg))
378
389
(name-str (symbol-name name-sym))
379
390
(location (when (listp pkg) (plist-get (cdr pkg) :location )))
380
391
(step (when (listp pkg) (plist-get (cdr pkg) :step )))
381
392
(excluded (when (listp pkg) (plist-get (cdr pkg) :excluded )))
382
- (toggle (when (listp pkg) (plist-get (cdr pkg) :toggle )))
393
+ (toggle (when (and togglep ( listp pkg) ) (plist-get (cdr pkg) :toggle )))
383
394
(protected (when (listp pkg) (plist-get (cdr pkg) :protected )))
384
395
(copyp (not (null obj)))
385
396
(obj (if obj obj (cfgl-package name-str :name name-sym))))
@@ -602,23 +613,30 @@ Properties that can be copied are `:location', `:step' and `:excluded'."
602
613
name pkg-name)))
603
614
(post-init-func (intern (format " %S /post-init-%S "
604
615
name pkg-name)))
616
+ (ownerp (fboundp init-func))
605
617
(obj (object-assoc pkg-name :name result)))
606
618
(cl-pushnew pkg-name (oref layer :packages ))
607
619
(if obj
608
- (setq obj (configuration-layer/make-package pkg obj))
609
- (setq obj (configuration-layer/make-package pkg))
620
+ (setq obj (configuration-layer/make-package pkg obj ownerp ))
621
+ (setq obj (configuration-layer/make-package pkg nil ownerp ))
610
622
(push obj result))
611
623
(oset obj :lazy-install lazy-install)
612
- (when ( fboundp init-func)
624
+ (when ownerp
613
625
; ; last owner wins over the previous one,
614
626
; ; still warn about mutliple owners
615
627
(when (oref obj :owner )
616
628
(spacemacs-buffer/warning
617
629
(format (concat " More than one init function found for "
618
630
" package %S. Previous owner was %S, "
619
631
" replacing it with layer %S." )
620
- pkg (oref obj :owner ) name)))
632
+ pkg-name (oref obj :owner ) name)))
621
633
(oset obj :owner name))
634
+ (when (and (not ownerp)
635
+ (listp pkg)
636
+ (spacemacs/mplist-get pkg :toggle ))
637
+ (spacemacs-buffer/warning
638
+ (format (concat " Ignoring :toggle for package %s because "
639
+ " layer %S does not own it." ) pkg-name name)))
622
640
(when (fboundp pre-init-func)
623
641
(push name (oref obj :pre-layers )))
624
642
(when (fboundp post-init-func)
@@ -629,8 +647,8 @@ Properties that can be copied are `:location', `:step' and `:excluded'."
629
647
(let* ((pkg-name (if (listp pkg) (car pkg) pkg))
630
648
(obj (object-assoc pkg-name :name result)))
631
649
(if obj
632
- (setq obj (configuration-layer/make-package pkg obj))
633
- (setq obj (configuration-layer/make-package pkg))
650
+ (setq obj (configuration-layer/make-package pkg obj t ))
651
+ (setq obj (configuration-layer/make-package pkg nil t ))
634
652
(push obj result)
635
653
(oset obj :owner 'dotfile ))))
636
654
(dolist (xpkg dotspacemacs-excluded-packages)
@@ -649,23 +667,24 @@ Properties that can be copied are `:location', `:step' and `:excluded'."
649
667
(defun configuration-layer/lazy-install (layer-name &rest props )
650
668
" Configure auto-installation of layer with name LAYER-NAME."
651
669
(declare (indent 1 ))
652
- (when dotspacemacs-enable-lazy-installation
653
- (let ((layer (object-assoc layer-name :name configuration-layer--layers))
654
- (extensions (spacemacs/mplist-get props :extensions )))
655
- (oset layer :lazy-install t )
656
- (dolist (x extensions)
657
- (let ((ext (car x))
658
- (mode (cadr x)))
659
- (add-to-list 'configuration-layer--lazy-mode-alist (cons mode ext))
660
- (add-to-list
661
- 'auto-mode-alist
662
- `(, ext . (lambda ()
663
- (configuration-layer//auto-mode
664
- ', layer-name ', mode )))))))))
670
+ (let ((extensions (spacemacs/mplist-get props :extensions )))
671
+ (when (configuration-layer/layer-usedp layer-name)
672
+ (let ((layer (object-assoc layer-name
673
+ :name configuration-layer--layers)))
674
+ (oset layer :lazy-install t )))
675
+ (dolist (x extensions)
676
+ (let ((ext (car x))
677
+ (mode (cadr x)))
678
+ (add-to-list 'configuration-layer--lazy-mode-alist (cons mode ext))
679
+ (add-to-list
680
+ 'auto-mode-alist
681
+ `(, ext . (lambda ()
682
+ (configuration-layer//auto-mode
683
+ ', layer-name ', mode ))))))))
665
684
666
685
(defun configuration-layer//auto-mode (layer-name mode )
667
686
" Auto mode support of lazily installed layers."
668
- (when (configuration-layer//lazy-install-packages layer-name)
687
+ (when (configuration-layer//lazy-install-packages layer-name mode )
669
688
(funcall mode)))
670
689
671
690
(defun configuration-layer/filter-objects (objects ffunc )
@@ -951,24 +970,32 @@ path."
951
970
(format (concat " \n An error occurred while installing %s "
952
971
" (error: %s)\n " ) pkg-name err)))))))
953
972
954
- (defun configuration-layer//lazy-install-packages (layer-name )
955
- " Install packages of a lazily installed layer.
973
+ (defun configuration-layer//lazy-install-p (layer-name )
974
+ " Return non nil if the layer with LAYER-NAME should be lazy installed."
975
+ (or (not (memq layer-name configuration-layer--layers))
976
+ (let ((layer (object-assoc layer-name :name configuration-layer--layers)))
977
+ (oref layer :lazy-install ))))
978
+
979
+ (defun configuration-layer//lazy-install-packages (layer-name mode )
980
+ " Install layer with LAYER-NAME to support MODE.
956
981
Returns non-nil if the packages have been installed."
957
- (let* ((layer (object-assoc layer-name :name configuration-layer--layers))
958
- (packages (delq nil (mapcar (lambda (x )
959
- (object-assoc
960
- x :name configuration-layer--packages))
961
- (oref layer :packages ))))
962
- (pkg-count (length packages)))
963
- (when (and (oref layer :lazy-install )
964
- (yes-or-no-p (format
965
- (concat " Support for %s requires installation of "
966
- " %s package(s), do you want to install?" )
967
- layer-name pkg-count)))
982
+ (when (and (configuration-layer//lazy-install-p layer-name)
983
+ (yes-or-no-p (format
984
+ (concat " Support for %s requires installation of "
985
+ " layer %s, do you want to install it?" )
986
+ mode layer-name)))
987
+ (when (dotspacemacs/add-layer layer-name)
988
+ (configuration-layer/sync 'no-install ))
989
+ (let* ((layer (object-assoc layer-name :name configuration-layer--layers))
990
+ (packages (delq nil
991
+ (mapcar (lambda (x )
992
+ (object-assoc
993
+ x :name configuration-layer--packages))
994
+ (oref layer :packages )))))
968
995
(configuration-layer//install-packages packages)
969
996
(configuration-layer//configure-packages packages)
970
997
(oset layer :lazy-install nil ))
971
- ( not ( oref layer :lazy-install )) ))
998
+ t ))
972
999
973
1000
(defun configuration-layer//install-packages (packages )
974
1001
" Install PACKAGES which are not lazy installed."
@@ -1566,28 +1593,32 @@ to select one."
1566
1593
(when ext (push (cons mode ext) result)))))
1567
1594
result))
1568
1595
1569
- (defun configuration-layer//insert-lazy-install-form (mode ext )
1596
+ (defun configuration-layer//insert-lazy-install-form (layer-name mode ext )
1570
1597
" Insert a configuration form for lazy installation of MODE."
1571
1598
(let ((str (concat " (configuration-layer/lazy-install '"
1572
- (symbol-name mode )
1599
+ (symbol-name layer-name )
1573
1600
" :extensions '("
1574
1601
(let ((print-quoted t )) (prin1-to-string ext))
1602
+ " "
1603
+ (symbol-name mode)
1575
1604
" ))\n " )))
1576
1605
(insert str)))
1577
1606
1578
1607
(defun configuration-layer/insert-lazy-install-configuration ()
1579
1608
" Prompt for a layer and insert the forms to configure lazy installation."
1580
1609
(interactive )
1581
- (let ((layer-sym
1582
- (completing-read
1583
- " Choose a used layer"
1584
- (sort (object-assoc-list :name configuration-layer--layers)
1585
- (lambda (x y )
1586
- (string< (oref (cdr x) :name ) (oref (cdr y) :name )))))))
1610
+ (let ((layer-name
1611
+ (intern (completing-read
1612
+ " Choose a used layer"
1613
+ (sort (object-assoc-list :name configuration-layer--layers)
1614
+ (lambda (x y )
1615
+ (string< (oref (cdr x) :name )
1616
+ (oref (cdr y) :name ))))))))
1587
1617
(let ((mode-exts (configuration-layer//lazy-install-extensions-for-layer
1588
- ( intern layer-sym) )))
1618
+ layer-name )))
1589
1619
(dolist (x mode-exts)
1590
- (configuration-layer//insert-lazy-install-form (car x) (cdr x))))))
1620
+ (configuration-layer//insert-lazy-install-form
1621
+ layer-name (car x) (cdr x))))))
1591
1622
1592
1623
(defun configuration-layer//increment-error-count ()
1593
1624
" Increment the error counter."
0 commit comments