[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 003a89b 2/2: Add an undo command to url-cookie-mode

From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 003a89b 2/2: Add an undo command to url-cookie-mode
Date: Sun, 15 Apr 2018 16:49:29 -0400 (EDT)

branch: master
commit 003a89b6c8eb5e62b4ba2f2f3d4d3e3f6a8b7484
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Add an undo command to url-cookie-mode
    * lisp/url/url-cookie.el (url-cookie-undo): New command and
    keystroke (bug#16650).
 lisp/url/url-cookie.el | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/lisp/url/url-cookie.el b/lisp/url/url-cookie.el
index 535a98c..3adca26 100644
--- a/lisp/url/url-cookie.el
+++ b/lisp/url/url-cookie.el
@@ -395,6 +395,8 @@ instead delete all cookies that do not match REGEXP."
 ;;; Mode for listing and editing cookies.
+(defvar url-cookie--deleted-cookies nil)
 (defun url-cookie-list ()
   "Display a buffer listing the current URL cookies, if there are any.
 Use \\<url-cookie-mode-map>\\[url-cookie-delete] to remove cookies."
@@ -466,12 +468,37 @@ Use \\<url-cookie-mode-map>\\[url-cookie-delete] to 
remove cookies."
     (let ((point (point)))
+      (goto-char point))
+    (push cookie url-cookie--deleted-cookies)))
+(defun url-cookie-undo ()
+  "Undo deletion of a cookie."
+  (interactive)
+  (unless url-cookie--deleted-cookies
+    (error "No cookie deletions to undo"))
+  (let* ((cookie (pop url-cookie--deleted-cookies))
+         (variable (if (url-cookie-secure cookie)
+                      'url-cookie-secure-storage
+                    'url-cookie-storage))
+         (list (symbol-value variable))
+        (elem (assoc (url-cookie-domain cookie) list)))
+    (if elem
+        (nconc elem (list cookie))
+      (setq elem (list (url-cookie-domain cookie) cookie))
+      (set variable (cons elem list)))
+    (setq url-cookies-changed-since-last-save t)
+    (url-cookie-write-file)
+    (let ((point (point))
+          (inhibit-read-only t))
+      (erase-buffer)
+      (url-cookie--generate-buffer)
       (goto-char point))))
 (defvar url-cookie-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map [delete] 'url-cookie-delete)
     (define-key map [(control k)] 'url-cookie-delete)
+    (define-key map [(control _)] 'url-cookie-undo)
 (define-derived-mode url-cookie-mode special-mode "URL Cookie"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]