]> git.eshelyaron.com Git - emacs.git/commitdiff
Support Ibuffer in project-list-buffers
authormikpom <mikpom@mikpom.ru>
Sun, 9 Jun 2024 02:32:57 +0000 (05:32 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sun, 9 Jun 2024 09:52:35 +0000 (11:52 +0200)
* 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

index f3574774e8b1eaa7a51e0ebe394eeb65a46520c3..7efa5e2a38054abbffa5bcaf2e9a593a67754819 100644 (file)
@@ -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.