Rename & change doom/update-pinned-package-declaration

+ Now named doom/update-pinned-package-form
+ If passed the prefix arg, the command now prompts for a remote commit
  to use.
This commit is contained in:
Henrik Lissner 2020-01-25 04:14:40 -05:00
parent f600605de3
commit 57f550bc85
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -203,11 +203,11 @@ ones."
(message "Reloading packages...DONE")) (message "Reloading packages...DONE"))
;;;###autoload ;;;###autoload
(defun doom/update-pinned-package-declaration () (defun doom/update-pinned-package-form (&optional select)
"Inserts or updates a `:pin' for the `package!' statement at point. "Inserts or updates a `:pin' for the `package!' statement at point.
Grabs the latest commit id of the package using 'git'." Grabs the latest commit id of the package using 'git'."
(interactive) (interactive "P")
;; REVIEW Better error handling ;; REVIEW Better error handling
;; TODO Insert a new `package!' if no `package!' at poin ;; TODO Insert a new `package!' if no `package!' at poin
(require 'straight) (require 'straight)
@ -215,26 +215,30 @@ Grabs the latest commit id of the package using 'git'."
(while (and (atom (sexp-at-point)) (while (and (atom (sexp-at-point))
(not (bolp))) (not (bolp)))
(forward-sexp -1))) (forward-sexp -1)))
(if (not (eq (sexp-at-point) 'package!)) (save-excursion
(user-error "Not on a `package!' call") (if (not (eq (sexp-at-point) 'package!))
(backward-char) (user-error "Not on a `package!' call")
(let* ((recipe (cdr (sexp-at-point))) (backward-char)
(name (car recipe)) (let* ((recipe (cdr (sexp-at-point)))
(id (name (car recipe))
(cdr (doom-call-process (id
"git" "ls-remote" (cdr (doom-call-process
(straight-vc-git--destructure "git" "ls-remote"
(doom-plist-merge (straight-vc-git--destructure
(plist-get (cdr recipe) :recipe) (doom-plist-merge
(or (cdr (straight-recipes-retrieve name)) (plist-get (cdr recipe) :recipe)
(plist-get (cdr (assq name doom-packages)) :recipe))) (or (cdr (straight-recipes-retrieve name))
(upstream-repo upstream-host) (plist-get (cdr (assq name doom-packages)) :recipe)))
(straight-vc-git--encode-url upstream-repo upstream-host)))))) (upstream-repo upstream-host)
(unless id (straight-vc-git--encode-url upstream-repo upstream-host))))))
(user-error "No id for %S package" name)) (unless id
(let ((id (car (split-string id)))) (user-error "No id for %S package" name))
(if (re-search-forward ":pin +\"\\([^\"]+\\)\"" (cdr (bounds-of-thing-at-point 'sexp)) t) (let* ((id (if select
(replace-match id t t nil 1) (car (split-string (completing-read "Commit: " (split-string id "\n" t))))
(thing-at-point--end-of-sexp) (car (split-string id))))
(backward-char) (id (substring id 0 10)))
(insert " :pin " (prin1-to-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))))))))