]> git.eshelyaron.com Git - emacs.git/commitdiff
New option to confirm deletion in bookmark menu
authorKarl Fogel <kfogel@red-bean.com>
Wed, 5 May 2021 21:40:52 +0000 (16:40 -0500)
committerKarl Fogel <kfogel@red-bean.com>
Wed, 5 May 2021 21:40:52 +0000 (16:40 -0500)
* lisp/bookmark.el (bookmark-menu-confirm-deletion): New defcustom.
(bookmark-delete-all): Add comment explaining why we don't use the new
confirmation formula here.
(bookmark-bmenu-execute-deletions): Conditionally confirm deletion.
Note that the bulk of the code diff here is just reindentation of an
otherwise unchanged `let' expression.

* etc/NEWS: Announce the new option.

Thanks to Lars Ingebrigtsen and Eli Zaretskii for review, and thanks
to Oliver Taylor for suggesting the option in the first place:

  https://lists.gnu.org/archive/html/emacs-humanities/2021-02/msg00022.html
  From: Oliver Taylor
  Subject: Re: [emacs-humanities] Extending Emacs Bookmarks to Work with EWW
  To: Karl Fogel
Cc: Stefan Kangas, Emacs-humanities mailing list
  Date: Wed, 3 Feb 2021 20:21:59 -0800
  Message-Id: <936D47EA-4D11-452B-8303-971B6386877B@me.com>

etc/NEWS
lisp/bookmark.el

index 8f4a6837b1a08854ef9438baaa428de60a101064..c759b333b609a8e0b4150d5f3aa03fbd3829a5d7 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -276,6 +276,14 @@ commands.  The new keystrokes are 'C-x x g' ('revert-buffer'),
 ** Commands 'set-frame-width' and 'set-frame-height' can now get their
 input using the minibuffer.
 
+---
+** New user option 'bookmark-menu-confirm-deletion'
+In Bookmark Menu mode, Emacs by default does not prompt for
+confirmation when you type 'x' to execute the deletion of bookmarks
+that have been marked for deletion.  However, if this new option is
+non-nil then Emacs will require confirmation with 'yes-or-no-p' before
+deleting.
+
 \f
 * Editing Changes in Emacs 28.1
 
index 3b7519059f7fa2e4ca35701e43efa25dad43456f..64b467adfaedf75b1137815a41a11b4c75af08bf 100644 (file)
@@ -121,6 +121,12 @@ recently set ones come first, oldest ones come last)."
   :type 'boolean)
 
 
+(defcustom bookmark-menu-confirm-deletion nil
+  "Non-nil means confirm before deleting bookmarks in a bookmark menu buffer.
+Nil means don't prompt for confirmation."
+  :version "28.1"
+  :type 'boolean)
+
 (defcustom bookmark-automatically-show-annotations t
   "Non-nil means show annotations when jumping to a bookmark."
   :type 'boolean)
@@ -1433,6 +1439,13 @@ probably because we were called from there."
 If optional argument NO-CONFIRM is non-nil, don't ask for
 confirmation."
   (interactive "P")
+  ;; We don't use `bookmark-menu-confirm-deletion' here because that
+  ;; variable is specifically to control confirmation prompting in a
+  ;; bookmark menu buffer, where the user has the marked-for-deletion
+  ;; bookmarks arrayed in front of them and might have accidentally
+  ;; hit the key that executes the deletions.  The UI situation here
+  ;; is quite different, by contrast: the user got to this point by a
+  ;; sequence of keystrokes unlikely to be typed by chance.
   (when (or no-confirm
             (yes-or-no-p "Permanently delete all bookmarks? "))
     (bookmark-maybe-load-default-file)
@@ -2199,30 +2212,35 @@ To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\
 
 
 (defun bookmark-bmenu-execute-deletions ()
-  "Delete bookmarks flagged `D'."
+  "Delete bookmarks flagged `D'.
+If `bookmark-menu-confirm-deletion' is non-nil, prompt for
+confirmation first."
   (interactive nil bookmark-bmenu-mode)
-  (let ((reporter (make-progress-reporter "Deleting bookmarks..."))
-        (o-point  (point))
-        (o-str    (save-excursion
-                    (beginning-of-line)
-                    (unless (= (following-char) ?D)
-                      (buffer-substring
-                       (point)
-                       (progn (end-of-line) (point))))))
-        (o-col     (current-column)))
-    (goto-char (point-min))
-    (while (re-search-forward "^D" (point-max) t)
-      (bookmark-delete (bookmark-bmenu-bookmark) t)) ; pass BATCH arg
-    (bookmark-bmenu-list)
-    (if o-str
-        (progn
-          (goto-char (point-min))
-          (search-forward o-str)
-          (beginning-of-line)
-          (forward-char o-col))
-      (goto-char o-point))
-    (beginning-of-line)
-    (progress-reporter-done reporter)))
+  (if (and bookmark-menu-confirm-deletion
+           (not (yes-or-no-p "Delete selected bookmarks? ")))
+      (message "Bookmarks not deleted.")
+    (let ((reporter (make-progress-reporter "Deleting bookmarks..."))
+          (o-point  (point))
+          (o-str    (save-excursion
+                      (beginning-of-line)
+                      (unless (= (following-char) ?D)
+                        (buffer-substring
+                         (point)
+                         (progn (end-of-line) (point))))))
+          (o-col     (current-column)))
+      (goto-char (point-min))
+      (while (re-search-forward "^D" (point-max) t)
+        (bookmark-delete (bookmark-bmenu-bookmark) t)) ; pass BATCH arg
+      (bookmark-bmenu-list)
+      (if o-str
+          (progn
+            (goto-char (point-min))
+            (search-forward o-str)
+            (beginning-of-line)
+            (forward-char o-col))
+        (goto-char o-point))
+      (beginning-of-line)
+      (progress-reporter-done reporter))))
 
 
 (defun bookmark-bmenu-rename ()