.emacs.d/init.d/basics/package-management.el

74 lines
2.5 KiB
EmacsLisp

;;; package-management.el --- Initialize package management. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-03-16T00:13:48+0100>
;;; Commentary:
;; * Set up package sources and their priorities.
;; * Set up use-package.
;; * Compile elisp files.
;; * Update keyring.
;; * Update packages.
;; * Set up quelpa.
;;; Code:
(customize-set-variable
'straight-use-package-by-default t
"Makes use-package invoke straight.el to install the package.")
(customize-set-variable 'straight-cache-autoloads t
"Cache the autoloads of all packages in a single file.")
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(add-hook 'after-init-hook #'straight-prune-build)
;; Workaround for 26.2 <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341>.
(when (< emacs-major-version 27)
(defvar gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))
;; Isolate package configurations.
(straight-use-package 'use-package)
(defun my/straight-pull-all-maybe ()
"Run `straight-pull-all' if 7 days have passed since the build cache was modified."
(let ((days 7))
(if (> (- (time-to-seconds)
(time-to-seconds
(file-attribute-modification-time
(file-attributes (expand-file-name "straight/build-cache.el"
user-emacs-directory)))))
(* 60 60 24 days))
(straight-pull-all))))
;; ;; Autocompile files on load.
;; (use-package auto-compile
;; :custom (load-prefer-newer t) ; Use uncompiled file if it is newer.
;; :config (auto-compile-on-load-mode))
;; Tool for updating the GNU ELPA keyring.
(use-package gnu-elpa-keyring-update
:config
(defvar my/keyring-last-access
(time-to-seconds
(file-attribute-access-time
(file-attributes gnu-elpa-keyring-update--keyring)))
"Last access time for the GNU ELPA keyring.")
;; Only update keyring if atime (mtime with relatime) is > 1 week ago.
(if (> (- (time-to-seconds) my/keyring-last-access) (* 60 60 24 7))
(gnu-elpa-keyring-update)))
(provide 'basics/package-management)
;;; package-management.el ends here