From e3cc44f3439a36eaaed9566a4cd6af0a0e1001fc Mon Sep 17 00:00:00 2001 From: mikpom Date: Sun, 9 Jun 2024 05:32:57 +0300 Subject: [PATCH] Support Ibuffer in project-list-buffers * lisp/progmodes/project.el (project-buffers-viewer): New option. (project-list-buffers): Dispatch using it. (project-list-buffers-buffer-menu, project-list-buffers-ibuffer): New functions (bug#71290). (cherry picked from commit c0480e2211ff210ed037a2ac952070305769bafb) --- lisp/progmodes/project.el | 59 ++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index f3574774e8b..7efa5e2a380 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1546,6 +1546,16 @@ displayed." (interactive (list (project--read-project-buffer))) (display-buffer-other-frame buffer-or-name)) +(defcustom project-buffers-viewer 'project-list-buffers-buffer-menu + "Function to use in `project-list-buffers' to render the list. + +It should accept two arguments: PROJECT and FILES-ONLY. The latter +means that only file-visiting buffers should be displayed." + :group 'project + :version "30.1" + :type '(radio (function-item project-list-buffers-buffer-menu) + (function-item project-list-buffers-ibuffer))) + ;;;###autoload (defun project-list-buffers (&optional arg) "Display a list of project buffers. @@ -1555,27 +1565,31 @@ 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)) - (buffer-list-function - (lambda () - (seq-filter - (lambda (buffer) - (let ((name (buffer-name buffer)) - (file (buffer-file-name buffer))) - (and (or Buffer-menu-show-internal - (not (string= (substring name 0 1) " ")) - file) - (not (eq buffer (current-buffer))) - (or file (not Buffer-menu-files-only))))) - (project-buffers pr))))) + (let ((pr (project-current t))) + (funcall project-buffers-viewer pr arg))) + +(defun project-list-buffers-buffer-menu (project &optional files-only) + "Lists buffers of a project in Buffer-menu mode" + (let ((buffer-list-function + (lambda () + (seq-filter + (lambda (buffer) + (let ((name (buffer-name buffer)) + (file (buffer-file-name buffer))) + (and (or Buffer-menu-show-internal + (not (string= (substring name 0 1) " ")) + file) + (not (eq buffer (current-buffer))) + (or file (not Buffer-menu-files-only))))) + (project-buffers project))))) (display-buffer (if (version< emacs-version "29.0.50") (let ((buf (list-buffers-noselect - arg (with-current-buffer - (get-buffer-create "*Buffer List*") - (setq-local Buffer-menu-show-internal nil) - (let ((Buffer-menu-files-only arg)) - (funcall buffer-list-function)))))) + files-only (with-current-buffer + (get-buffer-create "*Buffer List*") + (setq-local Buffer-menu-show-internal nil) + (let ((Buffer-menu-files-only files-only)) + (funcall buffer-list-function)))))) (with-current-buffer buf (setq-local revert-buffer-function (lambda (&rest _ignored) @@ -1583,7 +1597,14 @@ ARG, show only buffers that are visiting files." (funcall buffer-list-function)) (tabulated-list-print t)))) buf) - (list-buffers-noselect arg buffer-list-function))))) + (list-buffers-noselect files-only buffer-list-function))))) + +(defun project-list-buffers-ibuffer (project &optional files-only) + "Lists buffers of a project with Ibuffer" + ;; TODO files-only + (ibuffer t (format "*Ibuffer-%s*" (project-name project)) + `((predicate . (member (current-buffer) + (project-buffers ',project)))))) (defcustom project-kill-buffer-conditions '(buffer-file-name ; All file-visiting buffers are included. -- 2.39.2