unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#71290: Options for viewing project buffers
@ 2024-05-31 12:28 mikpom
  2024-06-01 15:27 ` Dmitry Gutov
  0 siblings, 1 reply; 5+ messages in thread
From: mikpom @ 2024-05-31 12:28 UTC (permalink / raw)
  To: 71290

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?

Kind regards,
-Mikhail





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#71290: Options for viewing project buffers
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Gutov @ 2024-06-01 15:27 UTC (permalink / raw)
  To: mikpom, 71290

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).





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#71290: Options for viewing project buffers
  2024-06-01 15:27 ` Dmitry Gutov
@ 2024-06-01 16:07   ` mikpom
  2024-06-05  4:00     ` mikpom
  0 siblings, 1 reply; 5+ messages in thread
From: mikpom @ 2024-06-01 16:07 UTC (permalink / raw)
  To: Dmitry Gutov, 71290

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).






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#71290: Options for viewing project buffers
  2024-06-01 16:07   ` mikpom
@ 2024-06-05  4:00     ` mikpom
  2024-06-09  2:42       ` Dmitry Gutov
  0 siblings, 1 reply; 5+ messages in thread
From: mikpom @ 2024-06-05  4:00 UTC (permalink / raw)
  To: Dmitry Gutov, 71290

[-- 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#71290: Options for viewing project buffers
  2024-06-05  4:00     ` mikpom
@ 2024-06-09  2:42       ` Dmitry Gutov
  0 siblings, 0 replies; 5+ messages in thread
From: Dmitry Gutov @ 2024-06-09  2:42 UTC (permalink / raw)
  To: mikpom, 71290-done

Hi!

On 05/06/2024 07:00, mikpom wrote:
> 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.

This works, thank you. Pushed to master with expanded docstring and a 
minor fix (the ARG argument).

Also added the below patch.

This seems to work well, so marking this as resolved.

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index ab928a35e54..a16ff30395b 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1567,7 +1567,8 @@ project-list-buffers
      (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"
+  "List buffers for PROJECT in Buffer-menu mode.
+If FILES-ONLY is non-nil, only show the file-visiting buffers."
    (let ((buffer-list-function
           (lambda ()
             (seq-filter
@@ -1598,11 +1599,13 @@ project-list-buffers-buffer-menu
         (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
+  "List buffers for PROJECT using Ibuffer.
+If FILES-ONLY is non-nil, only show the file-visiting buffers."
    (ibuffer t (format "*Ibuffer-%s*" (project-name project))
-           `((predicate . (member (current-buffer)
-                                  (project-buffers ',project))))))
+           `((predicate . (and
+                           (or ,(not files-only) buffer-file-name)
+                           (member (current-buffer)
+                                   (project-buffers ',project)))))))

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






^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-06-09  2:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-06-09  2:42       ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).