From: "Marwan L." via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 55470@debbugs.gnu.org
Subject: bug#55470: [PATCH] Add package-delete-regexp
Date: Tue, 17 May 2022 00:25:30 +0100 [thread overview]
Message-ID: <YoLdajcK6fsLZvV2@mlgnu.home> (raw)
[-- 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.
next reply other threads:[~2022-05-16 23:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-16 23:25 Marwan L. via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-05-17 17:48 ` bug#55470: [PATCH] Add package-delete-regexp 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YoLdajcK6fsLZvV2@mlgnu.home \
--to=bug-gnu-emacs@gnu.org \
--cc=55470@debbugs.gnu.org \
--cc=techmetx11@disroot.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.