reddit / emacs

Exploring package-vc-install as an alternative to Quelpa

slinchisl · 2022-12-01 07:58
0lMon · 2022-12-01 09:06
Hej Hej, Thanks for this! I am myself very interested in package-vc. I thought about a similar solution, but as an special use-package extension. I didn't dig to deep into it right now, but I think this would eliminate to wrap package-vc-install. Maybe not really eliminate but put it behind the extension/keyword in use-package. Did you thought or maybe even try that already? Cheers!
Wonnk13 · 2022-12-01 12:45
Interesting. I haven't really kept up to date with package management in the last few years and it's really become quite a source of pain for me. I would love if i could lock packages to a specific version. When I `package-refresh-contents` and upgrade packages it's always a roll of the dice to see what breaks. And then there's the issue of multiple package repositories and package versions. I'm slowly investigating straight, but it seems fairly complex converting my existing use-package config.
slinchisl · 2022-12-01 13:07
Thanks for your kind words! > I thought about a similar solution, but as an special use-package extension. > > I didn't dig to deep into it right now, but I think this would eliminate to wrap package-vc-install. Maybe not really eliminate but put it behind the extension/keyword in use-package. > > Did you thought or maybe even try that already? I thought about this briefly, but it seemed a little overcomplicated for my specific use-case (not to mention it'd be another package :). The implementation itself isn't all that complicated, though, one basically just has to crib what the people who wrote `quelpa-use-package` have done already. Being extremely lazy, I will still use the wrapper: (cl-defun slot/vc-install (&key (fetcher "github") repo name rev backend) (let* ((url (format "https://www.%s.com/%s" fetcher repo)) (iname (when name (intern name))) (package-name (or iname (intern (file-name-base repo))))) (unless (package-installed-p package-name) (package-vc-install url iname rev backend)))) However, this is not necessary and could easily be worked into the below code. The rest is just what quelpa does, minimally changed to our case: (require 'cl-lib) (require 'use-package-core) (defvar package-vc-use-package-keyword :vc) (defun package-vc-use-package-set-keyword () (unless (member package-vc-use-package-keyword use-package-keywords) (setq use-package-keywords (let* ((pos (cl-position :unless use-package-keywords)) (head (cl-subseq use-package-keywords 0 (+ 1 pos))) (tail (nthcdr (+ 1 pos) use-package-keywords))) (append head (list package-vc-use-package-keyword) tail))))) (defun use-package-normalize/:vc (name-symbol keyword args) (let ((arg (car args))) (pcase arg ((or `nil `t) (list name-symbol)) ((pred symbolp) args) ((pred listp) (cond ((listp (car arg)) arg) ((string-match "^:" (symbol-name (car arg))) (cons name-symbol arg)) ((symbolp (car arg)) args))) (_ nil)))) (defun use-package-handler/:vc (name-symbol keyword args rest state) (let ((body (use-package-process-keywords name-symbol rest state))) ;; This happens at macro expansion time, not when the expanded code is ;; compiled or evaluated. (if args (use-package-concat `((unless (package-installed-p ',(pcase (car args) ((pred symbolp) (car args)) ((pred listp) (car (car args))))) (apply #'slot/vc-install ',(cdr args)))) body) body))) (defun package-vc-use-package-override-:ensure (func name-symbol keyword ensure rest state) (let ((ensure (if (plist-member rest :vc) nil ensure))) (funcall func name-symbol keyword ensure rest state))) (defun package-vc-use-package-activate-advice () (advice-add 'use-package-handler/:ensure :around #'package-vc-use-package-override-:ensure)) (defun package-vc-use-package-deactivate-advice () (advice-remove 'use-package-handler/:ensure #'package-vc-use-package-override-:ensure)) ;; register keyword on require (package-vc-use-package-set-keyword) Now we can use this by first (because I use `use-package-always-ensure`) calling `package-vc-use-package-activate-advice` somewhere in our `init.el` and then utilising the new `vc` keyword: (use-package math-delimiters :vc (:fetcher "github" :repo "oantolin/math-delimiters")) I threw this together in 10 minutes, so the above code probably contains some redundancies, but that's the general idea. Not sure if it's worth making this an external package; if anything it should be added to Emacs core once use-package itself is merged.
SaltyMycologist8 · 2022-12-01 15:45
wow, thank you for use-package-ensure-always :)
ireallywantfreedom · 2022-12-01 19:33
Maybe I'm a weirdo, but I don't want to package any of my stuff on various package repositories. It just seems like a hassle and I don't want to deal with people potentially not using that package repo and wanting it on another. Is this the solution? Throw it on github and tell people to just `package-vc-install` it?
github-alphapapa · 2022-12-01 19:36
Seeing this signature was a bit disappointing: (package-vc-install PACKAGE &optional NAME REV BACKEND) It seems like keyword arguments should be used; we've had enough experience with `nil nil t nil t` by now, haven't we?
nv-elisp · 2022-12-01 21:14
That's been a possibility for quite some time with alternative package managers like straight, quelpa, elpaca, etc, but you may be overestimating the hassle. Whether you choose MELPA, GNU ELPA, or NonGNU ELPA, the process for getting a package approved is simple. So long as the package is available in one of these curated ELPAs, people don't usually care which it is available in.
slinchisl · 2022-12-02 07:54
Yes indeed; just one more reason to use some kind of `cl-defun` wrapper!
adouzzy · 2022-12-06 01:50
It's just lisp.
lygaret · 2022-12-21 01:53
dropped right into my site-lisp, working great, and agreed that it should get into core -- thanks a ton!!