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

105 lines
3.4 KiB
EmacsLisp
Raw Normal View History

2019-10-14 17:38:14 +02:00
;;; package-management.el --- Initialize package management. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-02-27T05:36:25+0100>
2019-10-14 17:38:14 +02:00
;;; Commentary:
;; * Set up package sources and their priorities.
;; * Set up use-package.
2019-10-14 17:38:14 +02:00
;; * Compile elisp files.
;; * Update keyring.
2019-10-14 17:38:14 +02:00
;; * Update packages.
;; * Set up quelpa.
2019-10-14 17:38:14 +02:00
;;; 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)
2019-10-14 17:38:14 +02:00
("gnu" . 20)
("melpa" . 10)))
2019-10-14 17:38:14 +02:00
;; 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"))
2019-10-14 17:38:14 +02:00
(when (< emacs-major-version 27)
(package-initialize))
2019-10-14 17:38:14 +02:00
;; Add path for custom packages.
(add-to-list 'load-path (concat user-emacs-directory "custom-packages/"))
2019-10-14 17:38:14 +02:00
;; 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.
2019-10-14 17:38:14 +02:00
(use-package auto-compile
:custom (load-prefer-newer t) ; Use uncompiled file if it is newer.
:config (auto-compile-on-load-mode))
2019-10-14 17:38:14 +02:00
;; 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))
)
2019-10-14 17:38:14 +02:00
;; 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)
)
2019-10-14 17:38:14 +02:00
2020-02-24 22:01:43 +01:00
;; Install Emacs packages directly from source.
(use-package quelpa
:demand t
:custom ((quelpa-self-upgrade-p nil)
2020-02-24 22:01:43 +01:00
(quelpa-update-melpa-p nil)
(quelpa-checkout-melpa-p nil))
:config
(defun my/quelpa-upgrade-all-maybe (&optional force)
"Run `quelpa-upgrade-all' if at least 7 days passed since the last run.
The prefix FORCE will be passed to `quelpa-upgrade-all'."
(interactive "P")
(let ((timestamp (expand-file-name "last_upgrade" quelpa-dir))
(days 7))
(when (or (not (file-exists-p timestamp))
(> (- (time-to-seconds) ; Current time - file modification time.
(time-to-seconds (nth 5 (file-attributes timestamp))))
(* 60 60 24 days)))
(let ((current-prefix-arg force))
(quelpa-upgrade-all))
(write-region "" nil timestamp))))
:hook (after-init . my/quelpa-upgrade-all-maybe)
2020-02-24 22:01:43 +01:00
)
2020-02-27 03:13:15 +01:00
;; Use :quelpa in use-package configurations.
(use-package quelpa-use-package
; Override `use-package-always-ensure' for quelpa-packages.
:config (quelpa-use-package-activate-advice)
)
2019-10-14 17:38:14 +02:00
(provide 'basics/package-management)
;;; package-management.el ends here