unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Karl Fogel <kfogel@red-bean.com>
To: emacs-devel@gnu.org
Subject: Re: [PATCH] When deleting in bookmark menu, prompt for confirmation.
Date: Wed, 05 May 2021 00:24:07 -0500	[thread overview]
Message-ID: <87mtt9sqh4.fsf@red-bean.com> (raw)
In-Reply-To: <83zgxb67g2.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 03 May 2021 20:41:33 +0300")

[-- Attachment #1: Type: text/plain, Size: 702 bytes --]

Revised patch attached, with the option now defaulting to nil 
(i.e., to the old behavior) as per discussion.  Review/comments 
welcome.

Lars, you wrote this regarding v1 of this patch:

>...the first line [of the doc string] should be a complete 
>sentence.

It actually was a complete sentence even in v1, but I think I know 
what you meant.  However, the "Non-nil means..." phrasing is found 
throughout Emacs -- I counted over 1000 places with this quick 
check:

  $ find lisp -name "*.el" | xargs grep '"Non-nil means'

(One can add '-C3' to grep to see that they are indeed 
`defcustom's and `defvar's.)

I guess that people are used to it, so I left that phrasing as-is.

Best regards,
-Karl


[-- Attachment #2: bookmark-menu-deletion-confirmation-patch-v2.txt --]
[-- Type: text/plain, Size: 4943 bytes --]

[[[
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
+++ 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
 
--- lisp/bookmark.el
+++ lisp/bookmark.el
@@ -121,6 +121,13 @@ bookmark-sort-flag
   :type 'boolean)
 
 
+(defcustom bookmark-menu-confirm-deletion nil
+  "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."
+  :version "28.1"
+  :type 'boolean)
+
 (defcustom bookmark-automatically-show-annotations t
   "Non-nil means show annotations when jumping to a bookmark."
   :type 'boolean)
@@ -1376,6 +1383,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 +2156,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 ()

  parent reply	other threads:[~2021-05-05  5:24 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03  3:43 [PATCH] When deleting in bookmark menu, prompt for confirmation Karl Fogel
2021-05-03  9:16 ` 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 [this message]
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=87mtt9sqh4.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).