1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

* lisp/buff-menu.el (Buffer-menu-group-sort-by): New defcustom.

(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'.
This commit is contained in:
Juri Linkov 2024-06-07 19:57:07 +03:00
parent 979365eef2
commit 9cd182dae8
2 changed files with 22 additions and 9 deletions

View 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

View 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."