From c377d6674bb9f96f474d037dd5caad1157c2f7d4 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 9 Jun 2024 21:18:28 +0300 Subject: [PATCH] * lisp/buff-menu.el: Support a function value of Buffer-menu-group-by. (Buffer-menu-group-by): Add a choice for a function that returns names of all levels. (list-buffers--refresh): If Buffer-menu-group-by is a function, then use it directly. (cherry picked from commit 0aed6f5f0d9319dc616424e2c7df80580a04c739) --- lisp/buff-menu.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el index fa706a4e1a7..9bd15dde59d 100644 --- a/lisp/buff-menu.el +++ b/lisp/buff-menu.el @@ -97,6 +97,8 @@ as it is by default." (defcustom Buffer-menu-group-by nil "If non-nil, functions to call to divide buffer-menu buffers into groups. +When customized to a function, this function should return names +of all levels for each entry. When customized to a list of functions, then each function defines the group name at each nested level of multiple levels. Each function is called with one argument: a list of entries in the same @@ -109,13 +111,14 @@ The default options can group by a mode, and by a root directory of a project or just `default-directory'. If this is nil, buffers are not divided into groups." :type '(choice (const :tag "No grouping" nil) - (repeat :tag "Group by" + (function :tag "Custom function") + (repeat :tag "Use levels" (choice (const :tag "Group by project root or directory" Buffer-menu-group-by-root) (const :tag "Group by mode" Buffer-menu-group-by-mode) - (function :tag "Custom function")))) + (function :tag "Custom level function")))) :group 'Buffer-menu :version "30.1") @@ -854,9 +857,11 @@ See more at `Buffer-menu-filter-predicate'." (tabulated-list-groups tabulated-list-entries `(:path-function - ,(lambda (entry) - (list (mapcar (lambda (f) (funcall f entry)) - Buffer-menu-group-by))) + ,(if (functionp Buffer-menu-group-by) + Buffer-menu-group-by + (lambda (entry) + (list (mapcar (lambda (f) (funcall f entry)) + Buffer-menu-group-by)))) :sort-function ,Buffer-menu-group-sort-by)))) (tabulated-list-init-header)) -- 2.39.2