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 @@
(package-menu-mark-delete, package-menu--find-upgrades)
(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>
* 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
'package-selected-packages (remove name package-selected-packages)))
(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
(defun package-autoremove ()
"Remove packages that are no more needed.
......@@ -1550,21 +1562,15 @@ will be deleted."
(when (or package-selected-packages
(yes-or-no-p
"`package-selected-packages' is empty! Really remove ALL packages? "))
(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 into lst
finally (if lst
(let ((removable (package--removable-packages)))
(if removable
(when (y-or-n-p
(format "%s packages will be deleted:\n%s, proceed? "
(length lst)
(mapconcat #'symbol-name lst ", ")))
(length removable)
(mapconcat #'symbol-name removable ", ")))
(mapc (lambda (p)
(package-delete (cadr (assq p package-alist)) t))
lst))
removable)
(message "Nothing to autoremove"))))))
(defun package-archive-base (desc)
......@@ -2377,9 +2383,18 @@ Optional argument NOQUERY non-nil means do not ask the user to confirm."
(package-delete elt)
(error (message (cadr err)))))
(error "Aborted")))
(if (or delete-list install-list)
(package-menu--generate t t)
(message "No operations specified."))))
(if (not (or delete-list install-list))
(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)
(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