Subject: Re: bug#52148: 29.0.50; [PATCH] Make `project-kill-buffers' display list of buffers to kill

From: Matthias Meulien <[email-masked]>
Date: Sun, 28 Nov 2021 09:42:09 +0100

Eli Zaretskii <[email-masked]> writes:

> Thanks.  A couple of minor comments below.

Updated patch:

>From fbb8829f93f7e898b3d243e9ed80101f0f0e1b8b Mon Sep 17 00:00:00 2001
From: Matthias Meulien <[email-masked]>
Date: Sat, 27 Nov 2021 22:43:20 +0100
Subject: [PATCH] project-kill-buffers can display list of buffers to kill

* lisp/progmodes/project.el
(project-kill-buffers-display-buffer-list): Option to toggle
temporarily display of the list of buffers to kill when calling
project-kill-buffers
(project-kill-buffers): Handle
project-kill-buffers-display-buffer-list option
---
 etc/NEWS                  |  4 ++++
 lisp/progmodes/project.el | 37 +++++++++++++++++++++++++++++++++----
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 87a7a43a5e..2bc1e0046a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -427,6 +427,10 @@ it with new 'term-{faint,italic,slow-blink,fast-blink}' faces.
 *** 'project-find-file' and 'project-or-external-find-file' now accept
 a prefix argument which is interpreted to mean "include all files".
 
+*** 'project-kill-buffers' can display the list of buffers to kill.
+Customize the user option 'project-kill-buffers-display-buffer-list'
+to enable the display of the buffer list.
+
 +++
 *** New command 'xref-go-forward'.
 It is bound to 'C-M-,' and jumps to the location where 'xref-go-back'
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index ed076a683d..14df03570d 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1210,6 +1210,15 @@ project-kill-buffer-conditions
   :group 'project
   :package-version '(project . "0.6.0"))
 
+(defcustom project-kill-buffers-display-buffer-list nil
+  "Non-nil to display list of buffers to kill before killing project buffers.
+Used by `project-kill-buffers'."
+  :type 'boolean
+  :version "29.1"
+  :group 'project
+  :package-version '(project . "0.8.1")
+  :safe #'booleanp)
+
 (defun project--buffer-list (pr)
   "Return the list of all buffers in project PR."
   (let ((conn (file-remote-p (project-root pr)))
@@ -1276,14 +1285,34 @@ project-kill-buffers
 interactively."
   (interactive)
   (let* ((pr (project-current t))
-         (bufs (project--buffers-to-kill pr)))
+         (bufs (project--buffers-to-kill pr))
+         (query-user (lambda ()
+                       (yes-or-no-p
+                        (format "Kill %d buffers in %s? "
+                                (length bufs)
+                                (project-root pr))))))
     (cond (no-confirm
            (mapc #'kill-buffer bufs))
           ((null bufs)
            (message "No buffers to kill"))
-          ((yes-or-no-p (format "Kill %d buffers in %s? "
-                                (length bufs)
-                                (project-root pr)))
+          (project-kill-buffers-display-buffer-list
+           (with-current-buffer-window
+               (get-buffer-create "*Buffer List*")
+               `(display-buffer--maybe-at-bottom
+                 (dedicated . t)
+                 (window-height . (fit-window-to-buffer))
+                 (preserve-size . (nil . t))
+                 (body-function
+                  . ,#'(lambda (_window)
+                         (list-buffers-noselect nil bufs))))
+               #'(lambda (window _value)
+                   (with-selected-window window
+                     (unwind-protect
+                         (funcall query-user)
+                       (when (window-live-p window)
+                         (quit-restore-window window 'kill))))))
+           (mapc #'kill-buffer bufs))
+          ((funcall query-user)
            (mapc #'kill-buffer bufs)))))
 
 
-- 
2.30.2

-- 
Matthias