unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* outline-minor-mode for tabulated-list-mode
@ 2024-02-18 17:05 Juri Linkov
  2024-02-18 17:19 ` T.V Raman
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Juri Linkov @ 2024-02-18 17:05 UTC (permalink / raw)
  To: emacs-devel

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

Would it be nice to support outline-minor-mode in all modes
that are based on tabulated-list-mode such as list-packages,
list-processes, list-buffers, etc.

Here is how this looks for the list of buffers grouped by mode:


[-- Attachment #2: outline-buffers.png --]
[-- Type: image/png, Size: 23578 bytes --]

[-- Attachment #3: Type: text/plain, Size: 670 bytes --]

The customization that groups by mode is simply:

  (setq Buffer-menu-group-by
        (lambda (b) (concat "* " (aref (cadr b) 5))))

Also note that sorting (e.g. by Size as above) sorts buffers
inside each group separately.

Another example is grouping by project name/root:

  (setq Buffer-menu-group-by
        (lambda (b)
          (with-current-buffer (car b)
            (if-let ((project (project-current)))
                (concat "* " (project-name project)) ;; or project-root
              "* Unorganized"))))

There are infinitely many ways to group buffers, so no predefined
functions are included.

Here is the minimal patch that implements this feature:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: outline-buffers.patch --]
[-- Type: text/x-diff, Size: 4794 bytes --]

diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el
index e13c3b56b4e..9123d9868f9 100644
--- a/lisp/buff-menu.el
+++ b/lisp/buff-menu.el
@@ -95,6 +95,12 @@ Buffer-menu-use-frame-buffer-list
   :group 'Buffer-menu
   :version "22.1")
 
+(defcustom Buffer-menu-group-by nil
+  "If non-nil, buffers are grouped by function."
+  :type 'function
+  :group 'Buffer-menu
+  :version "30.1")
+
 (defvar-local Buffer-menu-files-only nil
   "Non-nil if the current Buffer Menu lists only file buffers.
 This is set by the prefix argument to `buffer-menu' and related
@@ -674,7 +680,12 @@ list-buffers-noselect
       (setq Buffer-menu-buffer-list buffer-list)
       (setq Buffer-menu-filter-predicate filter-predicate)
       (list-buffers--refresh buffer-list old-buffer)
-      (tabulated-list-print))
+      (tabulated-list-print)
+      (when tabulated-list-groups
+        (setq-local outline-minor-mode-cycle t
+                    outline-minor-mode-highlight t
+                    outline-minor-mode-use-buttons 'in-margins)
+        (outline-minor-mode 1)))
     buffer))
 
 (defun Buffer-menu-mouse-select (event)
@@ -750,7 +761,11 @@ list-buffers--refresh
 		  `("Mode" ,Buffer-menu-mode-width t)
 		  '("File" 1 t)))
     (setq tabulated-list-use-header-line Buffer-menu-use-header-line)
-    (setq tabulated-list-entries (nreverse entries)))
+    (setq tabulated-list-entries (nreverse entries))
+    (when Buffer-menu-group-by
+      (setq tabulated-list-groups
+            (seq-group-by Buffer-menu-group-by
+                          tabulated-list-entries))))
   (tabulated-list-init-header))
 
 (defun tabulated-list-entry-size-> (entry1 entry2)
diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el
index 9884a2fc24b..5b91670f8e9 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -139,6 +139,10 @@ tabulated-list-entries
 arguments and must return a list of the above form.")
 (put 'tabulated-list-entries 'permanent-local t)
 
+(defvar-local tabulated-list-groups nil
+  "Groups displayed in the current Tabulated List buffer.")
+(put 'tabulated-list-groups 'permanent-local t)
+
 (defvar-local tabulated-list-padding 0
   "Number of characters preceding each Tabulated List mode entry.
 By default, lines are padded with spaces, but you can use the
@@ -437,6 +441,9 @@ tabulated-list-print
 `tabulated-list-put-tag').  Don't use this immediately after
 changing `tabulated-list-sort-key'."
   (let ((inhibit-read-only t)
+        (groups (if (functionp tabulated-list-groups)
+		    (funcall tabulated-list-groups)
+		  tabulated-list-groups))
 	(entries (if (functionp tabulated-list-entries)
 		     (funcall tabulated-list-entries)
 		   tabulated-list-entries))
@@ -447,7 +454,14 @@ tabulated-list-print
 	 (setq saved-col (current-column)))
     ;; Sort the entries, if necessary.
     (when sorter
-      (setq entries (sort entries sorter)))
+      (if groups
+          (setq groups
+                (mapcar (lambda (group)
+                          (cons (car group) (sort (cdr group) sorter)))
+                        groups))
+        (setq entries (sort entries sorter))))
+    (unless (functionp tabulated-list-groups)
+      (setq tabulated-list-groups groups))
     (unless (functionp tabulated-list-entries)
       (setq tabulated-list-entries entries))
     ;; Without a sorter, we have no way to just update.
@@ -459,6 +473,21 @@ tabulated-list-print
       (unless tabulated-list-use-header-line
         (tabulated-list-print-fake-header)))
     ;; Finally, print the resulting list.
+    (if groups
+        (dolist (group groups)
+          (insert (car group) ?\n)
+          (let ((saved-pt-new (tabulated-list-print-entries (cdr group) sorter update entry-id)))
+            (when saved-pt-new (setq saved-pt saved-pt-new))))
+      (setq saved-pt (tabulated-list-print-entries entries sorter update entry-id)))
+    (set-buffer-modified-p nil)
+    ;; If REMEMBER-POS was specified, move to the "old" location.
+    (if saved-pt
+	(progn (goto-char saved-pt)
+	       (move-to-column saved-col))
+      (goto-char (point-min)))))
+
+(defun tabulated-list-print-entries (entries sorter update entry-id)
+  (let (saved-pt)
     (while entries
       (let* ((elt (car entries))
              (tabulated-list--near-rows
@@ -497,12 +526,7 @@ tabulated-list-print
       (setq entries (cdr entries)))
     (when update
       (delete-region (point) (point-max)))
-    (set-buffer-modified-p nil)
-    ;; If REMEMBER-POS was specified, move to the "old" location.
-    (if saved-pt
-	(progn (goto-char saved-pt)
-	       (move-to-column saved-col))
-      (goto-char (point-min)))))
+    saved-pt))
 
 (defun tabulated-list-print-entry (id cols)
   "Insert a Tabulated List entry at point.

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

* Re: outline-minor-mode for tabulated-list-mode
  2024-02-18 17:05 outline-minor-mode for tabulated-list-mode Juri Linkov
@ 2024-02-18 17:19 ` T.V Raman
  2024-02-18 17:20 ` Eli Zaretskii
  2024-02-23 15:46 ` Spencer Baugh
  2 siblings, 0 replies; 7+ messages in thread
From: T.V Raman @ 2024-02-18 17:19 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

Nice!


-- 



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

* Re: outline-minor-mode for tabulated-list-mode
  2024-02-18 17:05 outline-minor-mode for tabulated-list-mode Juri Linkov
  2024-02-18 17:19 ` T.V Raman
@ 2024-02-18 17:20 ` Eli Zaretskii
  2024-02-23 15:46 ` Spencer Baugh
  2 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2024-02-18 17:20 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

> From: Juri Linkov <juri@linkov.net>
> Date: Sun, 18 Feb 2024 19:05:31 +0200
> 
> +(defcustom Buffer-menu-group-by nil
> +  "If non-nil, buffers are grouped by function."
> +  :type 'function
> +  :group 'Buffer-menu
> +  :version "30.1")

Please consider letting users choose a symbol, not a function.  Each
symbol can be mapped to a function, but having a user option whose
values are functions makes it harder for users to customize the
option.

Thanks.



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

* Re: outline-minor-mode for tabulated-list-mode
  2024-02-18 17:05 outline-minor-mode for tabulated-list-mode Juri Linkov
  2024-02-18 17:19 ` T.V Raman
  2024-02-18 17:20 ` Eli Zaretskii
@ 2024-02-23 15:46 ` Spencer Baugh
  2024-02-23 18:00   ` Thomas Hisch
  2 siblings, 1 reply; 7+ messages in thread
From: Spencer Baugh @ 2024-02-23 15:46 UTC (permalink / raw)
  To: emacs-devel

Juri Linkov <juri@linkov.net> writes:
> Would it be nice to support outline-minor-mode in all modes
> that are based on tabulated-list-mode such as list-packages,
> list-processes, list-buffers, etc.
>
> Here is how this looks for the list of buffers grouped by mode:

This is very timely, because I just recently have been working on a
list-projects command using tabulated-list-mode, and I've wanted the
ability to group together related projects.  This seems like a perfect
way to do that!




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

* Re: outline-minor-mode for tabulated-list-mode
  2024-02-23 15:46 ` Spencer Baugh
@ 2024-02-23 18:00   ` Thomas Hisch
  2024-02-25 17:31     ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Hisch @ 2024-02-23 18:00 UTC (permalink / raw)
  To: Spencer Baugh; +Cc: emacs-devel

On Fri, Feb 23, 2024 at 6:17 PM Spencer Baugh <sbaugh@janestreet.com> wrote:
>
> Juri Linkov <juri@linkov.net> writes:
> > Would it be nice to support outline-minor-mode in all modes
> > that are based on tabulated-list-mode such as list-packages,
> > list-processes, list-buffers, etc.
> >
> > Here is how this looks for the list of buffers grouped by mode:
>
> This is very timely, because I just recently have been working on a
> list-projects command using tabulated-list-mode, and I've wanted the
> ability to group together related projects.

Me too. I also wanted to add groups/sections to tabulated-list-mode.
That's why I've created a package called dashboard-table.el [0] for that.
It would be nice if this were supported by tabulated-list-mode OOTB.

[0] https://github.com/thisch/dashboard-table.el



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

* Re: outline-minor-mode for tabulated-list-mode
  2024-02-23 18:00   ` Thomas Hisch
@ 2024-02-25 17:31     ` Juri Linkov
  2024-02-25 21:40       ` Thomas Hisch
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2024-02-25 17:31 UTC (permalink / raw)
  To: Thomas Hisch; +Cc: Spencer Baugh, emacs-devel

>> This is very timely, because I just recently have been working on a
>> list-projects command using tabulated-list-mode, and I've wanted the
>> ability to group together related projects.
>
> Me too. I also wanted to add groups/sections to tabulated-list-mode.
> That's why I've created a package called dashboard-table.el [0] for that.
> It would be nice if this were supported by tabulated-list-mode OOTB.
>
> [0] https://github.com/thisch/dashboard-table.el

Thanks for the reference.  I wonder does your implementation allow
sorting columns?  I guess not.  Since this doesn't seem possible
without changes in tabulated-list-mode.  So the proposed changes
for tabulated-list-mode split rows to groups where it's possible
to sort inside each group independently from other groups.



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

* Re: outline-minor-mode for tabulated-list-mode
  2024-02-25 17:31     ` Juri Linkov
@ 2024-02-25 21:40       ` Thomas Hisch
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Hisch @ 2024-02-25 21:40 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Spencer Baugh, emacs-devel

On Sun, Feb 25, 2024 at 6:55 PM Juri Linkov <juri@linkov.net> wrote:
> > Me too. I also wanted to add groups/sections to tabulated-list-mode.
> > That's why I've created a package called dashboard-table.el [0] for that.
> > It would be nice if this were supported by tabulated-list-mode OOTB.
> >
> > [0] https://github.com/thisch/dashboard-table.el
>
> Thanks for the reference.  I wonder does your implementation allow
> sorting columns?  I guess not.  Since this doesn't seem possible
> without changes in tabulated-list-mode.  So the proposed changes
> for tabulated-list-mode split rows to groups where it's possible
> to sort inside each group independently from other groups.

You guess right. It doesn't support sorting columns, at least I don't remember
adding explicit support for it.

> So the proposed changes
> for tabulated-list-mode split rows to groups where it's possible
> to sort inside each group independently from other groups.

Let me test your tabulated-list-mode changes in the next few days and see if
they allow me to get rid of my pkg.

Best regards
Thomas



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

end of thread, other threads:[~2024-02-25 21:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-18 17:05 outline-minor-mode for tabulated-list-mode Juri Linkov
2024-02-18 17:19 ` T.V Raman
2024-02-18 17:20 ` Eli Zaretskii
2024-02-23 15:46 ` Spencer Baugh
2024-02-23 18:00   ` Thomas Hisch
2024-02-25 17:31     ` Juri Linkov
2024-02-25 21:40       ` Thomas Hisch

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