I've tried this:
(setq pkg-list '(rust-mode lsp-mode))
(dolist (pkg pkg-list)
(when (package-installed-p pkg)
(package-delete pkg)))
But it doesn't work.
In a case like this you can inspect the function to see what it does with the interactive
form. That is, use C-h f package-delete
, then follow the link to the source, and then look at the (interactive ...)
bit. You'll also see in the docstring that the function expects a cl struct.
The code for this function is a bit convoluted, but eventually you can see that it is looking up in package-alist
. So you can use:
(dolist (pkg pkg-list)
(when (package-installed-p pkg)
(package-delete (car (cdr (assoc pkg package-alist))))))
Argument PKG-DESC is a full description of package as vector.
Debugger entered--Lisp error: (wrong-type-argument package-desc rust-mode)
. The code is working withpackage-install
.