From the variable’s documentation:
Store here packages installed explicitly by user.
Whatever you explicitly install (e.g. with the package-install
command, or with a package “manager” like use-package
), gets into this variable.
This variable is fed automatically by Emacs when installing a new package.
So it happens automatically! In fact, it gets saved to your custom-file
if set via customize
(which package.el
does for you).
Still from the documentation (also mentioned by @phils in a comment)
This variable is used by package-autoremove
to decide
which packages are no longer needed.
Whenever you issue the package-autoremove
command it consults this variable. package-autoremove
will remove everything that is
- not marked as explicitly installed (ie. not in this list), and
- not a dependency of an explicitly installed package.
The documentation also tells another use-case:
You can use it to (re)install packages on other machines
by running package-install-selected-packages
.
So simply populate this variable manually, and use that command to install your favourite packages on all your machines.
To have a better picture, go to the package manager using list-packages
. You will see a bunch of
available
packages; these are available in the configured repositories (see package-archives
), but not installed on your system
installed
packages; these are what you installed explicitly. This list is exactly the same as your package-selected-packages
.
dependency
packages; these are packages that are installed on your system, but that are not in package-selected-packages
. Under normal circumstances these are installed as dependencies of other packages
built-in
packages; these are shipped with your Emacs installation and always available. You can’t remove them.
obsolete
packages; these are packages you have installed, but there is a newer version available
incompat
packages are packages that can’t be installed on your system. The reason is always stated by describe-package
, e.g. “because it depends on Emacs 27” or “because it depends on uninstallable packages”.
For (much) more info, see the emacs(Packages) info node.
package-autoremove
to decide which packages are no longer needed. You can use it to (re)install packages on other machines by runningpackage-install-selected-packages
." – phils Jun 15 '20 at 13:53(setq nameofpackage VALUE)
sets a variable callednameofpackage
to value VALUE. It doesn't do anything else, unless that variable has a particular purpose in other code. – phils Jun 16 '20 at 11:00(setq nameofpackage t)
won't tell the package system anything. It just sets a variable. If no other elisp uses a variable by that name, then it essentially has no effect whatsoever. If that is a variable which is used by other code (such as, but not necessarily, the package in question), then you'd have to read the docstring for that variable to learn what the effect of setting it tot
would be. – phils Jun 17 '20 at 04:45package-selected-packages
has an effect because there is elisp code in the package manager which uses that variable. – phils Jun 17 '20 at 04:51