Skip to content

Commit

Permalink
core: Don't delete bootstrap packages as orphans
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBB authored and syl20bnr committed Nov 5, 2015
1 parent 39b33e8 commit 6c0ba2c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
22 changes: 9 additions & 13 deletions core/core-configuration-layer.el
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
(defvar configuration-layer--skipped-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-error-count nil
"Non nil indicates the number of errors occurred during the
installation of initialization.")
Expand Down Expand Up @@ -1025,7 +1028,8 @@ to select one."

(defun configuration-layer//is-package-orphan (pkg-name dist-pkgs dependencies)
"Returns not nil if PKG-NAME is the name of an orphan package."
(unless (object-assoc pkg-name :name dist-pkgs)
(unless (or (object-assoc pkg-name :name dist-pkgs)
(memq pkg-name configuration-layer--protected-packages))
(if (ht-contains? dependencies pkg-name)
(let ((parents (ht-get dependencies pkg-name)))
(reduce (lambda (x y) (and x y))
Expand Down Expand Up @@ -1115,24 +1119,16 @@ to select one."
(t (let ((p (cadr (assq pkg-name package-alist))))
(when p (package-delete p))))))

(defun configuration-layer//filter-used-themes (orphans)
"Filter out used theme packages from ORPHANS candidates.
Returns the filtered list."
(delq nil (mapcar (lambda (x)
(and (not (memq x spacemacs-used-theme-packages))
x)) orphans)))

(defun configuration-layer/delete-orphan-packages (packages)
"Delete PACKAGES if they are orphan."
(interactive)
(let* ((dependencies (configuration-layer//get-packages-dependencies))
(implicit-packages (configuration-layer//get-implicit-packages
configuration-layer--used-distant-packages))
(orphans (configuration-layer//filter-used-themes
(configuration-layer//get-orphan-packages
configuration-layer--used-distant-packages
implicit-packages
dependencies)))
(orphans (configuration-layer//get-orphan-packages
configuration-layer--used-distant-packages
implicit-packages
dependencies))
(orphans-count (length orphans)))
;; (message "dependencies: %s" dependencies)
;; (message "implicit: %s" implicit-packages)
Expand Down
6 changes: 6 additions & 0 deletions core/core-funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
;;
;;; License: GPLv3

(defun spacemacs/load-or-install-protected-package (pkg &optional log file-to-load)
"Load PKG package, and protect it against being deleted as an orphan.
See `spacemacs/load-or-install-package' for more information."
(push pkg configuration-layer--protected-packages)
(spacemacs/load-or-install-package pkg log file-to-load))

(defun spacemacs/load-or-install-package (pkg &optional log file-to-load)
"Load PKG package. PKG will be installed if it is not already installed.
Whenever the initial require fails the absolute path to the package
Expand Down
28 changes: 15 additions & 13 deletions core/core-spacemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ initialization."
;; default theme
(let ((default-theme (car dotspacemacs-themes)))
(spacemacs/load-theme default-theme)
;; used to prevent automatic deletion of used packages
(setq spacemacs-used-theme-packages
(delq nil (mapcar 'spacemacs//get-theme-package
dotspacemacs-themes)))
;; protect used themes from deletion as orphans
(setq configuration-layer--protected-packages
(append
(delq nil (mapcar 'spacemacs//get-theme-package
dotspacemacs-themes))
configuration-layer--protected-packages))
(setq-default spacemacs--cur-theme default-theme)
(setq-default spacemacs--cycle-themes (cdr dotspacemacs-themes)))
;; removes the GUI elements
Expand Down Expand Up @@ -122,30 +124,30 @@ initialization."
(spacemacs-buffer/insert-banner-and-buttons)
;; mandatory dependencies
;; dash is required to prevent a package.el bug with f on 24.3.1
(spacemacs/load-or-install-package 'dash t)
(spacemacs/load-or-install-package 's t)
(spacemacs/load-or-install-protected-package 'dash t)
(spacemacs/load-or-install-protected-package 's t)
;; bind-key is required by use-package
(spacemacs/load-or-install-package 'bind-key t)
(spacemacs/load-or-install-package 'use-package t)
(spacemacs/load-or-install-protected-package 'bind-key t)
(spacemacs/load-or-install-protected-package 'use-package t)
(setq use-package-verbose dotspacemacs-verbose-loading)
;; package-build is required by quelpa
(spacemacs/load-or-install-package 'package-build t)
(spacemacs/load-or-install-protected-package 'package-build t)
(setq quelpa-verbose dotspacemacs-verbose-loading
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)
(spacemacs/load-or-install-package 'quelpa t)
(spacemacs/load-or-install-protected-package 'quelpa t)
;; inject use-package hooks for easy customization of
;; stock package configuration
(setq use-package-inject-hooks t)
;; which-key
(spacemacs/load-or-install-package 'which-key t)
(spacemacs/load-or-install-protected-package 'which-key t)
;; evil and evil-leader must be installed at the beginning of the
;; boot sequence.
;; Use C-u as scroll-up (must be set before actually loading evil)
(spacemacs/load-or-install-package 'evil t)
(spacemacs/load-or-install-package 'evil-leader t)
(spacemacs/load-or-install-protected-package 'evil t)
(spacemacs/load-or-install-protected-package 'evil-leader t)
(require 'core-evilified-state)
;; check for new version
(if dotspacemacs-mode-line-unicode-symbols
Expand Down
3 changes: 0 additions & 3 deletions core/core-themes-support.el
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@
"alist matching a theme name with its package name, required when
package name does not match theme name + `-theme' suffix.")

(defvar spacemacs-used-theme-packages nil
"List of packages of used themes.")

(defun spacemacs//get-theme-package (theme)
"Returns the package theme for the given THEME name."
(cond
Expand Down

0 comments on commit 6c0ba2c

Please sign in to comment.