]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/buff-menu.el (Buffer-menu-group-sort-by): New defcustom.
authorJuri Linkov <juri@linkov.net>
Fri, 7 Jun 2024 16:57:07 +0000 (19:57 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 8 Jun 2024 13:00:49 +0000 (15:00 +0200)
(list-buffers--refresh): Use Buffer-menu-group-sort-by instead of the
hard-coded function (bug#70150).
(Buffer-menu-group-sort-alphabetically): New function as an option for
'Buffer-menu-group-sort-by'.
(list-buffers-noselect): Remove setting outline-minor-mode-use-buttons
to 'in-margins' that it not required for this feature to work correctly.

* lisp/emacs-lisp/tabulated-list.el (tabulated-list-groups-sort):
Add optional argument 'level'.

(cherry picked from commit 9cd182dae8822e810b73b2c1c1c41955096bb2de)

lisp/buff-menu.el
lisp/emacs-lisp/tabulated-list.el

index c35fa42934ce6216c8f7d7eb3e0addf6ab2feb32..fa706a4e1a725cc2f163c9040a14765b3b0cb099 100644 (file)
@@ -119,6 +119,19 @@ If this is nil, buffers are not divided into groups."
   :group 'Buffer-menu
   :version "30.1")
 
+(defcustom Buffer-menu-group-sort-by nil
+  "If non-nil, function to sort buffer-menu groups by name.
+Each function is called with two arguments: an alist of groups
+where an alist key is a group name and also the level as a number,
+and should return the same alist where groups are sorted.
+If this is nil, group names are unsorted."
+  :type '(choice (const :tag "No group sorting" nil)
+                 (const :tag "Sort groups alphabetically"
+                        Buffer-menu-group-sort-alphabetically)
+                 (function :tag "Custom 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
@@ -759,8 +772,7 @@ See more at `Buffer-menu-filter-predicate'."
       (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-highlight t)
         (outline-minor-mode 1)))
     buffer))
 
@@ -845,10 +857,7 @@ See more at `Buffer-menu-filter-predicate'."
              ,(lambda (entry)
                 (list (mapcar (lambda (f) (funcall f entry))
                               Buffer-menu-group-by)))
-             :sort-function
-             ,(lambda (groups)
-                ;; Sort groups by name
-                (sort groups :key #'car :in-place t))))))
+             :sort-function ,Buffer-menu-group-sort-by))))
   (tabulated-list-init-header))
 
 (defun tabulated-list-entry-size-> (entry1 entry2)
@@ -881,4 +890,7 @@ See more at `Buffer-menu-filter-predicate'."
         (project-root project)
       default-directory)))
 
+(defun Buffer-menu-group-sort-alphabetically (groups _level)
+  (sort groups :in-place t :key #'car))
+
 ;;; buff-menu.el ends here
index a0a58bf8b427bfb6d6625645b33d62b2076d2bd9..30397137efb1128d59a53f0ef41c14d9ae1a09d1 100644 (file)
@@ -929,14 +929,15 @@ where every string is an outline heading at increasing level of deepness."
           (cl-pushnew entry (gethash path hash))))
       (trie-get tree nil))))
 
-(defun tabulated-list-groups-sort (tree sort-function)
+(defun tabulated-list-groups-sort (tree sort-function &optional level)
   "Sort TREE using the sort function SORT-FUN."
+  (unless level (setq level 1))
   (mapcar (lambda (elt)
             (if (vectorp (cdr elt))
                 elt
               (cons (car elt) (tabulated-list-groups-sort
-                               (cdr elt) sort-function))))
-          (funcall sort-function tree)))
+                               (cdr elt) sort-function (1+ level)))))
+          (funcall sort-function tree level)))
 
 (defun tabulated-list-groups-flatten (tree)
   "Flatten multi-level TREE to single level."