all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 59935@debbugs.gnu.org
Subject: bug#59935: 29.0.60; project-list-buffers is slow
Date: Sun, 11 Dec 2022 19:07:27 +0200	[thread overview]
Message-ID: <86bko9na29.fsf@mail.linkov.net> (raw)
In-Reply-To: <4a78ffcc-15fb-27ac-48b9-82fe84c596aa@yandex.ru> (Dmitry Gutov's message of "Sat, 10 Dec 2022 21:22:20 +0200")

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

> Do you have the time to finish the fix yourself? It was your feature, after
> all.

Here is a complete patch tested for all possible cases:
- emacs 28/29
- with/without file arg
- with/without reverting


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Buffer-menu-buffer-list-function.patch --]
[-- Type: text/x-diff, Size: 5560 bytes --]

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 38d4fdad5fc..64af86558e4 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1321,18 +1321,31 @@ 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))
+         (buffer-list-function
+          (lambda ()
+            (seq-filter
+             (lambda (buffer)
+               (let ((name (buffer-name buffer))
+                     (file (buffer-file-name buffer)))
+                 (and (or (not (string= (substring name 0 1) " "))
+                          file)
+                      (not (eq buffer (current-buffer)))
+                      (or file (not Buffer-menu-files-only)))))
+             (project-buffers pr)))))
     (display-buffer
      (if (version< emacs-version "29.0.50")
-         (let ((buf (list-buffers-noselect arg (project-buffers pr))))
+         (let ((buf (list-buffers-noselect
+                     arg (let ((Buffer-menu-files-only arg))
+                           (funcall buffer-list-function)))))
            (with-current-buffer buf
              (setq-local revert-buffer-function
                          (lambda (&rest _ignored)
-                           (list-buffers--refresh (project-buffers pr))
+                           (list-buffers--refresh
+                            (funcall buffer-list-function))
                            (tabulated-list-print t))))
            buf)
-       (list-buffers-noselect
-        arg nil (lambda (buf) (memq buf (project-buffers pr))))))))
+       (list-buffers-noselect arg buffer-list-function)))))
 
 (defcustom project-kill-buffer-conditions
   '(buffer-file-name    ; All file-visiting buffers are included.
diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el
index 588fe599a46..cabf7cb8fc4 100644
--- a/lisp/buff-menu.el
+++ b/lisp/buff-menu.el
@@ -100,12 +100,8 @@ Buffer-menu-files-only
 This is set by the prefix argument to `buffer-menu' and related
 commands.")
 
-(defvar-local Buffer-menu-filter-predicate nil
-  "Function to filter out buffers in the buffer list.
-Buffers that don't satisfy the predicate will be skipped.
-The value should be a function of one argument; it will be
-called with the buffer.  If this function returns non-nil,
-then the buffer will be displayed in the buffer list.")
+(defvar-local Buffer-menu-buffer-list-function nil
+  "Function to return buffers for the buffer list.")
 
 (defvar-keymap Buffer-menu-mode-map
   :doc "Local keymap for `Buffer-menu-mode' buffers."
@@ -623,23 +619,23 @@ Buffer-menu-view-other-window
 ;;; Functions for populating the Buffer Menu.
 
 ;;;###autoload
-(defun list-buffers-noselect (&optional files-only buffer-list filter-predicate)
+(defun list-buffers-noselect (&optional files-only buffer-list)
   "Create and return a Buffer Menu buffer.
 This is called by `buffer-menu' and others as a subroutine.
 
 If FILES-ONLY is non-nil, show only file-visiting buffers.
-If BUFFER-LIST is non-nil, it should be a list of buffers; it
-means list those buffers and no others.
-If FILTER-PREDICATE is non-nil, it should be a function
-that filters out buffers from the list of buffers.
-See more at `Buffer-menu-filter-predicate'."
+If BUFFER-LIST is non-nil, it should be either a list of buffers
+or a function that returns a list of buffers; it means
+list those buffers and no others.
+See more at `Buffer-menu-buffer-list-function'."
   (let ((old-buffer (current-buffer))
 	(buffer (get-buffer-create "*Buffer List*")))
     (with-current-buffer buffer
       (Buffer-menu-mode)
       (setq Buffer-menu-files-only
 	    (and files-only (>= (prefix-numeric-value files-only) 0)))
-      (setq Buffer-menu-filter-predicate filter-predicate)
+      (when (functionp buffer-list)
+        (setq Buffer-menu-buffer-list-function buffer-list))
       (list-buffers--refresh buffer-list old-buffer)
       (tabulated-list-print))
     buffer))
@@ -661,13 +657,17 @@ list-buffers--refresh
         (marked-buffers (Buffer-menu-marked-buffers))
         (buffer-menu-buffer (current-buffer))
 	(show-non-file (not Buffer-menu-files-only))
-	(filter-predicate (and (functionp Buffer-menu-filter-predicate)
-			       Buffer-menu-filter-predicate))
 	entries name-width)
     ;; Collect info for each buffer we're interested in.
-    (dolist (buffer (or buffer-list
-			(buffer-list (if Buffer-menu-use-frame-buffer-list
-					 (selected-frame)))))
+    (dolist (buffer (cond
+                     ((functionp buffer-list)
+                      (funcall buffer-list))
+                     (buffer-list)
+                     (Buffer-menu-buffer-list-function
+                      (funcall Buffer-menu-buffer-list-function))
+                     (t (buffer-list
+                         (if Buffer-menu-use-frame-buffer-list
+                             (selected-frame))))))
       (with-current-buffer buffer
 	(let* ((name (buffer-name))
 	       (file buffer-file-name))
@@ -676,9 +676,7 @@ list-buffers--refresh
 			 (and (or (not (string= (substring name 0 1) " "))
                                   file)
 			      (not (eq buffer buffer-menu-buffer))
-			      (or file show-non-file)
-			      (or (not filter-predicate)
-				  (funcall filter-predicate buffer)))))
+			      (or file show-non-file))))
 	    (push (list buffer
 			(vector (cond
                                  ((eq buffer old-buffer) ".")

  reply	other threads:[~2022-12-11 17:07 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-10  1:49 bug#59935: 29.0.60; project-list-buffers is slow Dmitry Gutov
2022-12-10  2:03 ` Dmitry Gutov
2022-12-10  8:11 ` Eli Zaretskii
2022-12-10 10:47   ` Dmitry Gutov
2022-12-10 11:12     ` Eli Zaretskii
2022-12-10 11:37       ` Dmitry Gutov
2022-12-10 14:33         ` Eli Zaretskii
2022-12-10 19:19           ` Dmitry Gutov
2022-12-10 19:42             ` Eli Zaretskii
2022-12-10 19:53               ` Dmitry Gutov
2022-12-10 20:11                 ` Eli Zaretskii
2022-12-10 20:23                   ` Dmitry Gutov
2022-12-11  6:19                     ` Eli Zaretskii
2022-12-11 10:23                       ` Dmitry Gutov
2022-12-11 10:54                         ` Eli Zaretskii
2022-12-11 16:32                           ` Dmitry Gutov
2022-12-12 10:36                   ` Jean Louis
2022-12-12 17:12                     ` Juri Linkov
2022-12-13  3:10                       ` Jean Louis
2022-12-12 19:58                     ` Dmitry Gutov
2022-12-13  3:10                       ` Jean Louis
2022-12-13 15:29                         ` Dmitry Gutov
2022-12-13 19:30                           ` Jean Louis
2022-12-13 20:31                             ` Dmitry Gutov
2022-12-15 14:58                               ` Jean Louis
2022-12-15 15:12                                 ` Dmitry Gutov
2022-12-10 17:45 ` Juri Linkov
2022-12-10 19:22   ` Dmitry Gutov
2022-12-11 17:07     ` Juri Linkov [this message]
2022-12-11 17:49       ` Eli Zaretskii
2022-12-11 17:56         ` Juri Linkov
2022-12-11 18:08           ` Eli Zaretskii
2022-12-11 18:13             ` Dmitry Gutov
2022-12-11 18:12         ` Dmitry Gutov
2022-12-11 18:17           ` Eli Zaretskii
2022-12-11 18:35             ` Dmitry Gutov
2022-12-11 19:00               ` Eli Zaretskii
2022-12-11 19:41                 ` Dmitry Gutov
2022-12-11 20:42                   ` Eli Zaretskii
2022-12-12 17:16                     ` Juri Linkov
2022-12-12 17:27                       ` Eli Zaretskii
2022-12-12 17:51                         ` Juri Linkov
2022-12-12 18:10                           ` Eli Zaretskii
2022-12-12 18:14                             ` Juri Linkov
2022-12-12 18:22                               ` Eli Zaretskii
2022-12-13 17:49                                 ` Juri Linkov
2022-12-11 18:37       ` Dmitry Gutov
2022-12-13 17:49         ` Juri Linkov
2022-12-13 18:51           ` Dmitry Gutov

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86bko9na29.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=59935@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.