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"))
;;;###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,6 +215,7 @@ Grabs the latest commit id of the package using 'git'."
(while (and (atom (sexp-at-point))
(not (bolp)))
(forward-sexp -1)))
(save-excursion
(if (not (eq (sexp-at-point) 'package!))
(user-error "Not on a `package!' call")
(backward-char)
@ -232,9 +233,12 @@ Grabs the latest commit id of the package using 'git'."
(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))))
(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)))))))
(insert " :pin " (prin1-to-string id))))))))