unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55470: [PATCH] Add package-delete-regexp
@ 2022-05-16 23:25 Marwan L. via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-05-17 17:48 ` Lars Ingebrigtsen
  2022-05-18 23:17 ` Philip Kaludercic
  0 siblings, 2 replies; 8+ messages in thread
From: Marwan L. via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-05-16 23:25 UTC (permalink / raw)
  To: 55470

[-- Attachment #1: Type: text/plain, Size: 346 bytes --]

This function allows you to delete packages, with names that match the
regexp. This is makes operations like deleting multiple packages that
begin with the same namespace (^company.*, ^treemacs.*, etc.) much
easier to do

The function will also tell you how much packages it will delete (in a
temporary buffer) and prompt for a Yes or No answer


[-- Attachment #2: package.diff --]
[-- Type: text/plain, Size: 1498 bytes --]

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index f356a2bf60..a166b0ef47 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2400,6 +2400,33 @@ If NOSAVE is non-nil, the package is not removed from
            (message "Package `%s' deleted."
                     (package-desc-full-name pkg-desc))))))
 
+(defun package-delete-regexp (pkg-regexp &optional force nosave)
+  "Delete packages matching the regexp PKG-REGEXP
+This will use `package-delete' to delete packages"
+  (interactive
+   (let ((pkg-regexp (read-string "Delete packages (regexp): ")))
+     (list pkg-regexp)))
+
+  ;;; Search through every package name and match it with the user's regexp
+  ;;; and filter out the nil's
+  (let ((pkg-list (remq nil
+                        (mapcar
+			 (lambda (elem)
+                           (if (string-match pkg-regexp (package-desc-full-name (nth 1 elem)))
+			       (nth 1 elem)))
+			 (package--alist)))))
+    (if (length> pkg-list 0) 
+	(with-output-to-temp-buffer "Package Deletion"
+	  (pop-to-buffer "Package Deletion")
+	  (princ "This operation will delete these following packages: \n")
+	  (dolist (elem pkg-list)
+	    (princ (format "%s\n" (package-desc-full-name elem))))
+	  (if (y-or-n-p "Delete? ")
+	      (dolist (elem pkg-list)
+		(package-delete elem force nosave)))
+	  (kill-current-buffer))
+      (message "No packages found"))))
+
 ;;;###autoload
 (defun package-reinstall (pkg)
   "Reinstall package PKG.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-08-09 15:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-16 23:25 bug#55470: [PATCH] Add package-delete-regexp Marwan L. via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-17 17:48 ` Lars Ingebrigtsen
2022-07-11 13:20   ` Lars Ingebrigtsen
2022-08-09 15:48     ` Lars Ingebrigtsen
2022-05-18 23:17 ` Philip Kaludercic
2022-05-19 12:04   ` Marwan L. via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-19 14:26     ` Philip Kaludercic
2022-05-19 18:15       ` Marwan L. via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).