From dfcdc1cbed773041e907a389b8901ca845af49bb Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 23 Feb 2016 12:51:24 +1100 Subject: [PATCH] Allow deleting all non-matching cookies * lisp/url/url-cookie.el (url-cookie-delete-cookies): Allow keeping matching cookies (bug#22720). --- lisp/url/url-cookie.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lisp/url/url-cookie.el b/lisp/url/url-cookie.el index a4b7a58fdf3..6848230c28f 100644 --- a/lisp/url/url-cookie.el +++ b/lisp/url/url-cookie.el @@ -353,14 +353,19 @@ to run the `url-cookie-setup-save-timer' function manually." url-cookie-save-interval #'url-cookie-write-file)))) -(defun url-cookie-delete-cookies (&optional regexp) +(defun url-cookie-delete-cookies (&optional regexp keep) "Delete all cookies from the cookie store where the domain matches REGEXP. -If REGEXP is nil, all cookies are deleted." +If REGEXP is nil, all cookies are deleted. If KEEP is non-nil, +instead delete all cookies that do not match REGEXP." (dolist (variable '(url-cookie-secure-storage url-cookie-storage)) (let ((cookies (symbol-value variable))) (dolist (elem cookies) - (when (or (null regexp) - (string-match regexp (car elem))) + (when (or (and (null keep) + (or (null regexp) + (string-match regexp (car elem)))) + (and keep + regexp + (not (string-match regexp (car elem))))) (setq cookies (delq elem cookies)))) (set variable cookies))) (setq url-cookies-changed-since-last-save t) -- 2.39.5