core: refactor the progress bar
Spacemacs is slow to startup so better give it a not buggy progress bar :-) * Move progress bar code to core-progress-bar.el file * Remove the counters at the end of the progress bar * Fix update of the progress bar value * Fix progress bar size when staring Emacs maximized
This commit is contained in:
parent
7944ed2634
commit
a0a3ff0c20
|
@ -20,6 +20,7 @@
|
|||
(require 'ht)
|
||||
(require 'core-dotspacemacs)
|
||||
(require 'core-funcs)
|
||||
(require 'core-progress-bar)
|
||||
(require 'core-spacemacs-buffer)
|
||||
|
||||
(defvar configuration-layer--refresh-package-timeout dotspacemacs-elpa-timeout
|
||||
|
@ -559,8 +560,8 @@ refreshed during the current session."
|
|||
;; check if layer list has changed since last dump
|
||||
(when (file-exists-p
|
||||
configuration-layer--last-dotspacemacs-configuration-layers-file)
|
||||
(load-file
|
||||
configuration-layer--last-dotspacemacs-configuration-layers-file))
|
||||
(load configuration-layer--last-dotspacemacs-configuration-layers-file
|
||||
nil (not init-file-debug)))
|
||||
(let ((layers dotspacemacs-configuration-layers))
|
||||
(dotspacemacs|call-func dotspacemacs/layers "Calling dotfile layers...")
|
||||
;; `dotspacemacs--configuration-layers-saved' is used to detect if the layer
|
||||
|
@ -1884,9 +1885,7 @@ RNAME is the name symbol of another existing layer."
|
|||
|
||||
(defun configuration-layer//configure-packages (packages)
|
||||
"Configure all passed PACKAGES honoring the steps order."
|
||||
(setq spacemacs-loading-dots-chunk-threshold
|
||||
(/ (length configuration-layer--used-packages)
|
||||
spacemacs-loading-dots-chunk-count))
|
||||
(spacemacs/init-progress-bar (length packages))
|
||||
(spacemacs-buffer/message "+ Configuring bootstrap packages...")
|
||||
(configuration-layer//configure-packages-2
|
||||
(configuration-layer/filter-objects
|
||||
|
@ -1910,7 +1909,6 @@ RNAME is the name symbol of another existing layer."
|
|||
"Configure all passed PACKAGES."
|
||||
(let (packages-to-configure)
|
||||
(dolist (pkg-name packages)
|
||||
(spacemacs-buffer/loading-animation)
|
||||
(let ((pkg (configuration-layer/get-package pkg-name)))
|
||||
(cond
|
||||
((oref pkg :lazy-install)
|
||||
|
@ -2022,6 +2020,7 @@ LAYER must not be the owner of PKG."
|
|||
|
||||
(defun configuration-layer//configure-package (pkg)
|
||||
"Configure PKG object, i.e. call its post-init function."
|
||||
(spacemacs/update-progress-bar)
|
||||
(let* ((pkg-name (oref pkg :name))
|
||||
(owner (car (oref pkg :owners))))
|
||||
;; init
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
;;; core-progress-bar.el --- Spacemacs Core File
|
||||
;;
|
||||
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
||||
;;
|
||||
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
||||
;; URL: https://github.com/syl20bnr/spacemacs
|
||||
;;
|
||||
;; This file is not part of GNU Emacs.
|
||||
;;
|
||||
;;; License: GPLv3
|
||||
(require 'core-spacemacs-buffer)
|
||||
|
||||
(defvar spacemacs-loading-char ?█)
|
||||
(defvar spacemacs-loading-char-light ?░)
|
||||
(defvar spacemacs-loading-string "")
|
||||
(defvar spacemacs-loading-counter 0)
|
||||
(defvar spacemacs-loading-value 0)
|
||||
(defvar spacemacs-loading-dots-chunk-count 5)
|
||||
(defvar spacemacs-loading-dots-count 0)
|
||||
(defvar spacemacs-loading-dots-chunk-size 0)
|
||||
(defvar spacemacs-loading-dots-chunk-threshold 0)
|
||||
|
||||
(defun spacemacs/init-progress-bar (max)
|
||||
"Initialize the progress bar."
|
||||
(setq spacemacs-loading-dots-count (window-total-size nil 'width))
|
||||
(setq spacemacs-loading-dots-chunk-size (/ spacemacs-loading-dots-count
|
||||
spacemacs-loading-dots-chunk-count))
|
||||
(setq spacemacs-loading-dots-chunk-threshold
|
||||
(- (/ max spacemacs-loading-dots-chunk-count) 5))
|
||||
(setq spacemacs-loading-counter 0)
|
||||
(setq spacemacs-loading-value 0)
|
||||
(spacemacs-buffer/set-mode-line (make-string spacemacs-loading-dots-count
|
||||
spacemacs-loading-char-light))
|
||||
(spacemacs//redisplay))
|
||||
|
||||
(defun spacemacs/update-progress-bar ()
|
||||
"Update progress bar by incrementing its value by 1.
|
||||
Display the progress bar by chunks of size `spacemacs--loading-dots-chunk-threshold'"
|
||||
(when (and (not noninteractive)
|
||||
dotspacemacs-loading-progress-bar)
|
||||
(setq spacemacs-loading-counter (1+ spacemacs-loading-counter))
|
||||
(setq spacemacs-loading-value (1+ spacemacs-loading-value))
|
||||
(when (>= spacemacs-loading-counter
|
||||
spacemacs-loading-dots-chunk-threshold)
|
||||
(let* ((progress
|
||||
(max 0 (* spacemacs-loading-dots-chunk-size
|
||||
(floor (/ spacemacs-loading-value
|
||||
spacemacs-loading-dots-chunk-threshold)))))
|
||||
(remain (max 0 (- spacemacs-loading-dots-count progress))))
|
||||
(setq spacemacs-loading-counter 0)
|
||||
(setq spacemacs-loading-string
|
||||
(concat (make-string progress spacemacs-loading-char)
|
||||
(make-string remain spacemacs-loading-char-light)))
|
||||
(spacemacs-buffer/set-mode-line spacemacs-loading-string))
|
||||
(spacemacs//redisplay))))
|
||||
|
||||
(provide 'core-progress-bar)
|
|
@ -571,28 +571,6 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer."
|
|||
(when messagebuf
|
||||
(message "(Spacemacs) %s" msg)))))
|
||||
|
||||
(defun spacemacs-buffer/loading-animation ()
|
||||
"Display the progress bar by chunks of size `spacemacs--loading-dots-chunk-threshold'."
|
||||
(when (and (not noninteractive)
|
||||
dotspacemacs-loading-progress-bar)
|
||||
(setq spacemacs-loading-counter (1+ spacemacs-loading-counter))
|
||||
(setq spacemacs-loading-value (1+ spacemacs-loading-value))
|
||||
(when (>= spacemacs-loading-counter spacemacs-loading-dots-chunk-threshold)
|
||||
(let ((suffix (format "> %s/%s" spacemacs-loading-value
|
||||
(length configuration-layer--used-packages))))
|
||||
(setq spacemacs-loading-counter 0)
|
||||
(setq spacemacs-loading-string
|
||||
(make-string
|
||||
(max 0
|
||||
(- (* spacemacs-loading-dots-chunk-size
|
||||
(floor (/ spacemacs-loading-value
|
||||
spacemacs-loading-dots-chunk-threshold)))
|
||||
(length suffix)))
|
||||
spacemacs-loading-char))
|
||||
(spacemacs-buffer/set-mode-line
|
||||
(concat spacemacs-loading-string suffix)))
|
||||
(spacemacs//redisplay))))
|
||||
|
||||
(defmacro spacemacs-buffer||add-shortcut
|
||||
(shortcut-char search-label &optional no-next-line)
|
||||
"Add a single-key keybinding for quick navigation in the home buffer.
|
||||
|
|
|
@ -36,19 +36,6 @@
|
|||
:group 'starter-kit
|
||||
:prefix 'spacemacs-)
|
||||
|
||||
;; loading progress bar variables
|
||||
(defvar spacemacs-loading-char ?█)
|
||||
(defvar spacemacs-loading-string "")
|
||||
(defvar spacemacs-loading-counter 0)
|
||||
(defvar spacemacs-loading-value 0)
|
||||
;; (defvar spacemacs-loading-text "Loading")
|
||||
;; (defvar spacemacs-loading-done-text "Ready!")
|
||||
(defvar spacemacs-loading-dots-chunk-count 3)
|
||||
(defvar spacemacs-loading-dots-count (window-total-size nil 'width))
|
||||
(defvar spacemacs-loading-dots-chunk-size
|
||||
(/ spacemacs-loading-dots-count spacemacs-loading-dots-chunk-count))
|
||||
(defvar spacemacs-loading-dots-chunk-threshold 0)
|
||||
|
||||
(defvar spacemacs-post-user-config-hook nil
|
||||
"Hook run after dotspacemacs/user-config")
|
||||
(defvar spacemacs-post-user-config-hook-run nil
|
||||
|
|
|
@ -2221,7 +2221,7 @@
|
|||
(defun layer1/init-pkg () (push 'init witness))
|
||||
(defun layer2/pre-init-pkg () (push 'pre-init witness))
|
||||
(mocker-let
|
||||
((spacemacs-buffer/loading-animation nil ((:output nil))))
|
||||
((spacemacs/update-progress-bar nil ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name)))
|
||||
(should (equal '(init pre-init) witness)))))
|
||||
|
||||
|
@ -2239,7 +2239,7 @@
|
|||
(defun layer1/init-pkg () (push 'init witness))
|
||||
(defun layer2/post-init-pkg () (push 'post-init witness))
|
||||
(mocker-let
|
||||
((spacemacs-buffer/loading-animation nil ((:output nil))))
|
||||
((spacemacs/update-progress-bar nil ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name)))
|
||||
(should (equal '(post-init init) witness)))))
|
||||
|
||||
|
@ -2251,7 +2251,7 @@
|
|||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((configuration-layer//configure-package (p) ((:occur 1)))
|
||||
(spacemacs-buffer/loading-animation nil ((:output nil))))
|
||||
(spacemacs/update-progress-bar nil ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name))))))
|
||||
|
||||
(ert-deftest test-configure-packages-2--site-package-is-configured()
|
||||
|
@ -2262,7 +2262,7 @@
|
|||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((configuration-layer//configure-package (p) ((:occur 1)))
|
||||
(spacemacs-buffer/loading-animation nil ((:output nil))))
|
||||
(spacemacs/update-progress-bar nil ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name))))))
|
||||
|
||||
(ert-deftest test-configure-packages-2--toggle-t-is-configured ()
|
||||
|
@ -2273,7 +2273,7 @@
|
|||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((configuration-layer//configure-package (p) ((:occur 1)))
|
||||
(spacemacs-buffer/loading-animation nil ((:output nil))))
|
||||
(spacemacs/update-progress-bar nil ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name))))))
|
||||
|
||||
(ert-deftest test-configure-packages-2--toggle-nil-is-not-configured ()
|
||||
|
@ -2284,7 +2284,7 @@
|
|||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((configuration-layer//configure-package (p) nil)
|
||||
(spacemacs-buffer/loading-animation nil ((:output nil)))
|
||||
(spacemacs/update-progress-bar nil ((:output nil)))
|
||||
(spacemacs-buffer/message (m) ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name))))))
|
||||
|
||||
|
@ -2296,7 +2296,7 @@
|
|||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((configuration-layer//configure-package (p) ((:occur 1)))
|
||||
(spacemacs-buffer/loading-animation nil ((:output nil))))
|
||||
(spacemacs/update-progress-bar nil ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name))))))
|
||||
|
||||
(ert-deftest test-configure-packages-2--protected-excluded-package-is-configured()
|
||||
|
@ -2307,7 +2307,7 @@
|
|||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((configuration-layer//configure-package (p) ((:occur 1)))
|
||||
(spacemacs-buffer/loading-animation nil ((:output nil))))
|
||||
(spacemacs/update-progress-bar nil ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name))))))
|
||||
|
||||
(ert-deftest test-configure-packages-2--excluded-package-is-not-configured()
|
||||
|
@ -2318,7 +2318,7 @@
|
|||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((configuration-layer//configure-package (p) nil)
|
||||
(spacemacs-buffer/loading-animation nil ((:output nil)))
|
||||
(spacemacs/update-progress-bar nil ((:output nil)))
|
||||
(spacemacs-buffer/message (m) ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name))))))
|
||||
|
||||
|
@ -2330,7 +2330,7 @@
|
|||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((configuration-layer//configure-package (p) nil)
|
||||
(spacemacs-buffer/loading-animation nil ((:output nil)))
|
||||
(spacemacs/update-progress-bar nil ((:output nil)))
|
||||
(spacemacs-buffer/message (m) ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name))))))
|
||||
|
||||
|
@ -2343,7 +2343,7 @@
|
|||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((configuration-layer//configure-package (p) nil)
|
||||
(spacemacs-buffer/loading-animation nil ((:output nil)))
|
||||
(spacemacs/update-progress-bar nil ((:output nil)))
|
||||
(spacemacs-buffer/message (m) ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name))))))
|
||||
|
||||
|
@ -2355,7 +2355,7 @@
|
|||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((configuration-layer//configure-package (p) nil)
|
||||
(spacemacs-buffer/loading-animation nil ((:output nil)))
|
||||
(spacemacs/update-progress-bar nil ((:output nil)))
|
||||
(spacemacs-buffer/message (m) ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name))))))
|
||||
|
||||
|
@ -2371,7 +2371,7 @@
|
|||
(helper--add-layers `(,(cfgl-layer "layer1" :name 'layer1 :dir "/path/")) t)
|
||||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((spacemacs-buffer/loading-animation nil ((:output nil)))
|
||||
((spacemacs/update-progress-bar nil ((:output nil)))
|
||||
(configuration-layer//configure-package (p) ((:occur 1))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name)))
|
||||
(push "/path/local/pkg/" expected-load-path)
|
||||
|
@ -2386,7 +2386,7 @@
|
|||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((spacemacs-buffer/loading-animation nil ((:output nil))))
|
||||
((spacemacs/update-progress-bar nil ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name)))
|
||||
(push (file-name-as-directory
|
||||
(concat configuration-layer-private-directory "local/pkg"))
|
||||
|
@ -2402,7 +2402,7 @@
|
|||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((spacemacs-buffer/loading-animation nil ((:output nil)))
|
||||
((spacemacs/update-progress-bar nil ((:output nil)))
|
||||
(spacemacs-buffer/message (m) ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name)))
|
||||
(should (equal load-path old-load-path)))))
|
||||
|
@ -2419,7 +2419,7 @@
|
|||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((spacemacs-buffer/loading-animation nil ((:output nil))))
|
||||
((spacemacs/update-progress-bar nil ((:output nil))))
|
||||
(configuration-layer//configure-packages-2 `(,(oref pkg :name)))
|
||||
(push spacemacs-docs-directory expected-load-path)
|
||||
(should (equal expected-load-path load-path)))))
|
||||
|
@ -2435,7 +2435,7 @@
|
|||
(mocker-mock-default-record-cls 'mocker-stub-record))
|
||||
(helper--add-packages (list pkg) t)
|
||||
(mocker-let
|
||||
((spacemacs-buffer/loading-animation nil ((:output nil)))
|
||||
((spacemacs/update-progress-bar nil ((:output nil)))
|
||||
(configuration-layer//warning
|
||||
(msg &rest args)
|
||||
((:record-cls 'mocker-stub-record :output nil :occur 1))))
|
||||
|
|
Loading…
Reference in New Issue