Add doom/update-pinned-package-declaration command
This may be renamed later, or rewritten to jump to the user's `packages.el` and entering it there. Or something. For now it's useful for its niche.
This commit is contained in:
parent
7326d2b4dc
commit
b7e81bc042
1 changed files with 32 additions and 0 deletions
|
@ -201,3 +201,35 @@ ones."
|
||||||
(message "Reloading packages")
|
(message "Reloading packages")
|
||||||
(doom-initialize-packages t)
|
(doom-initialize-packages t)
|
||||||
(message "Reloading packages...DONE"))
|
(message "Reloading packages...DONE"))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom/update-pinned-package-declaration ()
|
||||||
|
"Inserts or updates a `:pin' for the `package!' statement at point.
|
||||||
|
|
||||||
|
Grabs the latest commit id of the package using 'git'."
|
||||||
|
(interactive)
|
||||||
|
;; REVIEW Better error handling
|
||||||
|
;; TODO Insert a new `package!' if no `package!' at poin
|
||||||
|
(ignore-errors
|
||||||
|
(while (atom (sexp-at-point))
|
||||||
|
(forward-sexp -1)))
|
||||||
|
(when (eq (sexp-at-point) 'package!)
|
||||||
|
(backward-char)
|
||||||
|
(let* ((recipe (cdr (sexp-at-point)))
|
||||||
|
(name (car recipe))
|
||||||
|
(id
|
||||||
|
(cdr (doom-call-process
|
||||||
|
"git" "ls-remote"
|
||||||
|
(straight-vc-git--destructure
|
||||||
|
(doom-plist-merge (plist-get (cdr recipe) :recipe)
|
||||||
|
(cdr (straight-recipes-retrieve name)))
|
||||||
|
(upstream-repo upstream-host)
|
||||||
|
(straight-vc-git--encode-url upstream-repo upstream-host))))))
|
||||||
|
(unless id
|
||||||
|
(user-error "No id for %S package" name))
|
||||||
|
(let ((id (car (split-string id))))
|
||||||
|
(if (re-search-forward ":pin +\"\\([^\"]+\\)\"" (cdr (bounds-of-thing-at-point 'sexp)) t)
|
||||||
|
(replace-match id t t nil 1)
|
||||||
|
(thing-at-point--end-of-sexp)
|
||||||
|
(backward-char)
|
||||||
|
(insert " :pin " (prin1-to-string id)))))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue