summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-28 20:05:34 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-28 20:06:06 -0700
commitc8df5f657906676517dae3f320898ee9484e1a15 (patch)
tree7bbca1b129ddc4c9f8620f6c66301b362b1c5845
parent0c7d041b8b0e3b6a584d23a4be42401dfc5c5dc4 (diff)
emacs: Don't load all downloaded packages
-rw-r--r--.config/emacs/init.el50
1 files changed, 47 insertions, 3 deletions
diff --git a/.config/emacs/init.el b/.config/emacs/init.el
index 3932d6a..16555ce 100644
--- a/.config/emacs/init.el
+++ b/.config/emacs/init.el
@@ -82,16 +82,60 @@
'(("gnu" . 99)
("melpa-stable" . 5)
("melpa" . 0)))
- (package-initialize))
+ ;; Finally, initialize the package manager. Pass the `t` argument
+ ;; to cause it to not go ahead and load all downloaded packages; and
+ ;; wait for (use-package) to request them.
+ (package-initialize t))
;; use-package.el
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
+(package-activate 'use-package)
(eval-when-compile
- (add-to-list 'load-path (concat user-emacs-directory "use-package"))
(require 'use-package)
- (setq use-package-always-ensure t))
+ ;; Have (use-package) calls eagerly install things.
+ (setq use-package-always-ensure t)
+ ;; Patch (use-package-ensure-elpa) to call (package-activate
+ ;; package) if the package is already installed, which is needed to
+ ;; make it work with the the `t` argument in
+ ;; `(package-initialize t)`.
+ ;;
+ ;; Apparently back in 2015 hacking (use-package-ensure-lazyelpa)
+ ;; wasn't necessary (https://emacs.stackexchange.com/a/16852), and
+ ;; I'm not sure what changed.
+ (defun use-package-ensure-lazyelpa (name args _state &optional _no-refresh)
+ (dolist (ensure args)
+ (let ((package
+ (or (and (eq ensure t) (use-package-as-symbol name))
+ ensure)))
+ (when package
+ (require 'package)
+ (when (consp package)
+ (use-package-pin-package (car package) (cdr package))
+ (setq package (car package)))
+ (if (package-installed-p package)
+ (package-activate package)
+ (condition-case-unless-debug err
+ (progn
+ (when (assoc package (bound-and-true-p
+ package-pinned-packages))
+ (package-read-all-archive-contents))
+ (if (assoc package package-archive-contents)
+ (package-install package)
+ (package-refresh-contents)
+ (when (assoc package (bound-and-true-p
+ package-pinned-packages))
+ (package-read-all-archive-contents))
+ (package-install package))
+ t)
+ (error
+ (display-warning 'use-package
+ (format "Failed to install %s: %s"
+ name (error-message-string err))
+ :error))))))))
+ (setq use-package-ensure-function 'use-package-ensure-lazyelpa))
+;; Load bind-key so that (use-package :bind) works.
(require 'bind-key)
;; Themes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;