Straight.el: packages + dependencies stay installed even if not declared in the init file

Created on 1 Sep 2017  路  4Comments  路  Source: raxod502/straight.el

After a package is installed with straight-use-package is not deleted even after the straight-use-package declaration is removed from init.el Should it (and it's dependencies) be removed automatically? Is there an existing way to avoid removing the packages manually from the straight folder? I could not find one.

question

Most helpful comment

By default, straight.el never deletes package code, since it has no way of knowing that you don't have valuable local changes in those Git repositories. The important point is that packages unreferenced by your init-file are not loaded, so they cannot affect the behavior of your Emacs session. (This is unlike package.el, where having a package on disk means that it is loaded automatically.)

You can remove unused data from the build directory using M-x straight-prune-build. There is no automatic way to remove unused Git repositories, although I am not opposed to adding such a command (it would need to go through all such repositories interactively, and warn about unstaged changes, possibly useful stashes, etc. in order to be safe).

If you'd like to throw together a quick command to take care of this in a less-safe way, you can get a list of all packages that were loaded (directly or transitively) by your init-file using the following form:

(hash-table-keys straight--profile-cache)

All 4 comments

By default, straight.el never deletes package code, since it has no way of knowing that you don't have valuable local changes in those Git repositories. The important point is that packages unreferenced by your init-file are not loaded, so they cannot affect the behavior of your Emacs session. (This is unlike package.el, where having a package on disk means that it is loaded automatically.)

You can remove unused data from the build directory using M-x straight-prune-build. There is no automatic way to remove unused Git repositories, although I am not opposed to adding such a command (it would need to go through all such repositories interactively, and warn about unstaged changes, possibly useful stashes, etc. in order to be safe).

If you'd like to throw together a quick command to take care of this in a less-safe way, you can get a list of all packages that were loaded (directly or transitively) by your init-file using the following form:

(hash-table-keys straight--profile-cache)

One more important note: the above form will give you a list of all loaded packages. But the name of a package's Git repository does not have to be the same as the package name, and indeed multiple different packages can be built from the same Git repository. (See the conceptual overview.)

To get the name of the Git repository that a given package was built from, use the following form:

(plist-get (gethash "package-name-as-string" straight--recipe-cache) :local-repo)

Ok. I'm going to write a quick command to do this to see how hard it is to implement the safe method. Should I leave this issue open in case someone else also wants to work on this?

That feature is already tracked in https://github.com/raxod502/straight.el/issues/49, so there's no need for a separate ticket, I think.

If you're looking to fix this in straight.el proper (as opposed to in your own configuration), then I would recommend that the method use straight--map-repos-interactively on the list of all unused Git repositories. You wouldn't need to interface with the VC backend system necessarily, since this is kind of a separate operation, but I would recommend using the validator pattern as seen in e.g. straight-vc-git--validate-remote/straight-vc-git--validate-local/straight-vc-git-normalize. (The idea is to write a set of validator functions which detect a number of error conditions and present the user with a popup, take some action, and then return non-nil iff there were no error conditions to begin with. Then validators can be composed using and, and the top-level function called by straight--map-repos-interactively simply calls the validators in a while loop until they all return non-nil.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raxod502 picture raxod502  路  3Comments

gagbo picture gagbo  路  4Comments

hlissner picture hlissner  路  3Comments

aspiers picture aspiers  路  4Comments

Fuco1 picture Fuco1  路  3Comments