all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: mikpom <mikpom@mikpom.ru>
To: Dmitry Gutov <dmitry@gutov.dev>, 71290@debbugs.gnu.org
Subject: bug#71290: Options for viewing project buffers
Date: Wed, 05 Jun 2024 11:00:53 +0700	[thread overview]
Message-ID: <45d69f9576ef593efd4d96fddc2bc03957ac45b7.camel@mikpom.ru> (raw)
In-Reply-To: <bf9e64b2e57e2c9cae5c5fe67513cb5875d24ee1.camel@mikpom.ru>

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

So I implemented (thank  for a suggestion in Emacs-ru chat) optional
Ibuffer viewer. Diff on project.el is attached. It works in my setting.

Best wishes, 
-Mikhail

On Sat, 2024-06-01 at 23:07 +0700, mikpom wrote:
> Thanks for pointing to ibuffer-project. It will deliver on my request
> even if suggested feature is never implemented.
> 
> On Sat, 2024-06-01 at 18:27 +0300, Dmitry Gutov wrote:
> > Hi!
> > 
> > On 31/05/2024 15:28, mikpom wrote:
> > > Greetings devs and emacs community.
> > > 
> > > I occasionally need to list buffers of a project and do so with
> > > the
> > > built-in command project-list-buffers from project.el. The
> > > problem
> > > is
> > > that this command utilizes Buffer-menu mode and does so in a
> > > hard-
> > > coded
> > > way. Personally I prefer IBuffer which is already heavily
> > > customized
> > > while I have zero knowledge of Buffer-menu mode.
> > > 
> > > I suggest to make an option whether project.el will list buffers
> > > with
> > > Ibuffer, Buffer-menu or even something else?
> > 
> > I'm happy to add a new option, but if you look at the definition of
> > project-list-buffers, it's not as trivial as
> > 
> >   - bind default-directory
> >   - call function
> > 
> > And ibuffer seems to require some effort as well. As a consequence,
> > the 
> > option is unlikely to be infinitely extensible, it would just list 
> > 'list-buffers' and 'ibuffers' as possible values. Maybe a "Custom 
> > function" alternative too, but the users who would want to use it
> > will 
> > need to put it some work as well.
> > 
> > Speaking of ibuffer in particular, here's a hint of setup required
> > to
> > use it for project buffers: 
> > https://github.com/emacsmirror/ibuffer-project/blob/master/ibuffer-project.el
> > 
> > Of course, a lot of this could be optional (improvements to make
> > the
> > UI 
> > better), so if someone wanted to contribute a minimal
> > implementation,
> > we 
> > could certainly use it (just please don't copy the code from the
> > above, 
> > it's not copyright-assigned).
> 


[-- Attachment #2: add_ibuffer_viewer.patch --]
[-- Type: text/x-patch, Size: 4137 bytes --]

diff --git a/project.el b/project.el
index b671a08..9021779 100644
--- a/project.el
+++ b/project.el
@@ -1354,6 +1354,11 @@ displayed."
   (interactive (list (project--read-project-buffer)))
   (display-buffer-other-frame buffer-or-name))
 
+(defcustom project-buffers-viewer 'project-list-buffers-buffer-menu "Function used to list buffers of a project."
+  :group 'project
+  :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.
@@ -1363,33 +1368,8 @@ 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 (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 (with-current-buffer
-                             (get-buffer-create "*Buffer List*")
-                           (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
-                            (funcall buffer-list-function))
-                           (tabulated-list-print t))))
-           buf)
-       (list-buffers-noselect arg buffer-list-function)))))
+  (let ((pr (project-current t)))
+    (funcall project-buffers-viewer pr arg)))
 
 (defcustom project-kill-buffer-conditions
   '(buffer-file-name    ; All file-visiting buffers are included.
@@ -1830,5 +1810,41 @@ to directory DIR."
     (let ((project-current-directory-override dir))
       (call-interactively command))))
 
+(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 (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*")
+                           (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
+                            (funcall buffer-list-function))
+                           (tabulated-list-print t))))
+           buf)
+       (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))))))
+
 (provide 'project)
 ;;; project.el ends here

  reply	other threads:[~2024-06-05  4:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31 12:28 bug#71290: Options for viewing project buffers mikpom
2024-06-01 15:27 ` Dmitry Gutov
2024-06-01 16:07   ` mikpom
2024-06-05  4:00     ` mikpom [this message]
2024-06-09  2:42       ` 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=45d69f9576ef593efd4d96fddc2bc03957ac45b7.camel@mikpom.ru \
    --to=mikpom@mikpom.ru \
    --cc=71290@debbugs.gnu.org \
    --cc=dmitry@gutov.dev \
    /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.