[[[ In bookmark menu, offer prompt to confirm deletion * src/emacs/lisp/bookmark.el (bookmark-menu-confirm-deletion): New defcustom. (bookmark-bmenu-execute-deletions): Conditionally confirm. (bookmark-delete-all): Add comment explaining why we don't use the new confirmation formula here. (Note: the bulk of the code diff is just reindentation of an otherwise unchanged `let' expression in `bookmark-bmenu-execute-deletions'.) Thanks to Oliver Taylor for suggesting the new behavior: 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> ]]] --- lisp/bookmark.el +++ lisp/bookmark.el @@ -121,6 +121,12 @@ bookmark-sort-flag :type 'boolean) +(defcustom bookmark-menu-confirm-deletion t + "Non-nil means prompt for confirmation when executing the deletion +of bookmarks marked for deletion in a bookmark menu buffer. Nil +means don't prompt for confirmation." + :type 'boolean) + (defcustom bookmark-automatically-show-annotations t "Non-nil means show annotations when jumping to a bookmark." :type 'boolean) @@ -1376,6 +1382,13 @@ bookmark-delete-all 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) @@ -2142,30 +2155,35 @@ bookmark-bmenu-delete-all (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 ()