core: package-list-v2 sort package list

This commit is contained in:
syl20bnr 2015-08-07 22:51:27 -04:00
parent e145f73b8b
commit e4748ea692
2 changed files with 32 additions and 14 deletions

View file

@ -112,10 +112,10 @@
:documentation "If non-nil this package is ignored.")))
(defvar configuration-layer-layers '()
"A list of `cfgl-layer' objects.")
"A non-sorted list of `cfgl-layer' objects.")
(defvar configuration-layer-packages '()
"A list of `cfgl-package' objects.")
"An alphabetically sorted list of `cfgl-package' objects.")
(defvar configuration-layer-error-count nil
"Non nil indicates the number of errors occurred during the
@ -314,6 +314,11 @@ layer directory."
(oset obj :excluded t))))
result))
(defun configuration-layer//sort-packages (packages)
"Return a sorted list of PACKAGES objects."
(sort packages (lambda (x y) (string< (symbol-name (oref x :name))
(symbol-name (oref y :name))))))
(defun configuration-layer//get-private-layer-dir (name)
"Return an absolute path the the private configuration layer with name
NAME."
@ -483,21 +488,21 @@ LAYERS is a list of layer symbols."
(warning-minimum-level :error))
(configuration-layer//set-layers-variables layers)
;; first load all the config files ...
(configuration-layer//load-layers-files layers '("funcs.el"
"config.el"))
(configuration-layer//load-layers-files
layers '("funcs.el" "config.el"))
;; ... then the package files
;; TODO remove extensions in 0.105.0
(configuration-layer//load-layers-files layers '("packages.el"
"extensions.el"))
;; fill the hash tables
(configuration-layer//load-layers-files
layers '("packages.el" "extensions.el"))
;; read layers
(setq configuration-layer-packages
(configuration-layer/get-packages layers t))
(configuration-layer//sort-packages
(configuration-layer/get-packages layers t)))
;; number of chuncks for the loading screen
(setq spacemacs-loading-dots-chunk-threshold
(/ (length configuration-layer-packages)
spacemacs-loading-dots-chunk-count))
;; sort packages before installing and configuring them
(configuration-layer//sort-packages)
;; install and configuration
(configuration-layer//install-packages)
(configuration-layer//configure-packages)
;; finally load the remaining files of a layer
@ -520,10 +525,6 @@ LAYERS is a list of layer symbols."
(symbol-value `(push ',layer list))
(puthash pkg list hash)))
(defun configuration-layer/sort-hash-table-keys (h)
"Return a sorted list of the keys in the given hash table H."
(mapcar 'intern (sort (mapcar 'symbol-name (ht-keys h)) 'string<)))
(defun configuration-layer//install-packages ()
"Install the packages all the packages if there are not currently installed."
(interactive)

View file

@ -409,6 +409,23 @@
[object cfgl-package "pkg1" pkg1 layer1 nil nil elpa nil nil])
(configuration-layer/get-packages layers))))))
;; ---------------------------------------------------------------------------
;; configuration-layer//sort-packages
;; ---------------------------------------------------------------------------
(ert-deftest test-sort-packages--example ()
(let ((pkgs `(,(configuration-layer/make-package 'pkg4)
,(configuration-layer/make-package 'pkg3)
,(configuration-layer/make-package 'pkg6)
,(configuration-layer/make-package 'pkg2)
,(configuration-layer/make-package 'pkg1))))
(should (equal '([object cfgl-package "pkg1" pkg1 nil nil nil elpa nil nil]
[object cfgl-package "pkg2" pkg2 nil nil nil elpa nil nil]
[object cfgl-package "pkg3" pkg3 nil nil nil elpa nil nil]
[object cfgl-package "pkg4" pkg4 nil nil nil elpa nil nil]
[object cfgl-package "pkg6" pkg6 nil nil nil elpa nil nil])
(configuration-layer//sort-packages pkgs)))))
;; ---------------------------------------------------------------------------
;; configuration-layer//directory-type
;; ---------------------------------------------------------------------------