Skip to content

Commit

Permalink
feat(use-package): add the :pin-ref keyword to use straight-x
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Apr 14, 2023
1 parent 797e115 commit cc4f11b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/me-bootstrap.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
(unless (require 'use-package nil t)
(straight-use-package 'use-package))

;; Add the `:pin-ref' extension to `use-package'
(require 'me-use-package-pin-ref)

(setq
;; Set `use-package' to verbose when MinEmacs is started in verbose mode
use-package-verbose minemacs-verbose
Expand Down
35 changes: 35 additions & 0 deletions core/me-use-package-pin-ref.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;; me-use-package-pin-ref.el --- Extend use-package to allow straight-x package pinning -*- lexical-binding: t; -*-

;; Copyright (C) 2022-2023 Abdelhak Bougouffa

;; Author: Abdelhak Bougouffa (concat "abougouffa" "@" "fedora" "project" "." "org")

;; Add support for pinning versions of individual packages. See:
;; github.com/radian-software/straight.el#how-do-i-pin-package-versions-or-use-only-tagged-releases
(with-eval-after-load 'straight
;; Add a profile (and lockfile) for stable package revisions.
(add-to-list 'straight-profiles '(pinned . "pinned.el"))
(require 'straight-x))

;; Allow pinning versions from `use-package' using the `:pin-ref' keyword
(with-eval-after-load 'use-package
(add-to-list 'use-package-keywords :pin-ref)

(defun use-package-normalize/:pin-ref (name-symbol keyword args)
(use-package-only-one (symbol-name keyword) args
(lambda (label arg)
(cond
((stringp arg) arg)
((symbolp arg) (symbol-name arg))
(t (use-package-error ":pin-ref wants a commit hash or a ref."))))))

(defun use-package-handler/:pin-ref (name-symbol keyword ref rest state)
(let ((body (use-package-process-keywords name-symbol rest state)))
(if (null ref)
body
(use-package-concat
`((let ((straight-current-profile 'pinned))
(push '(,(symbol-name name-symbol) . ,ref) straight-x-pinned-packages)
,(macroexp-progn body))))))))

(provide 'me-use-package-pin-ref)

0 comments on commit cc4f11b

Please sign in to comment.