From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Karl Fogel Newsgroups: gmane.emacs.devel Subject: [PATCH] When deleting in bookmark menu, prompt for confirmation. Date: Sun, 02 May 2021 22:43:03 -0500 Message-ID: <87a6pcqy7s.fsf@red-bean.com> Reply-To: Karl Fogel Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6940"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: Emacs Development Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 03 05:43:55 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ldPUw-0001i0-Ud for ged-emacs-devel@m.gmane-mx.org; Mon, 03 May 2021 05:43:55 +0200 Original-Received: from localhost ([::1]:54392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldPUw-0006YS-1m for ged-emacs-devel@m.gmane-mx.org; Sun, 02 May 2021 23:43:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldPUF-00060B-41 for emacs-devel@gnu.org; Sun, 02 May 2021 23:43:11 -0400 Original-Received: from sanpietro.red-bean.com ([45.79.25.59]:53334) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldPUC-0001qZ-VA for emacs-devel@gnu.org; Sun, 02 May 2021 23:43:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=red-bean.com; s=202005newsp; h=Content-Type:MIME-Version:Message-ID:Date: Reply-To:Subject:To:From:Sender:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=1PlyVPjHZM3D5QqrYNhbRKMPJAbWcoAioxgW6yy8B9g=; t=1620013385; x=1621222985; b=Ft5/kC+Epkib7/BgNSSwd/QfRGB2ZUiWiJ3xE4ImpK9vTBbXJvoRG0GlnYRNJ0BBYZqfZSbcTY ifU6hQI7RyzbyVNyuhK0pRLc+sgC9qg3sZgfVcO/zDapwqL5KWTorW4npLzN9v75p9T0rHHdDM50j 2cxn4Boct5Ezd6ELKyj0yCu2//xikZc1WW3xWRLbCu8L8YvNEHZTxy7w+wZVebx74ZHSFUc4ZZ2nO LzmLzX+CPJ6WxOwOlTsO/G9lLQugcJAjXrmhNbydf7sXKRBBAy0ST8QK+d82ysulessdeggFd1bLU UtZ+zdFu7+yk+cTsde6JduomIj5LSNbDheorQ==; Original-Received: from 99-112-125-163.lightspeed.cicril.sbcglobal.net ([99.112.125.163]:33014 helo=floss) by sanpietro.red-bean.com with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ldPU8-0004i3-CR for emacs-devel@gnu.org; Mon, 03 May 2021 03:43:04 +0000 Received-SPF: pass client-ip=45.79.25.59; envelope-from=kfogel@red-bean.com; helo=sanpietro.red-bean.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:268795 Archived-At: --=-=-= Content-Type: text/plain; format=flowed 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 --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=bookmark-menu-deletion-confirmation-patch.txt [[[ 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 () --=-=-=--