diff --git a/core/core-configuration-layer.el b/core/core-configuration-layer.el index 0231e01e3..891aabff7 100644 --- a/core/core-configuration-layer.el +++ b/core/core-configuration-layer.el @@ -292,8 +292,7 @@ If NO-INSTALL is non nil then install steps are skipped." (setq configuration-layer--used-distant-packages (configuration-layer//get-distant-used-packages configuration-layer--packages)) - (when dotspacemacs-enable-lazy-installation - (configuration-layer/load-auto-layer-file)) + (configuration-layer/load-auto-layer-file) (unless no-install (configuration-layer//install-packages (configuration-layer/filter-objects @@ -667,34 +666,35 @@ If TOGGLEP is non nil then `:toggle' parameter is ignored." (defun configuration-layer/lazy-install (layer-name &rest props) "Configure auto-installation of layer with name LAYER-NAME." (declare (indent 1)) - (let ((extensions (spacemacs/mplist-get props :extensions))) - (when (configuration-layer/layer-usedp layer-name) - (let* ((layer (object-assoc layer-name - :name configuration-layer--layers)) - (packages (when layer (cfgl-layer-owned-packages layer)))) - ;; set lazy install flag for a layer if and only if all its owned - ;; distant packages are not already installed - (let ((lazy (cl-reduce (lambda (x y) (and x y)) - (mapcar - (lambda (p) - (or (not (eq layer-name (oref p :owner))) - (null (package-installed-p - (oref p :name))))) - (configuration-layer//get-distant-used-packages - packages)) - :initial-value t))) - (oset layer :lazy-install lazy) - (dolist (pkg packages) - (oset pkg :lazy-install lazy))))) - (dolist (x extensions) - (let ((ext (car x)) - (mode (cadr x))) - (add-to-list 'configuration-layer--lazy-mode-alist (cons mode ext)) - (add-to-list - 'auto-mode-alist - `(,ext . (lambda () - (configuration-layer//auto-mode - ',layer-name ',mode)))))))) + (when (configuration-layer//lazy-install-p layer-name) + (let ((extensions (spacemacs/mplist-get props :extensions))) + (when (configuration-layer/layer-usedp layer-name) + (let* ((layer (object-assoc layer-name + :name configuration-layer--layers)) + (packages (when layer (cfgl-layer-owned-packages layer)))) + ;; set lazy install flag for a layer if and only if all its owned + ;; distant packages are not already installed + (let ((lazy (cl-reduce + (lambda (x y) (and x y)) + (mapcar (lambda (p) + (or (not (eq layer-name (oref p :owner))) + (null (package-installed-p + (oref p :name))))) + (configuration-layer//get-distant-used-packages + packages)) + :initial-value t))) + (oset layer :lazy-install lazy) + (dolist (pkg packages) + (oset pkg :lazy-install lazy))))) + (dolist (x extensions) + (let ((ext (car x)) + (mode (cadr x))) + (add-to-list 'configuration-layer--lazy-mode-alist (cons mode ext)) + (add-to-list + 'auto-mode-alist + `(,ext . (lambda () + (configuration-layer//auto-mode + ',layer-name ',mode))))))))) (defun configuration-layer//auto-mode (layer-name mode) "Auto mode support of lazily installed layers." @@ -987,9 +987,9 @@ path." (defun configuration-layer//lazy-install-p (layer-name) "Return non nil if the layer with LAYER-NAME should be lazy installed." - (let ((layer (object-assoc layer-name :name configuration-layer--layers))) - (or (null layer) - (oref layer :lazy-install)))) + (or (memq dotspacemacs-enable-lazy-installation '(all t)) + (and (eq 'unused dotspacemacs-enable-lazy-installation) + (not (configuration-layer/layer-usedp layer-name))))) (defun configuration-layer//lazy-install-packages (layer-name mode) "Install layer with LAYER-NAME to support MODE." diff --git a/core/core-dotspacemacs.el b/core/core-dotspacemacs.el index 9e5a3cd17..fa07c26db 100644 --- a/core/core-dotspacemacs.el +++ b/core/core-dotspacemacs.el @@ -65,8 +65,15 @@ environment, otherwise it is strongly recommended to let it set to t.") "List of additional paths where to look for configuration layers. Paths must have a trailing slash (ie. `~/.mycontribs/')") -(defvar dotspacemacs-enable-lazy-installation t - "If non-nil layers with lazy install support are lazy installed.") +(defvar dotspacemacs-enable-lazy-installation 'unused + " Lazy installation of layers (i.e. layers are installed only when a file +with a supported type is opened). Possible values are `all', `unused' and `nil'. +`unused' will lazy install only unused layers (i.e. layers not listed in +variable `dotspacemacs-configuration-layers'), `all' will lazy install any layer +that support lazy installation even the layers listed in +`dotspacemacs-configuration-layers'. `nil' disable the lazy installation feature +and you have to explicitly list a layer in the variable +`dotspacemacs-configuration-layers' to install it.") (defvar dotspacemacs-additional-packages '() "List of additional packages that will be installed wihout being diff --git a/core/templates/.spacemacs.template b/core/templates/.spacemacs.template index 82fa3b05f..ca71d8c82 100644 --- a/core/templates/.spacemacs.template +++ b/core/templates/.spacemacs.template @@ -11,6 +11,16 @@ values." ;; `+distribution'. For now available distributions are `spacemacs-base' ;; or `spacemacs'. (default 'spacemacs) dotspacemacs-distribution 'spacemacs + ;; Lazy installation of layers (i.e. layers are installed only when a file + ;; with a supported type is opened). Possible values are `all', `unused' + ;; and `nil'. `unused' will lazy install only unused layers (i.e. layers + ;; not listed in variable `dotspacemacs-configuration-layers'), `all' will + ;; lazy install any layer that support lazy installation even the layers + ;; listed in `dotspacemacs-configuration-layers'. `nil' disable the lazy + ;; installation feature and you have to explicitly list a layer in the + ;; variable `dotspacemacs-configuration-layers' to install it. + ;; (default 'unused) + dotspacemacs-enable-lazy-installation 'unused ;; If non-nil layers with lazy install support are lazy installed. ;; (default t) dotspacemacs-enable-lazy-installation t