Function: package-menu-execute

package-menu-execute is an interactive and byte-compiled function defined in package.el.gz.

Signature

(package-menu-execute &optional NOQUERY)

Documentation

Perform Package Menu actions on marked packages.

Packages marked for installation are downloaded and installed, packages marked for deletion are removed, and packages marked for upgrading are downloaded and upgraded.

If no packages are marked, the action taken depends on the state of the current package, the one at point. If it's not already installed, this command will install the package; if it's installed, the command will delete the package.

Optional argument NOQUERY non-nil means do not ask the user to confirm the installations/deletions; this is always nil in interactive invocations.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/package.el.gz
(defun package-menu-execute (&optional noquery)
  "Perform Package Menu actions on marked packages.
Packages marked for installation are downloaded and installed,
packages marked for deletion are removed, and packages marked for
upgrading are downloaded and upgraded.

If no packages are marked, the action taken depends on the state
of the current package, the one at point.  If it's not already
installed, this command will install the package; if it's installed,
the command will delete the package.

Optional argument NOQUERY non-nil means do not ask the user to
confirm the installations/deletions; this is always nil in interactive
invocations."
  (interactive nil package-menu-mode)
  (package--ensure-package-menu-mode)
  (let (install-list delete-list cmd pkg-desc)
    (save-excursion
      (goto-char (point-min))
      (while (not (eobp))
        (setq cmd (char-after))
        (unless (eq cmd ?\s)
          ;; This is the key PKG-DESC.
          (setq pkg-desc (tabulated-list-get-id))
          (cond ((eq cmd ?D)
                 (push pkg-desc delete-list))
                ((eq cmd ?I)
                 (push pkg-desc install-list))))
        (forward-line)))
    ;; Nothing marked.
    (unless (or delete-list install-list)
      ;; Not on a package line.
      (unless (and (tabulated-list-get-id)
                   package-menu-use-current-if-no-marks)
        (user-error "No operations specified"))
      (let* ((id (tabulated-list-get-id))
             (status (package-menu-get-status)))
        (cond
         ((member status '("installed"))
          (push id delete-list))
         ((member status '("available" "avail-obso" "new" "dependency"))
          (push id install-list))
         (t (user-error "No default action available for status: %s"
                        status)))))
    (let-alist (package-menu--partition-transaction install-list delete-list)
      (when (or noquery
                (package-menu--prompt-transaction-p .delete .install .upgrade))
        (let ((message-template
               (concat "[ "
                       (when .delete
                         (format "Delete %d " (length .delete)))
                       (when .install
                         (format "Install %d " (length .install)))
                       (when .upgrade
                         (format "Upgrade %d " (length .upgrade)))
                       "]")))
          (message "Operation %s started" message-template)
          ;; Packages being upgraded are not marked as selected.
          (package--update-selected-packages .install .delete)
          (unless (package-menu--perform-transaction install-list delete-list)
            ;; If there weren't errors, output data.
            (if-let* ((removable (package--removable-packages)))
                (message "Operation finished.  Packages that are no longer needed: %d.  Type `%s' to remove them"
                         (length removable)
                         (substitute-command-keys "\\[package-autoremove]"))
              (message "Operation %s finished" message-template))))))))