Commit 2a4a5069 authored by Artur Malabarba's avatar Artur Malabarba

emacs-lisp/package.el (package-menu-execute): Offer to remove packages.

parent 504fada7
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
(package-menu-mark-delete, package-menu--find-upgrades) (package-menu-mark-delete, package-menu--find-upgrades)
(package-menu--status-predicate, describe-package-1): Use it (package-menu--status-predicate, describe-package-1): Use it
(package--removable-packages): New function.
(package-autoremove): Use it.
(package-menu-execute): Offer to remove unneeded packages.
2015-02-03 Thierry Volpiatto <thierry.volpiatto@gmail.com> 2015-02-03 Thierry Volpiatto <thierry.volpiatto@gmail.com>
* emacs-lisp/package.el (package-reinstall): Don't change package's selected status. * emacs-lisp/package.el (package-reinstall): Don't change package's selected status.
......
...@@ -1536,6 +1536,18 @@ If NOSAVE is non-nil, the package is not removed from ...@@ -1536,6 +1536,18 @@ If NOSAVE is non-nil, the package is not removed from
'package-selected-packages (remove name package-selected-packages))) 'package-selected-packages (remove name package-selected-packages)))
(message "Package `%s' deleted." (package-desc-full-name pkg-desc)))))) (message "Package `%s' deleted." (package-desc-full-name pkg-desc))))))
(defun package--removable-packages ()
"Return a list of names of packages no longer needed.
These are packages which are neither contained in
`package-selected-packages' nor a dependency of one that is."
(let ((needed (cl-loop for p in package-selected-packages
if (assq p package-alist)
;; `p' and its dependencies are needed.
append (cons p (package--get-deps p)))))
(cl-loop for p in (mapcar #'car package-alist)
unless (memq p needed)
collect p)))
;;;###autoload ;;;###autoload
(defun package-autoremove () (defun package-autoremove ()
"Remove packages that are no more needed. "Remove packages that are no more needed.
...@@ -1550,22 +1562,16 @@ will be deleted." ...@@ -1550,22 +1562,16 @@ will be deleted."
(when (or package-selected-packages (when (or package-selected-packages
(yes-or-no-p (yes-or-no-p
"`package-selected-packages' is empty! Really remove ALL packages? ")) "`package-selected-packages' is empty! Really remove ALL packages? "))
(let ((needed (cl-loop for p in package-selected-packages (let ((removable (package--removable-packages)))
if (assq p package-alist) (if removable
;; `p' and its dependencies are needed. (when (y-or-n-p
append (cons p (package--get-deps p))))) (format "%s packages will be deleted:\n%s, proceed? "
(cl-loop for p in (mapcar #'car package-alist) (length removable)
unless (memq p needed) (mapconcat #'symbol-name removable ", ")))
collect p into lst (mapc (lambda (p)
finally (if lst (package-delete (cadr (assq p package-alist)) t))
(when (y-or-n-p removable)
(format "%s packages will be deleted:\n%s, proceed? " (message "Nothing to autoremove"))))))
(length lst)
(mapconcat #'symbol-name lst ", ")))
(mapc (lambda (p)
(package-delete (cadr (assq p package-alist)) t))
lst))
(message "Nothing to autoremove"))))))
(defun package-archive-base (desc) (defun package-archive-base (desc)
"Return the archive containing the package NAME." "Return the archive containing the package NAME."
...@@ -2377,9 +2383,18 @@ Optional argument NOQUERY non-nil means do not ask the user to confirm." ...@@ -2377,9 +2383,18 @@ Optional argument NOQUERY non-nil means do not ask the user to confirm."
(package-delete elt) (package-delete elt)
(error (message (cadr err))))) (error (message (cadr err)))))
(error "Aborted"))) (error "Aborted")))
(if (or delete-list install-list) (if (not (or delete-list install-list))
(package-menu--generate t t) (message "No operations specified.")
(message "No operations specified.")))) (when package-selected-packages
(let ((removable (package--removable-packages)))
(when (and removable
(y-or-n-p
(format "These %d packages are no longer needed, delete them (%s)? "
(length removable)
(mapconcat #'symbol-name removable ", "))))
(mapc (lambda (p) (package-delete (cadr (assq p package-alist))))
removable))))
(package-menu--generate t t))))
(defun package-menu--version-predicate (A B) (defun package-menu--version-predicate (A B)
(let ((vA (or (aref (cadr A) 1) '(0))) (let ((vA (or (aref (cadr A) 1) '(0)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment