emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master c56070beb6 2/3: Make `x' in package-menu-mode more DWIM


From: Lars Ingebrigtsen
Subject: master c56070beb6 2/3: Make `x' in package-menu-mode more DWIM
Date: Sat, 7 May 2022 08:35:31 -0400 (EDT)

branch: master
commit c56070beb6cb7bc383c7f39215c915e1f43fd578
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make `x' in package-menu-mode more DWIM
    
    * lisp/emacs-lisp/package.el (package-menu-mode): Make the doc
    string more helpful.
    (package-menu-execute): Make `x' when no files are installed DWIM.
---
 etc/NEWS                   |  4 ++++
 lisp/emacs-lisp/package.el | 31 +++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 2e7a1d8638..5dd87e3e9e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -748,6 +748,10 @@ this includes "binary" buffers like 'archive-mode' and 
'image-mode'.
 This command allows you to upgrade packages without using 'M-x
 list-packages'.
 
+*** New DWIM action on 'x'.
+If no packages are marked, 'x' will install the package under point if
+it isn't already, and remove it if it is installed.
+
 ** Miscellaneous
 
 +++
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 58c1349e1c..c1e14a4acb 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2885,7 +2885,13 @@ either a full name or nil, and EMAIL is a valid email 
address."
 
 (define-derived-mode package-menu-mode tabulated-list-mode "Package Menu"
   "Major mode for browsing a list of packages.
-Letters do not insert themselves; instead, they are commands.
+The most useful commands here are:
+
+  `x': Install the package under point if it isn't already installed,
+       and delete it if it's already installed,
+  `i': mark a package for installation, and
+  `d': mark a package for deletion.  Use the `x' command to perform the
+       actions on the marked files.
 \\<package-menu-mode-map>
 \\{package-menu-mode-map}"
   :interactive nil
@@ -3632,8 +3638,13 @@ packages list, respectively."
 (defun package-menu-execute (&optional noquery)
   "Perform marked Package Menu actions.
 Packages marked for installation are downloaded and installed,
-packages marked for deletion are removed,
-and packages marked for upgrading are downloaded and upgraded.
+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 package under point.  If it's not already installed, this
+command will install the package, and if it's installed, it will
+delete the package.
 
 Optional argument NOQUERY non-nil means do not ask the user to confirm."
   (interactive nil package-menu-mode)
@@ -3651,8 +3662,20 @@ Optional argument NOQUERY non-nil means do not ask the 
user to confirm."
                 ((eq cmd ?I)
                  (push pkg-desc install-list))))
         (forward-line)))
+    ;; Nothing marked.
     (unless (or delete-list install-list)
-      (user-error "No operations specified"))
+      ;; Not on a package line.
+      (unless (tabulated-list-get-id)
+        (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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]