dotfiles/.config/emacs/core/earnemacs-packages.el

81 lines
2.6 KiB
EmacsLisp

;;; earnemacs-packages.el --- Package management -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2021 earnest ma
;; SPDX-License-Identifier: MIT
;; Author: earnest ma <me@earne.link>
;;; Commentary:
;; Bootstrap/ load and configure straight.el for package management.
;;; Code:
;; Profiles
(setq straight-profiles
'((nil . "default.el")
(pinned . "pinned.el")))
;; Use the develop branch of straight.el (for now), must set before bootstrap.
(setq straight-repository-branch "develop")
;; Boostrap/ load straight.el
(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))
;; Configure straight
; (setq straight-vc-git-default-clone-depth 1) ; save space
(setq straight-use-package-by-default t) ; use-package integration
(straight-use-package 'use-package)
(setq use-package-always-defer t) ; always defer unless :demanded
(require 'straight-x) ; load additional experimental commands
;;; Modules system:
(defvar earnemacs-modules nil
"A quoted list of optional modules to load. The default list is provided and
used form `load.template.el'. It should be checked after every major update to
earnemacs.")
(defun earnemacs-update-packages ()
"Update all packages (core/ module packages mostly will refer to pinned
lockfile unless no commit hash is provided) and write packages the user has
installed to the `default.el' lockfile."
(interactive)
(message "[earnemacs] Updating packages and lockfiles...")
(straight-x-pull-all)
(straight-x-freeze-versions)
(message "[earnemacs] Update complete, consider reloading earnemacs."))
;;; Pin packages to a certain commit (for core/ module packages only):
;; Any core/module package not given a commit hash here will update
;; as normal, and no hash is written to `pinned.el'.
(defmacro earnemacs-package-pin (package commit)
"Add the PACKAGE and COMMIT hash to the pinned lockfile. Aliased to `epin'.
Ex: (epin \"packagename\" \"70b64b6d91d62ecef8fa202c65c19b8aba7122e2\")
Only for core/ optional modules. (for now?)"
`(let ((straight-current-profile 'pinned))
(add-to-list 'straight-x-pinned-packages
'(,package . ,commit))))
(defalias 'epin 'earnemacs-package-pin)
(provide 'earnemacs-packages)
;;; earnemacs-packages.el ends here