From 57f550bc851c0bd2462ad798fe52e15e95eb02d0 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 25 Jan 2020 04:14:40 -0500 Subject: [PATCH] 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. --- core/autoload/packages.el | 54 +++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/core/autoload/packages.el b/core/autoload/packages.el index 35f275a61..e0c0240c3 100644 --- a/core/autoload/packages.el +++ b/core/autoload/packages.el @@ -203,11 +203,11 @@ ones." (message "Reloading packages...DONE")) ;;;###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. Grabs the latest commit id of the package using 'git'." - (interactive) + (interactive "P") ;; REVIEW Better error handling ;; TODO Insert a new `package!' if no `package!' at poin (require 'straight) @@ -215,26 +215,30 @@ Grabs the latest commit id of the package using 'git'." (while (and (atom (sexp-at-point)) (not (bolp))) (forward-sexp -1))) - (if (not (eq (sexp-at-point) 'package!)) - (user-error "Not on a `package!' call") - (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) - (or (cdr (straight-recipes-retrieve name)) - (plist-get (cdr (assq name doom-packages)) :recipe))) - (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))))))) + (save-excursion + (if (not (eq (sexp-at-point) 'package!)) + (user-error "Not on a `package!' call") + (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) + (or (cdr (straight-recipes-retrieve name)) + (plist-get (cdr (assq name doom-packages)) :recipe))) + (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 (if select + (car (split-string (completing-read "Commit: " (split-string id "\n" t)))) + (car (split-string id)))) + (id (substring id 0 10))) + (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))))))))