-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
core-configuration-layer.el
2901 lines (2692 loc) · 131 KB
/
core-configuration-layer.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; core-configuration-layer.el --- Spacemacs Core File -*- lexical-binding: t -*-
;;
;; Copyright (c) 2012-2024 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(require 'cl-lib)
(require 'epg)
(require 'eieio)
(require 'subr-x)
(require 'package)
(require 'warnings)
(require 'help-mode)
(require 'spacemacs-ht)
(require 'core-dotspacemacs)
(require 'core-funcs)
(require 'core-progress-bar)
(require 'core-spacemacs-buffer)
(require 'core-load-paths)
(defvar configuration-layer--refresh-package-timeout dotspacemacs-elpa-timeout
"Timeout in seconds to reach a package archive page.")
(defvar configuration-layer--last-dotspacemacs-configuration-layers-file
(concat spacemacs-cache-directory "last-configuration-layers"))
(defconst configuration-layer-template-directory
(expand-file-name (concat spacemacs-core-directory "templates/"))
"Configuration layer templates directory.")
(defconst configuration-layer-directory
(expand-file-name (concat spacemacs-start-directory "layers/"))
"Spacemacs layers directory.")
(defconst configuration-layer-private-layer-directory
(let ((dotspacemacs-layer-dir
(when dotspacemacs-directory
(expand-file-name
(concat dotspacemacs-directory "layers/")))))
(if (and dotspacemacs-directory
(file-exists-p dotspacemacs-layer-dir))
dotspacemacs-layer-dir
spacemacs-private-directory))
"Spacemacs default directory for private layers.")
(defconst configuration-layer-lock-file
(concat spacemacs-start-directory ".lock")
"Absolute path to the lock file.")
(defvar configuration-layer-stable-elpa-version spacemacs-version
"Version of ELPA stable repository. This value is aimed to be defined in
the .lock file at the root of the repository.")
(defvar configuration-layer-stable-elpa-name "spacelpa"
"Name of the stable ELPA repository. Should be defined in the lock file.")
(defvar configuration-layer-elpa-subdirectory ""
"Sub-directory name where to install ELPA packages. Should be defined in
the lock file.")
(defconst configuration-layer-stable-elpa-directory
(expand-file-name
(concat spacemacs-cache-directory "stable-elpa/" emacs-version "/"))
"Remote location of the tarball for the ELPA stable directory")
(defconst configuration-layer-stable-elpa-archive nil
"Absolute path to stable ELPA directory. This value is aimed to be defined in
the .lock file at the root of the repository.")
(defconst configuration-layer--stable-elpa-tarball-directory
"https://github.com/syl20bnr/spacelpa/archive/"
"Remote location of the tarball for the ELPA stable directory")
(defconst configuration-layer--stable-elpa-sig-directory
"https://github.com/syl20bnr/spacelpa/releases/download/"
"Remote location of the signature file for the ELPA stable directory")
(defconst configuration-layer--stable-elpa-gpg-keyring
(expand-file-name (concat spacemacs-core-directory "gnupg/spacemacs.gpg"))
"Absolute path to public GPG key used to signed the ELPA stable repository
tarballs.")
(defconst configuration-layer--stable-elpa-version-file
(concat configuration-layer-stable-elpa-directory "version")
"Absolute path to the file containing the current stable elpa repository
version")
(defun configuration-layer/elpa-directory (root)
"Evaluate the correct package subdirectory of ROOT. This is
done according to the value of `dotspacemacs-elpa-subdirectory'.
This function also appends the name of the current branch of Spacemacs.
If `dotspacemacs-elpa-subdirectory' is nil, then ROOT is used. Otherwise the
subdirectory of ROOT is used."
(file-name-as-directory
(expand-file-name
configuration-layer-elpa-subdirectory
(if (not dotspacemacs-elpa-subdirectory)
root
(let ((subdir (if (eq 'emacs-version dotspacemacs-elpa-subdirectory)
(format "%d%s%d"
emacs-major-version
version-separator
emacs-minor-version)
(eval dotspacemacs-elpa-subdirectory))))
(expand-file-name subdir root))))))
(defun configuration-layer/get-elpa-package-install-directory (pkg)
"Return the install directory of elpa PKG. Return nil if it is not found."
(let ((elpa-dir package-user-dir))
(when (file-exists-p elpa-dir)
(let* ((pkg-match (concat "\\`" (symbol-name pkg) "-[0-9]+"))
(dir (car (directory-files elpa-dir 'full pkg-match))))
(when dir (file-name-as-directory dir))))))
(defvar configuration-layer-pre-load-hook nil
"Hook executed at the beginning of configuration loading.")
(defvar configuration-layer-post-load-hook nil
"Hook executed at the end of configuration loading.")
(defconst configuration-layer--elpa-root-directory
(concat spacemacs-start-directory "elpa/")
"Spacemacs ELPA root directory.")
(defconst configuration-layer--rollback-root-directory
(concat spacemacs-cache-directory ".rollback/")
"Spacemacs rollback root directory.")
(defvar configuration-layer-rollback-directory
configuration-layer--rollback-root-directory
"Spacemacs current rollback directory.")
(defconst configuration-layer-rollback-info "rollback-info"
"Spacemacs rollback information file.")
(defclass cfgl-layer ()
((name :initarg :name
:type symbol
:documentation "Name of the layer.")
(dir :initarg :dir
:initform nil
:type (satisfies (lambda (x) (or (null x) (stringp x))))
:documentation "Absolute path to the layer directory.")
(packages :initarg :packages
:initform nil
:type list
:documentation "List of package symbols declared in this layer.")
(selected-packages :initarg :selected-packages
:initform 'all
:type (satisfies (lambda (x) (or (and (symbolp x) (eq 'all x))
(listp x))))
:documentation "List of selected package symbols.")
(variables :initarg :variables
:initform nil
:type list
:documentation "A list of variable-value pairs.")
(lazy-install :initarg :lazy-install
:initform nil
:type boolean
:documentation
"If non-nil then the layer needs to be installed")
(disabled :initarg :disabled-for
:initform nil
:type list
:documentation "A list of layers where this layer is disabled.")
(enabled :initarg :enabled-for
:initform 'unspecified
:type (satisfies (lambda (x) (or (listp x) (eq 'unspecified x))))
:documentation
"A list of layers where this layer is enabled. (Takes precedence over `:disabled-for'.)")
;; Note:
;; 'can-shadow' is a commutative relation:
;; if Y 'can-shadow' X then X 'can-shadow' Y
;; but the 'shadow' operation is not commutative, the order of the operands
;; is determined by the order of the layers in the dotfile
;; (variable: dotspacemacs-configuration-layers)
(can-shadow :initarg :can-shadow
:initform 'unspecified
:type (satisfies (lambda (x) (or (listp x) (eq 'unspecified x))))
:documentation "A list of layers this layer can shadow.")
(deps-loaded :initarg :deps-loaded
:initform nil
:type boolean
:documentation
"Boolean to track whether layers.el has been loaded."))
"A configuration layer.")
(cl-defmethod cfgl-layer-owned-packages ((layer cfgl-layer) &optional props)
"Return the list of owned packages by LAYER.
If PROPS is non-nil then return packages as lists with their properties.
LAYER has to be installed for this method to work properly."
(delq nil (mapcar
(lambda (x)
(let* ((pkg-name (if (listp x) (car x) x))
(pkg (configuration-layer/get-package pkg-name)))
(when (eq (oref layer :name) (car (oref pkg :owners))) x)))
(cfgl-layer-get-packages layer props))))
(cl-defmethod cfgl-layer-owned-packages ((layer null) &optional props)
"Accept nil as argument and return nil."
nil)
(cl-defmethod cfgl-layer-get-shadowing-layers ((layer cfgl-layer))
"Return the list of used layers that shadow LAYER."
(let ((rank (cl-position (oref layer :name) configuration-layer--used-layers))
(shadow-candidates (oref layer :can-shadow))
shadowing-layers)
(when (and (numberp rank)
(not (eq 'unspecified shadow-candidates))
(listp shadow-candidates))
(mapc
(lambda (other)
(let ((orank (cl-position other configuration-layer--used-layers)))
;; OTHER shadows LAYER if and only if OTHER's rank is bigger than
;; LAYER's rank.
(when (and (numberp orank) (< rank orank))
(add-to-list 'shadowing-layers other))))
;; since the 'can-shadow' relation is commutative it is safe to use this
;; list, i.e. if LAYER can shadow layers X and Y then X and Y can shadow
;; LAYER.
shadow-candidates))
shadowing-layers))
(cl-defmethod cfgl-layer-get-packages ((layer cfgl-layer) &optional props)
"Return the list of packages for LAYER.
If PROPS is non-nil then return packages as lists along with their properties."
(let ((all (eq 'all (oref layer :selected-packages))))
(delq nil (mapcar
(lambda (x)
(let ((pkg-name (if (listp x) (car x) x)))
(when (or all (memq pkg-name
(oref layer :selected-packages)))
(if props x pkg-name))))
(oref layer :packages)))))
(defclass cfgl-package ()
((name :initarg :name
:type symbol
:documentation "Name of the package.")
(min-version :initarg :min-version
:initform nil
:type list
:documentation "Minimum version to install as a version list.")
(owners :initarg :owners
:initform nil
:type list
:documentation "The layer defining the init function.")
(pre-layers :initarg :pre-layers
:initform '()
:type list
:documentation "List of layers with a pre-init function.")
(post-layers :initarg :post-layers
:initform '()
:type list
:documentation "List of layers with a post-init function.")
(location :initarg :location
:initform elpa
:type (satisfies (lambda (x)
(or (stringp x)
(memq x '(built-in local site elpa))
(and (listp x) (eq 'recipe (car x))))))
:documentation "Location of the package.")
(toggle :initarg :toggle
:initform t
:type (satisfies (lambda (x) (or (symbolp x) (listp x))))
:documentation
"Package is enabled/installed if toggle evaluates to non-nil.")
(step :initarg :step
:initform nil
:type (satisfies (lambda (x) (member x '(nil bootstrap pre))))
:documentation "Initialization step.")
(lazy-install :initarg :lazy-install
:initform nil
:type boolean
:documentation
"If non-nil then the package needs to be installed")
(protected :initarg :protected
:initform nil
:type boolean
:documentation
"If non-nil then this package cannot be excluded.")
(excluded :initarg :excluded
:initform nil
:type boolean
:documentation
"If non-nil this package is excluded from all layers.")
(requires :initarg :requires
:initform nil
:type list
:documentation
"Packages that must be enabled for this package to be enabled.")))
(cl-defmethod cfgl-package-toggled-p ((pkg cfgl-package) &optional inhibit-messages)
"Evaluate the `toggle' slot of passed PKG.
If INHIBIT-MESSAGES is non nil then any message emitted by the toggle evaluation
is ignored."
(let ((message-log-max (unless inhibit-messages message-log-max))
(toggle (oref pkg :toggle)))
(eval toggle)))
(cl-defmethod cfgl-package-reqs-satisfied-p ((pkg cfgl-package) &optional inhibit-messages)
"Check if requirements of a package are all enabled.
If INHIBIT-MESSAGES is non nil then any message emitted by the toggle evaluation
is ignored."
(cl-every
(lambda (dep-pkg)
(let ((pkg-obj (configuration-layer/get-package dep-pkg)))
(when pkg-obj
(cfgl-package-enabled-p pkg-obj inhibit-messages))))
(oref pkg :requires)))
(cl-defmethod cfgl-package-enabled-p ((pkg cfgl-package) &optional inhibit-messages)
"Check if a package is enabled.
This checks the excluded property, evaluates the toggle, if any, and recursively
checks whether dependent packages are also enabled.
If INHIBIT-MESSAGES is non nil then any message emitted by the toggle evaluation
is ignored."
(and (or (oref pkg :protected) (not (oref pkg :excluded)))
(cfgl-package-reqs-satisfied-p pkg inhibit-messages)
(cfgl-package-toggled-p pkg inhibit-messages)))
(cl-defmethod cfgl-package-used-p ((pkg cfgl-package) &optional inhibit-messages)
"Return non-nil if PKG is a used package."
(and (not (null (oref pkg :owners)))
(not (oref pkg :excluded))
(cfgl-package-enabled-p pkg inhibit-messages)))
(cl-defmethod cfgl-package-distant-p ((pkg cfgl-package))
"Return non-nil if PKG is a distant package (i.e. not built-in Emacs)."
(and (not (memq (oref pkg :location) '(built-in site local)))
(not (stringp (oref pkg :location)))))
(cl-defmethod cfgl-package-get-safe-owner ((pkg cfgl-package))
"Safe method to return the name of the layer which owns PKG."
;; The owner of a package is the first *used* layer in `:owners' slot.
;; Note: for packages in `configuration-layer--used-packages' the owner is
;; always the car of the `:owners' slot.
(let ((layers (oref pkg :owners)))
(while (and (consp layers)
(not (configuration-layer/layer-used-p (car layers))))
(pop layers))
(when (configuration-layer/layer-used-p (car layers))
(car layers))))
(defvar configuration-layer-elpa-archives nil
"List of ELPA archives required by Spacemacs. This value is set by the lock
file.")
(defvar configuration-layer-exclude-all-layers nil
"If non nil then only the distribution layer is loaded.")
(defvar configuration-layer-force-distribution nil
"If set, bypass the user's choice `dotspacemacs-distribution'.")
(defvar configuration-layer--package-archives-refreshed nil
"Non nil if package archives have already been refreshed.")
(defvar configuration-layer--load-packages-files nil
"If non-nil force loading `packages.el' files when creating layer objects.")
(defvar configuration-layer--used-layers '()
"A non-sorted list of used layer names.")
(defvar configuration-layer--layers-dependencies '()
"List of layers declared in `layers.el' files.")
(defvar configuration-layer--indexed-layers (make-hash-table :size 1024)
"Hash map to index `cfgl-layer' objects by their names.")
(defvar configuration-layer--used-packages '()
"An alphabetically sorted list of used package names.")
(defvar configuration-layer--indexed-packages (make-hash-table :size 2048)
"Hash map to index `cfgl-package' objects by their names.")
(defvar configuration-layer--check-new-version-error-packages nil
"A list of all packages that were skipped during last update attempt.")
(defvar configuration-layer--protected-packages nil
"A list of packages that will be protected from removal as orphans.")
(defvar configuration-layer--lazy-mode-alist nil
"Association list where the key is a mode and the value a regexp.")
(defvar configuration-layer--inhibit-errors nil
"If non-nil then error messages emitted by the layer system are ignored.")
(defvar configuration-layer--inhibit-warnings nil
"If non-nil then warning messages emitted by the layer system are ignored.")
(defvar configuration-layer--package-properties-read-onlyp nil
"If non-nil then package properties are read only and cannot be overridden by
`configuration-layer/make-package'.")
(defvar configuration-layer--declared-layers-usedp nil
"If non-nil then declared layers are considered to be used.")
(defvar configuration-layer-error-count nil
"Non nil indicates the number of errors occurred during the
installation of initialization.")
(defvar configuration-layer-categories '()
"List of strings corresponding to category names. A category is a
directory with a name starting with `+'.")
(defvar update-packages-alist '()
"Used to collect information about rollback packages in the
cache folder.")
(defun configuration-layer/load-lock-file ()
"Load the .lock file"
(configuration-layer/load-file configuration-layer-lock-file))
(defun configuration-layer/initialize ()
"Initialize `package.el'."
(unless dotspacemacs-use-spacelpa
(configuration-layer//stable-elpa-disable-repository))
(setq configuration-layer--refresh-package-timeout dotspacemacs-elpa-timeout)
(unless package--initialized
(setq configuration-layer-rollback-directory
(configuration-layer/elpa-directory
configuration-layer--rollback-root-directory))
(setq package-user-dir
(configuration-layer/elpa-directory
configuration-layer--elpa-root-directory))
(setq package-archives (configuration-layer//resolve-package-archives
configuration-layer-elpa-archives))))
(autoload 'quelpa "quelpa")
(autoload 'quelpa-checkout "quelpa")
(defvar quelpa-upgrade-p)
(defun configuration-layer//configure-quelpa ()
"Configure `quelpa' package."
(with-eval-after-load 'quelpa
(setq quelpa-verbose init-file-debug
quelpa-dir (concat spacemacs-cache-directory "quelpa/")
quelpa-build-dir (expand-file-name "build" quelpa-dir)
quelpa-persistent-cache-file (expand-file-name "cache" quelpa-dir)
quelpa-update-melpa-p nil
quelpa-build-explicit-tar-format-p (eq (quelpa--tar-type) 'gnu))))
(defun configuration-layer//make-quelpa-recipe (pkg)
"Read recipe in PKG if :fetcher is local, then turn it to a correct file recepe.
Otherwise return the recipe unchanged. PKG is of `cfgl-package' type."
(let* ((config (cdr (oref pkg :location)))
(fetcher (plist-get config :fetcher))
(pkg-name (oref pkg :name)))
(cond
((eq fetcher 'local)
`(,pkg-name
:fetcher file
:path ,(configuration-layer/get-location-directory
(oref pkg :name)
(oref pkg :location)
(car (oref pkg :owners)))))
(t (cons pkg-name (cdr (oref pkg :location)))))))
(defun configuration-layer//package-archive-absolute-path-p (archive)
"Return t if ARCHIVE has an absolute path defined."
(let ((path (cdr archive)))
(or (string-match-p "http" path)
(string-prefix-p "~" path)
(eq (string-match-p "^[a-zA-Z]:" path) 0)
(string-prefix-p "/" path))))
(defun configuration-layer//package-archive-local-path-p (archive)
"Return t if ARCHIVE has a local path."
(let ((path (cdr archive)))
(or (string-prefix-p "~" path)
(string-prefix-p "/" path)
(eq (string-match-p "^[a-zA-Z]:" path) 0)
(string-prefix-p "\." path))))
(defun configuration-layer//resolve-package-archives (archives)
"Resolve HTTP handlers for each archive in ARCHIVES and return a list
of all reachable ones.
If the url of an archive already contains the protocol then this url is
left untouched.
The returned list has a `package-archives' compliant format."
(mapcar
(lambda (x)
(let ((aname (car x))
(apath (cdr x)))
(cons aname
(if (configuration-layer//package-archive-absolute-path-p x)
apath
(concat
"https://"
apath)))))
archives))
(defun configuration-layer/retrieve-package-archives (&optional quiet force)
"Retrieve all archives declared in current `package-archives'.
This function first performs a simple GET request with a timeout in order to
fix very long refresh time when an archive is not reachable.
Note that this simple GET is a heuristic to determine the availability
likelihood of an archive, so it can gives false positive if the archive
page is served but the archive is not.
If QUIET is non nil then the function does not print message in the Spacemacs
home buffer.
If FORCE is non nil then refresh the archives even if they have been already
refreshed during the current session."
(unless (and configuration-layer--package-archives-refreshed
(not force))
(setq configuration-layer--package-archives-refreshed t)
(let ((count (length package-archives))
(i 1))
(dolist (archive package-archives)
(let ((aname (car archive))
(apath (cdr archive)))
(unless quiet
(spacemacs-buffer/replace-last-line
(format "--> refreshing package archive: %s... [%s/%s]"
aname i count) t))
(spacemacs//redisplay)
(setq i (1+ i))
(unless
(and (not (configuration-layer//package-archive-local-path-p
archive))
(eq 'error
(with-timeout
(dotspacemacs-elpa-timeout
(progn
(display-warning
'spacemacs
(format
"\nError connection time out for %s repository!"
aname) :warning)
'error))
(condition-case err
(url-retrieve-synchronously apath)
('error
(display-warning
'spacemacs
(format
"\nError while contacting %s repository!"
aname) :warning)
'error)))))
(let ((package-archives (list archive)))
(package-refresh-contents)))))
(package-read-all-archive-contents)
(unless quiet (spacemacs-buffer/append "\n")))))
(defun configuration-layer/load ()
"Load layers declared in dotfile if necessary."
(run-hooks 'configuration-layer-pre-load-hook)
(let (changed-since-last-dump-p)
;; check if layer list has changed since last dump
(when (file-exists-p
configuration-layer--last-dotspacemacs-configuration-layers-file)
(configuration-layer/load-file
configuration-layer--last-dotspacemacs-configuration-layers-file))
(let ((layers dotspacemacs-configuration-layers))
(dotspacemacs|call-func dotspacemacs/layers "Calling dotfile layers...")
;; `dotspacemacs--configuration-layers-saved' is used to detect if the layer
;; list has been changed outside of function `dotspacemacs/layers'
(setq dotspacemacs--configuration-layers-saved
dotspacemacs-configuration-layers)
(setq changed-since-last-dump-p
(not (equal layers dotspacemacs-configuration-layers)))
;; save layers list to file
(spacemacs/dump-vars-to-file
'(dotspacemacs-configuration-layers)
configuration-layer--last-dotspacemacs-configuration-layers-file))
(cond
(changed-since-last-dump-p
;; dump
(configuration-layer//load)
(when (spacemacs/emacs-with-pdumper-set-p)
(configuration-layer/message "Layer list has changed since last dump.")
(configuration-layer//dump-emacs)))
(spacemacs-force-dump
;; force dump
(configuration-layer//load)
(when (spacemacs/emacs-with-pdumper-set-p)
(configuration-layer/message
(concat "--force-dump passed on the command line or configuration has "
"been reloaded, forcing a redump."))
(configuration-layer//dump-emacs)))
((spacemacs-is-dumping-p)
;; dumping
(configuration-layer//load))
((and (spacemacs/emacs-with-pdumper-set-p)
(spacemacs-run-from-dump-p))
;; dumped
(configuration-layer/message
"Running from a dumped file. Skipping the loading process!"))
(t
;; standard loading
(configuration-layer//load)
(when (spacemacs/emacs-with-pdumper-set-p)
(configuration-layer/message
(concat "Layer list has not changed since last time. "
"Skipping dumping process!"))))))
(run-hooks 'configuration-layer-post-load-hook))
(defun configuration-layer//dump-emacs ()
"Dump emacs."
(configuration-layer/message
(concat "Dumping Emacs asynchronously, "
"you should not quit this Emacs "
"session until the dump is finished."))
(spacemacs/dump-emacs))
(defun configuration-layer//load ()
"Actually load the layers.
To prevent package from being installed or uninstalled set the variable
`spacemacs-sync-packages' to nil."
;; declare used layers then packages as soon as possible to resolve
;; usage and ownership
(configuration-layer/discover-layers 'refresh-index)
(configuration-layer//declare-used-layers dotspacemacs-configuration-layers)
(configuration-layer//declare-used-packages configuration-layer--used-layers)
;; then load the functions and finally configure the layers
(configuration-layer//load-layers-files configuration-layer--used-layers
'("funcs"))
(configuration-layer//configure-layers configuration-layer--used-layers)
;; load layers lazy settings
(configuration-layer/load-auto-layer-file)
;; try the package-quickstart-file before detecting package installation
(when (and (or package-quickstart dotspacemacs-enable-package-quickstart)
package-quickstart-file)
(setq package-quickstart t)
(load (file-name-sans-extension package-quickstart-file) t nil nil t))
;; install and/or uninstall packages
(when spacemacs-sync-packages
(let ((packages
(append
;; install used packages
(configuration-layer//filter-distant-packages
configuration-layer--used-packages t
(lambda (pkg) (not (oref pkg :lazy-install))))
;; also install all other packages if requested
(when (eq 'all dotspacemacs-install-packages)
(let (all-other-packages)
(dolist (layer (configuration-layer/get-layers-list))
(let ((configuration-layer--declared-layers-usedp nil)
(configuration-layer--load-packages-files t))
(configuration-layer/declare-layer layer)
(let* ((obj (configuration-layer/get-layer layer))
(pkgs (when obj (oref obj :packages))))
(configuration-layer/make-packages-from-layers
(list layer))
(dolist (pkg pkgs)
(let ((pkg-name (if (listp pkg) (car pkg) pkg)))
(cl-pushnew pkg-name all-other-packages))))))
(configuration-layer//filter-distant-packages
all-other-packages nil))))))
(configuration-layer//install-packages packages)
(when (and (or (eq 'used dotspacemacs-install-packages)
(eq 'used-only dotspacemacs-install-packages))
(not configuration-layer-force-distribution)
(not configuration-layer-exclude-all-layers))
(configuration-layer/delete-orphan-packages packages))))
;; configure used packages
(configuration-layer//configure-packages configuration-layer--used-packages)
;; evaluate layer variables a second time to override default values set in
;; packages configuration above
(configuration-layer//set-layers-variables configuration-layer--used-layers)
(configuration-layer//load-layers-files configuration-layer--used-layers
'("keybindings"))
(when (spacemacs-is-dumping-p)
;; dump stuff in layers
(dolist (layer-name configuration-layer--used-layers)
(let ((layer-dump-func (intern (format "%S/pre-dump" layer-name))))
(when (fboundp layer-dump-func)
(configuration-layer/message "Pre-dumping layer %S..." layer-name)
(funcall layer-dump-func))))
(dotspacemacs|call-func dotspacemacs/user-load
"Calling dotfile user-load...")))
(defun configuration-layer/load-auto-layer-file ()
"Load `auto-layer.el' file"
(let ((file (concat configuration-layer-directory "auto-layer.el")))
(when (file-exists-p file)
(spacemacs-buffer/message "Loading auto-layer file...")
(configuration-layer/load-file file))))
(defun configuration-layer/create-layer ()
"Ask the user for a configuration layer name and the layer
directory to use. Create a layer with this name in the selected
layer directory."
(interactive)
(let* ((current-layer-paths (mapcar (lambda (dir) (expand-file-name dir))
(cl-pushnew
configuration-layer-private-layer-directory
dotspacemacs-configuration-layer-path)))
(other-choice "Another directory...")
(helm-lp-source
`((name . "Configuration Layer Paths")
(candidates . ,(append current-layer-paths
(list other-choice)))
(action . (lambda (c) c))))
(layer-path-sel (if (configuration-layer/layer-used-p 'helm)
(helm :sources helm-lp-source
:prompt "Configuration layer path: ")
(completing-read "Configuration layer path: "
(append current-layer-paths
(list other-choice)))))
(layer-path (cond
((string-equal layer-path-sel other-choice)
(read-directory-name (concat "Other configuration "
"layer path: ") "~/"))
((member layer-path-sel current-layer-paths)
layer-path-sel)
(t
(error "Please select an option from the list"))))
(name (read-from-minibuffer "Configuration layer name: "))
(layer-dir (concat layer-path "/" name)))
(cond
((string-equal "" name)
(configuration-layer/message
"Cannot create a configuration layer without a name."))
((file-exists-p layer-dir)
(configuration-layer/message
(concat "Cannot create configuration layer \"%s\", "
"this layer already exists.") name))
(t
(make-directory layer-dir t)
(configuration-layer//copy-template name "packages.el" layer-dir)
(when (y-or-n-p "Create readme?")
(configuration-layer//copy-template name "README.org" layer-dir))
(configuration-layer/message
"Configuration layer \"%s\" successfully created." name)))))
(defun configuration-layer//select-packages (layer-specs packages)
"Return the selected packages of LAYER-SPECS from given PACKAGES list."
(let* ((value (when (listp layer-specs)
(spacemacs/mplist-get-values layer-specs :packages)))
(selected-packages (if (and (not (null (car value)))
(listp (car value)))
(car value)
value)))
(cond
;; select packages
((and selected-packages
(not (memq (car selected-packages) '(all not))))
selected-packages)
;; unselect packages
((and selected-packages
(eq 'not (car selected-packages)))
(delq nil (mapcar (lambda (x)
(let ((pkg-name (if (listp x) (car x) x)))
(unless (memq pkg-name selected-packages)
pkg-name)))
packages)))
;; no package selections or all package selected
(t 'all))))
(defun configuration-layer/make-layer (layer-specs &optional obj usedp dir)
"Return a `cfgl-layer' object based on LAYER-SPECS.
If OBJ is non nil then copy LAYER-SPECS properties into OBJ, otherwise create
a new object.
DIR is the directory where the layer is, if it is nil then search in the indexed
layers for the path.
If USEDP or `configuration-layer--load-packages-files' is non-nil then the
`packages.el' file of the layer is loaded."
(let* ((layer-name (if (listp layer-specs) (car layer-specs) layer-specs))
(obj (if obj obj (cfgl-layer (symbol-name layer-name)
:name layer-name)))
(packages (oref obj :packages))
(dir (or dir (oref obj :dir))))
(if (or (null dir)
(and dir (not (file-exists-p dir))))
(configuration-layer//warning
"Cannot make layer %S without a valid directory!"
layer-name)
(let* ((dir (file-name-as-directory dir))
(disabled (when (listp layer-specs)
(spacemacs/mplist-get-values layer-specs :disabled-for)))
(enabled (if (and (listp layer-specs)
(memq :enabled-for layer-specs))
(spacemacs/mplist-get-values layer-specs :enabled-for)
'unspecified))
(variables (when (listp layer-specs)
(spacemacs/mplist-get-values layer-specs :variables)))
(shadow
(if (and (listp layer-specs)
(memq :can-shadow layer-specs))
(spacemacs/mplist-get-values layer-specs :can-shadow)
'unspecified))
(packages-file (locate-file "packages" (list dir) load-suffixes))
(packages (when (and (null packages)
(or usedp configuration-layer--load-packages-files)
packages-file)
(configuration-layer/load-file packages-file)
(symbol-value (intern (format "%S-packages"
layer-name)))))
(selected-packages (if packages
(configuration-layer//select-packages
layer-specs packages)
;; default value
'all)))
(oset obj :dir dir)
(when usedp
(oset obj :disabled-for disabled)
(oset obj :enabled-for enabled)
(oset obj :variables variables)
(unless (eq 'unspecified shadow)
(oset obj :can-shadow shadow)))
(when packages
(oset obj :packages packages)
(oset obj :selected-packages selected-packages))
obj))))
(defun configuration-layer/make-package (pkg-specs layer-name &optional obj)
"Return a `cfgl-package' object based on PKG-SPECS.
LAYER-NAME is the layer name where the PKG-SPECS is listed.
If OBJ is non nil then copy PKG-SPECS properties into OBJ, otherwise create
a new object."
(let* ((pkg-name (if (listp pkg-specs) (car pkg-specs) pkg-specs))
(pkg-name-str (symbol-name pkg-name))
(layer (unless (eq 'dotfile layer-name)
(configuration-layer/get-layer layer-name)))
(min-version (when (listp pkg-specs)
(plist-get (cdr pkg-specs) :min-version)))
(step (when (listp pkg-specs)
(plist-get (cdr pkg-specs) :step)))
(toggle (when (listp pkg-specs)
(plist-get (cdr pkg-specs) :toggle)))
(requires (when (listp pkg-specs)
(plist-get (cdr pkg-specs) :requires)))
(requires (if (listp requires) requires (list requires)))
(excluded (when (listp pkg-specs)
(plist-get (cdr pkg-specs) :excluded)))
(location (when (listp pkg-specs)
(plist-get (cdr pkg-specs) :location)))
(protected (when (listp pkg-specs)
(plist-get (cdr pkg-specs) :protected)))
(init-func (intern (format "%S/init-%S"
layer-name pkg-name)))
(pre-init-func (intern (format "%S/pre-init-%S"
layer-name pkg-name)))
(post-init-func (intern (format "%S/post-init-%S"
layer-name pkg-name)))
(copyp (not (null obj)))
(obj (if obj obj (cfgl-package pkg-name-str :name pkg-name)))
(ownerp (or (and (eq 'dotfile layer-name)
(null (oref obj :owners)))
(fboundp init-func))))
(when min-version
(oset obj :min-version
(version-to-list min-version)))
(when step
(oset obj :step step))
(when toggle
(oset obj :toggle toggle))
(when (and ownerp requires)
(oset obj :requires requires))
(oset obj :excluded
(and (configuration-layer/layer-used-p layer-name)
(or excluded (oref obj :excluded))))
(when location
(if (and (listp location)
(eq (car location) 'recipe)
(eq (plist-get (cdr location) :fetcher) 'local))
(cond
(layer (let ((path (expand-file-name
(format "%s%s"
(configuration-layer/get-layer-local-dir
layer-name)
pkg-name-str))))
(oset
obj :location `(recipe :fetcher file :path ,path))))
((eq 'dotfile layer-name) nil))
(oset obj :location location)))
;; cannot override protected packages
(unless copyp
;; a bootstrap package is protected
(oset
obj :protected (or protected (eq 'bootstrap step)))
(when protected
(push pkg-name configuration-layer--protected-packages)))
(when ownerp
;; warn about multiple owners
(when (and (oref obj :owners)
(not (memq layer-name (oref obj :owners))))
(configuration-layer//warning
(format (concat "More than one init function found for "
"package %S. Previous owner was %S, "
"replacing it with layer %S.")
pkg-name (car (oref obj :owners)) layer-name)))
;; last owner wins over the previous one
(object-add-to-list obj :owners layer-name))
;; check consistency between package and defined init functions
(unless (or ownerp
(eq 'dotfile layer-name)
(eq 'system layer-name)
(fboundp pre-init-func)
(fboundp post-init-func)
(oref obj :excluded))
(configuration-layer//warning
(format (concat "package %s not initialized in layer %s, "
"you may consider removing this package from "
"the package list or use the :toggle keyword "
"instead of a `when' form.")
pkg-name layer-name)))
;; check if toggle can be applied
(when (and (not ownerp)
(and (not (eq 'unspecified toggle))
toggle))
(configuration-layer//warning
(format (concat "Ignoring :toggle for package %s because "
"layer %S does not own it.")
pkg-name layer-name)))
;; check if requires can be applied
(when (and (not ownerp) requires)
(configuration-layer//warning
(format (concat "Ignoring :requires for package %s because "
"layer %S does not own it.")
pkg-name layer-name)))
(when (fboundp pre-init-func)
(object-add-to-list obj :pre-layers layer-name))
(when (fboundp post-init-func)
(object-add-to-list obj :post-layers layer-name))
obj))
(define-button-type 'help-dotfile-variable
:supertype 'help-xref
'help-function
(lambda (variable)
(with-current-buffer (find-file-noselect dotspacemacs-filepath)
(pop-to-buffer (current-buffer))
(goto-char (point-min))
;; try to exclude comments
(if (re-search-forward (format "^[a-z\s\\(\\-]*%s" variable)
nil 'noerror)
(beginning-of-line)
(configuration-layer/message "Unable to find location in file"))))
'help-echo
(purecopy (concat "mouse-2, RET: "
"visit the Spacemacs dotfile where variable is defined.")))
(define-button-type 'help-describe-package
:supertype 'help-xref
'help-function 'configuration-layer/describe-package
'help-echo
(purecopy (concat "mouse-2, RET: show a description of this package.")))
(defun configuration-layer/describe-package (pkg-symbol
&optional layer-list pkg-list)
"Describe a package in the context of the configuration layer system."
(interactive
(list (intern
(completing-read "Package: " configuration-layer--used-packages))))
(let* ((pkg (configuration-layer/get-package pkg-symbol))
(owners (oref pkg :owners))
(owner (car owners)))
(with-help-window (help-buffer)
;; declaration location
(princ pkg-symbol)
(princ " is a package declared and configured ")
(cond
((eq 'dotfile owner)
(princ "by the variable `dotspacemacs-additional-packages' ")
(with-current-buffer standard-output
(save-excursion
(re-search-backward "`\\([^`']+\\)'" nil t)
(help-xref-button 1 'help-variable
'dotspacemacs-additional-packages
dotspacemacs-filepath)))
(princ "in your `dotfile'.\n")
(with-current-buffer standard-output
(save-excursion
(re-search-backward "`\\([^`']+\\)'" nil t)
(help-xref-button
1 'help-dotfile-variable 'dotspacemacs-additional-packages))))
((not (null owner))
(let* ((layer (configuration-layer/get-layer owner))
(path (concat (oref layer dir) "packages.el")))
(princ "by the layer `")
(princ owner)
(princ "'.\n")
(with-current-buffer standard-output
(save-excursion
(re-search-backward "`\\([^`']+\\)'" nil t)
(help-xref-button