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:
parent
f600605de3
commit
57f550bc85
1 changed files with 29 additions and 25 deletions
|
@ -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))))))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue