4

How can I call use-package with a variable as the package name?

Something like:

(setq my-pkg "magit")
(use-package my-pkg :ensure t)

It would be, for example, used in a mapc call.

I tried functions like intern or make-symbol but I did not succeed.

Thank you!

2

FWIW, though macros cannot be mapped, as others have mentioned, they can be manipulated with more macros, if you're willing to write them. This is Lisp, after all. :)

POC:

(defmacro my-use-packages (&rest packages)
  "Ensure and defer PACKAGES using `use-package'."
  (declare (indent defun))
  (macroexp-progn
   (mapcar (lambda (package)
             `(use-package ,package :ensure :defer))
           packages)))

(my-use-packages
  2048-game
  alert
  async
  regex-tool)

expands to

(progn
  (use-package 2048-game :ensure :defer)
  (use-package alert :ensure :defer)
  (use-package async :ensure :defer)
  (use-package regex-tool :ensure :defer))

Now, whether this pattern is actually worth the bother or benefits anyone is a different matter.

0

Short answer: not possible ! https://github.com/jwiegley/use-package/issues/182#issuecomment-83226802 (thanks to @npostavs)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.