;;; package-management.el --- Initialize package management. -*- lexical-binding: t; -*- ;; Time-stamp: <2020-03-11T16:10:53+0100> ;;; Commentary: ;; * Set up package sources and their priorities. ;; * Set up use-package. ;; * Compile elisp files. ;; * Update keyring. ;; * Update packages. ;; * Set up quelpa. ;;; Code: (require 'package) (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (setq package-archive-priorities '(("melpa-stable" . 30) ("gnu" . 20) ("melpa" . 10))) ;; Workaround for 26.2 . (when (< emacs-major-version 27) (defvar gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")) (when (< emacs-major-version 27) (package-initialize)) ;; Add path for custom packages. (add-to-list 'load-path (concat user-emacs-directory "custom-packages/")) ;; Install use-package if necessary. (unless (package-installed-p 'use-package) (package-refresh-contents) (package-install 'use-package)) (eval-when-compile (require 'use-package)) ;; Always install packages if they are not present. (use-package use-package :custom (use-package-always-ensure t)) ;; 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))) ;; Update packages if at least 7 days have passed. (use-package auto-package-update :after (quelpa) :demand t :defines (quelpa-cache) :custom ((auto-package-update-delete-old-versions t) (auto-package-update-interval 7) (auto-package-update-hide-results nil)) :config (progn (auto-package-update-maybe) (defvar my/tmp--package-activated-list nil) (defun my/apu-delete-quelpa-packages () "Delete quelpa packages from `package-activated-list'." (setq my/tmp--package-activated-list package-activated-list) (dolist (package quelpa-cache) (let ((package-name (car package))) (setq package-activated-list (delq package-name package-activated-list))))) (defun my/apu-restore-quelpa-packages () "Restore quelpa packages to `package-activated-list'." (if my/tmp--package-activated-list (setq package-activated-list my/tmp--package-activated-list) (message "Error: Could not restore `package-activated-list'.")) (setq my/tmp--package-activated-list nil))) :hook ((auto-package-update-before . my/apu-delete-quelpa-packages) (auto-package-update-after . my/apu-restore-quelpa-packages))) ;; Install Emacs packages directly from source. (use-package quelpa :demand t :custom ((quelpa-self-upgrade-p nil) (quelpa-update-melpa-p nil) (quelpa-checkout-melpa-p nil) (quelpa-upgrade-interval 7)) :hook (after-init . quelpa-upgrade-all-maybe)) ;; Use :quelpa in use-package configurations. (use-package quelpa-use-package :after (use-package quelpa) ; Override `use-package-always-ensure' for quelpa-packages. :config (quelpa-use-package-activate-advice)) (provide 'basics/package-management) ;;; package-management.el ends here