Subject: Re: bug#59935: 29.0.60; project-list-buffers is slow

From: Dmitry Gutov <[email-masked]>
Date: Sat, 10 Dec 2022 04:03:11 +0200

On 10/12/2022 03:49, Dmitry Gutov wrote:
> Curiously, though, it shows a different list of buffers. It also
> includes "hidden" buffers - diff-syntax, Echo Area, etc. We should look
> into that either way.

The combined fix for both can be this:

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 016dfdd5b4..835ab07e50 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1340,18 +1340,21 @@ project-list-buffers
  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)))
+  (let* ((pr (project-current t))
+         (fetcher (lambda ()
+                    (cl-delete-if-not
+                     (lambda (b)
+                       (or (buffer-file-name b)
+                           (string-match-p "\\`[^ ]" (buffer-name b))))
+                     (project-buffers pr)))))
      (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))))))))
+     (let ((buf (list-buffers-noselect arg (funcall fetcher))))
+       (with-current-buffer buf
+         (setq-local revert-buffer-function
+                     (lambda (&rest _ignored)
+                       (list-buffers--refresh (funcall fetcher))
+                       (tabulated-list-print t))))
+       buf))))

  (defcustom project-kill-buffer-conditions
    '(buffer-file-name    ; All file-visiting buffers are included.