Subject: bug#59153: List project buffers

From: Juri Linkov <[email-masked]>
Date: Tue, 15 Nov 2022 10:36:14 +0200

> But I would imagine that users of Emacs 28 and earlier would rather enjoy
> the new command (with a 'g' caveat) than have it disabled.
>
> As a safety measure, in older Emacs you could also set
> 'revert-buffer-function' locally to something displaying an error.
>
> I don't remember using 'g' in ibuffer or list-buffers much anyway. But that
> depends on one's habits.

Maybe something like this that supports 'g' in older versions:

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index ed26872ae77..63510e90502 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -712,6 +712,7 @@ project-prefix-map
     (define-key map "G" 'project-or-external-find-regexp)
     (define-key map "r" 'project-query-replace-regexp)
     (define-key map "x" 'project-execute-extended-command)
+    (define-key map "\C-b" 'project-list-buffers)
     map)
   "Keymap for project commands.")
 
@@ -1222,6 +1223,28 @@ project-display-buffer-other-frame
   (interactive (list (project--read-project-buffer)))
   (display-buffer-other-frame buffer-or-name))
 
+;;;###autoload
+(defun project-list-buffers (&optional arg)
+  "Display a list of project buffers.
+The list is displayed in a buffer named \"*Buffer List*\".
+
+By default, all project buffers are listed except those whose names
+start with a space (which are for internal use).  With prefix argument
+ARG, show only buffers that are visiting files."
+  (interactive "P")
+  (let ((pr (project-current t)))
+    (display-buffer
+     (if (version< emacs-version "29.0.50")
+         (let ((buf (list-buffers-noselect arg (project-buffers pr))))
+           (with-current-buffer buf
+             (setq-local revert-buffer-function
+                         (lambda (&rest _ignored)
+                           (list-buffers--refresh (project-buffers pr))
+                           (tabulated-list-print t))))
+           buf)
+       (list-buffers-noselect
+        arg nil (lambda (buf) (memq buf (project-buffers pr))))))))
+
 (defcustom project-kill-buffer-conditions
   '(buffer-file-name    ; All file-visiting buffers are included.
     ;; Most of temp and logging buffers (aside from hidden ones):