Make package-install accept a string as well

* lisp/emacs-lisp/package.el (package-install): Allow passing a string
instead of a symbol.  (Bug#72160)
(package-upgrade): Improve docstring.

* test/lisp/emacs-lisp/package-tests.el
(package-test-install-single-from-archive/string-type): New test.
This commit is contained in:
Stefan Kangas 2025-03-02 04:12:57 +01:00
parent 38782e684b
commit 735eace97b
2 changed files with 14 additions and 2 deletions

View file

@ -2196,7 +2196,8 @@ built-in package with a (possibly newer) version from a package archive."
;;;###autoload
(defun package-install (pkg &optional dont-select)
"Install the package PKG.
PKG can be a `package-desc' or a symbol naming one of the
PKG can be a `package-desc', or a symbol or string naming one of the
available packages in an archive in `package-archives'.
Mark the installed package as selected by adding it to
@ -2229,6 +2230,8 @@ had been enabled."
package-archive-contents)
nil t))
nil)))
(cl-check-type pkg (or string symbol package-desc))
(if (stringp pkg) (setq pkg (intern pkg)))
(package--archives-initialize)
(add-hook 'post-command-hook #'package-menu--post-refresh)
(let ((name (if (package-desc-p pkg)
@ -2256,7 +2259,9 @@ had been enabled."
;;;###autoload
(defun package-upgrade (name)
"Upgrade package NAME if a newer version exists."
"Upgrade package NAME if a newer version exists.
NAME can be either a symbol or a string."
(interactive
(list (completing-read
"Upgrade package: " (package--upgradeable-packages t) nil t)))

View file

@ -450,6 +450,13 @@ but with a different end of line convention (bug#48137)."
(package-refresh-contents)
(package-install 'simple-single)))
(ert-deftest package-test-install-single-from-archive/string-type ()
"Install a single package from a package archive, using string argument."
(with-package-test ()
(package-initialize)
(package-refresh-contents)
(package-install "simple-single")))
(ert-deftest package-test-install-prioritized ()
"Install a lower version from a higher-prioritized archive."
(with-package-test ()