slotThe/vc-use-package

Question about the role of :ensure

natrys opened this issue · 4 comments

As far as I can tell, if the package isn't installed, use-package won't install it automatically unless use-package-always-ensure is set to true, or user explicitly passes :ensure t.

I was wondering about what the vc-use-package--override-:ensure advice does? It seems to me vc-use-package installs the package (if it isn't installed), regardless of the value of :ensure (or if one is passed at all), or the value of use-package-always-ensure.

Installing probably makes the most sense as default, for a user of this package. But I think it would be nice to have this package do nothing, in case user explicitly sets :ensure nil.

I was wondering about what the vc-use-package--override-:ensure advice does?

It effectively disables :ensure when using :vc as well. The reason is that :ensure runs before :vc and thus the generated code will always have that stanza before whatever we write. For example, without the advice,

(use-package math-delimiters
  :ensure t
  :vc (:fetcher github :repo "oantolin/math-delimiters"))

would expand to something like

(progn
  (use-package-ensure-elpa 'math-delimiters '(t) 'nil)
  (unless (package-installed-p 'math-delimiters)
    (package-vc-install
     '(math-delimiters :url "https://github.com/oantolin/math-delimiters")
     nil))
  …)

The problem here is that use-package-ensure-elpa now tries to install the package from a package archive. We obviously don't want that, hence we change the first line to (use-package-ensure-elpa 'math-delimiters 'nil 'nil) in the presence of the :vc keyword. We could also omit the line entirely (because that's what setting the second argument to nil effectively does), but this is the least invasive way of doing it.

It seems to me vc-use-package installs the package (if it isn't installed), regardless of the value of :ensure (or if one is passed at all), or the value of use-package-always-ensure.

Yes.

Installing probably makes the most sense as default, for a user of this package. But I think it would be nice to have this package do nothing, in case user explicitly sets :ensure nil.

Do you have a specific use-case in mind? Since :vc explicitly means "get this from there", I think not installing a package unless :ensure t is set in some way (:ensure nil is indistinguishable from not specifying anything at all) would be a bit counterintuitive.

Do you have a specific use-case in mind?

It's just that sometimes when I play with a package and don't feel like permanently having it around (and autoloaded), I delete them. But I still like to keep the configuration, so that later I can just toggle :ensure and have it like working like before. But I guess this is just an aesthetical preference, commenting out the code accomplishes same thing, except looks ugly and stains git log ;) Do have an idea how I could perhaps make loading a noop with :vc and without commenting out the use-package block?

But actually I was operating under the assumption that there was some precedence for :ensure nil. I remember when I was using a local fork of org-mode using :load-path of use-package, I had to explicitly set ensure to nil, otherwise it was defaulting to org-mode bundled with Emacs. But now that I check, it was most likely a bug in use-package because it now works with or without ensure. Therefore I retract my suggestion.

Do have an idea how I could perhaps make loading a noop with :vc and without commenting out the use-package block?

You can use :disabled t to turn the whole declaration into a noop without commenting it out.

Thanks @slotThe. I can't believe I forgot about it.