[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master b8bdf64: New option to confirm deletion in bookmark menu
From: |
Karl Fogel |
Subject: |
master b8bdf64: New option to confirm deletion in bookmark menu |
Date: |
Wed, 5 May 2021 17:41:22 -0400 (EDT) |
branch: master
commit b8bdf64377120d2c802e4ef13cfab1fec8c37a27
Author: Karl Fogel <kfogel@red-bean.com>
Commit: Karl Fogel <kfogel@red-bean.com>
New option to confirm deletion in bookmark menu
* 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 | 8 +++++++
lisp/bookmark.el | 64 ++++++++++++++++++++++++++++++++++++--------------------
2 files changed, 49 insertions(+), 23 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 8f4a683..c759b33 100644
--- 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.
+
* Editing Changes in Emacs 28.1
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index 3b75190..64b467a 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -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 ()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master b8bdf64: New option to confirm deletion in bookmark menu,
Karl Fogel <=