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

82 lines
2.3 KiB
EmacsLisp

;;; package-management.el --- Initialize package management. -*- lexical-binding: t; -*-
;; Time-stamp: <2019-12-26T06:00:54+00:00>
;;; Commentary:
;; * Sets up package sources and their priorities.
;; * Sets up use-package.
;; * Compile elisp files.
;; * Update packages.
;;; 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 <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341>.
(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 "~/.emacs.d/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-ensure
:ensure nil
:custom
(use-package-always-ensure t)
)
;; Autocompile files as needed.
(use-package auto-compile
:custom
;; Use uncompiled file if it is newer than the compiled one.
(load-prefer-newer t)
: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
(nth 4 (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
:custom
(auto-package-update-delete-old-versions t)
(auto-package-update-interval 7)
(auto-package-update-hide-results nil)
:config
(auto-package-update-maybe))
(provide 'basics/package-management)
;;; package-management.el ends here