~northyear/dotemacs

232da91620c703f6d10d9ff74d73c78aeb8f5be7 — Milan Glacier 1 year, 4 months ago 51c0fbd
refactor(utils): add options for controlling time to incrementally load packages.
1 files changed, 16 insertions(+), 6 deletions(-)

M lisp/autoloads/my-utils-autoloads.el
M lisp/autoloads/my-utils-autoloads.el => lisp/autoloads/my-utils-autoloads.el +16 -6
@@ 98,21 98,31 @@ for debugging purposes when you want to examine a hook value."

(defvar my$load-incrementally-packages ()
    "packages to be loaded incrementally after startup")
(defvar my$load-incrementally-packages-first-time 2
    "time to load packages incrementally for the first time")
(defvar my$load-incrementally-packages-idle-time 0.75
    "idle time to load packages incrementally")

(defun my:load-packages-incrementally (pkgs)
    "load package from PKGS incrementally"
    (let ((gc-cons-threshold most-positive-fixnum))
    (let ((gc-cons-threshold most-positive-fixnum)
          (pkg (car pkgs))
          (rest-pkgs (cdr pkgs)))
        (when pkgs
            (if (featurep (car pkgs))
                    (my:load-packages-incrementally (cdr pkgs))
            (if (featurep pkg)
                    (my:load-packages-incrementally rest-pkgs)
                (progn
                    (require (car pkgs))
                    (run-with-idle-timer 0.75 nil #'my:load-packages-incrementally (cdr pkgs)))))))
                    (require pkg)
                    (run-with-idle-timer
                     my$load-incrementally-packages-idle-time nil
                     #'my:load-packages-incrementally rest-pkgs))))))

;;;###autoload
(defun my:load-packages-incrementally-setup ()
    "Set up a idle timer to start idly load packages."
    (run-with-idle-timer 2 nil #'my:load-packages-incrementally my$load-incrementally-packages))
    (run-with-idle-timer
     my$load-incrementally-packages-first-time nil
     #'my:load-packages-incrementally my$load-incrementally-packages))

(provide 'my-utils-autoloads)
;;; my-utils-autoloads ends here