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!

SmartyLisp
  • 117
  • 1
  • 6
  • The answer is probably no, see https://github.com/jwiegley/use-package/issues/182#issuecomment-83226802 – npostavs May 12 '17 at 14:52

2 Answers2

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.

Basil
  • 12,383
  • 43
  • 69
0

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

SmartyLisp
  • 117
  • 1
  • 6