From: Karl Fogel <kfogel@red-bean.com>
To: Emacs Development <emacs-devel@gnu.org>
Subject: [PATCH] When deleting in bookmark menu, prompt for confirmation.
Date: Sun, 02 May 2021 22:43:03 -0500 [thread overview]
Message-ID: <87a6pcqy7s.fsf@red-bean.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 420 bytes --]
I wanted to run this by folks here to get opinions/review before
committing. It stems from a suggestion by Oliver Taylor in a
thread on the Emacs Humanites mailing list (the thread is linked
to from the commit message).
If you prefer to view this patch in the GitLab diff-browsing
interface, it's here:
https://code.librehq.com/kfogel/emacs/-/commit/73b688abbb20ce48a7a5ea69e53e8a8bb6b279fc
Best regards,
-Karl
[-- Attachment #2: bookmark-menu-deletion-confirmation-patch.txt --]
[-- Type: text/plain, Size: 4263 bytes --]
[[[
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 ()
next reply other threads:[~2021-05-03 3:43 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-03 3:43 Karl Fogel [this message]
2021-05-03 9:16 ` [PATCH] When deleting in bookmark menu, prompt for confirmation Lars Ingebrigtsen
2021-05-03 12:48 ` Stefan Kangas
2021-05-03 13:02 ` Stefan Monnier
2021-05-04 7:53 ` Lars Ingebrigtsen
2021-05-04 16:29 ` [External] : " Drew Adams
2021-05-03 11:41 ` Eli Zaretskii
2021-05-03 12:47 ` Stefan Kangas
2021-05-03 13:16 ` Eli Zaretskii
2021-05-03 15:43 ` Stefan Kangas
2021-05-03 16:25 ` Eli Zaretskii
2021-05-03 17:21 ` Karl Fogel
2021-05-03 17:41 ` Eli Zaretskii
2021-05-03 18:28 ` Jim Porter
2021-05-03 18:44 ` Eli Zaretskii
2021-05-03 19:01 ` Jim Porter
2021-05-03 20:52 ` Karl Fogel
2021-05-05 5:24 ` Karl Fogel
2021-05-05 8:11 ` Lars Ingebrigtsen
2021-05-05 19:37 ` Karl Fogel
2021-05-05 20:06 ` Stefan Monnier
2021-05-05 21:38 ` Karl Fogel
2021-05-05 23:17 ` [External] : " Drew Adams
2021-05-05 23:25 ` Karl Fogel
2021-05-06 6:52 ` Matthias Meulien
2021-05-06 15:29 ` Drew Adams
2021-05-08 20:46 ` Matthias Meulien
2021-05-09 8:54 ` Eli Zaretskii
2021-05-09 18:37 ` Karl Fogel
2021-05-09 18:39 ` Eli Zaretskii
2021-05-25 5:38 ` Karl Fogel
2021-05-25 12:09 ` Eli Zaretskii
2021-05-25 20:24 ` Karl Fogel
2021-05-26 11:59 ` Eli Zaretskii
2021-05-26 19:33 ` Karl Fogel
2021-05-07 17:42 ` Karl Fogel
2021-05-07 22:24 ` Drew Adams
2021-05-08 6:13 ` Karl Fogel
2021-05-06 8:49 ` Lars Ingebrigtsen
2021-05-06 13:30 ` Stefan Monnier
2021-05-07 8:40 ` Lars Ingebrigtsen
2021-05-07 12:55 ` Stefan Monnier
2021-05-09 9:55 ` Lars Ingebrigtsen
2021-05-09 15:04 ` Stefan Kangas
2021-05-09 18:01 ` Stefan Monnier
2021-05-10 8:30 ` Lars Ingebrigtsen
2021-05-07 17:40 ` Karl Fogel
2021-05-05 11:56 ` Eli Zaretskii
2021-05-05 21:43 ` Karl Fogel
2021-05-03 17:43 ` [External] : " Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a6pcqy7s.fsf@red-bean.com \
--to=kfogel@red-bean.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).