@@ -286,12 +286,10 @@ end
286286--- Execute a command on each buffer of a group
287287--- @param group_name string
288288--- @param callback fun ( b : bufferline.Buffer )
289- local function command (group_name , callback )
289+ local function buf_exec (group_name , callback )
290290 local group = utils .find (function (list ) return list .name == group_name end , group_state .components_by_group )
291-
292291 if not group then return end
293-
294- utils .for_each (callback , group )
292+ utils .for_each (callback , group , function (item ) return type (item ) == " table" end )
295293end
296294
297295--- @generic T
@@ -344,10 +342,9 @@ function M.set_hidden(id, value)
344342 if group then group .hidden = value end
345343end
346344
347- --- @param priority number ?
348- --- @param name string ?
349- function M .toggle_hidden (priority , name )
350- local group = priority and group_by_priority (priority ) or group_by_name (name )
345+ --- @param opts { priority : number ?, name : string ?}
346+ function M .toggle_hidden (opts )
347+ local group = opts .priority and group_by_priority (opts .priority ) or group_by_name (opts .name )
351348 if group then group .hidden = not group .hidden end
352349end
353350
@@ -453,26 +450,50 @@ end
453450
454451function M .get_all () return group_state .user_groups end
455452
456- --- @alias group_actions " close" | " toggle"
453+ --- @param group_name string
454+ local function close_group (group_name )
455+ buf_exec (group_name , function (b ) api .nvim_buf_delete (b .id , { force = true }) end )
456+ if group_name == PINNED_NAME then vim .g [PINNED_KEY ] = " " end
457+ for buf , group_id in pairs (group_state .manual_groupings ) do
458+ if group_id == group_name then group_state .manual_groupings [buf ] = nil end
459+ end
460+ end
461+
462+ --- @param args string ?
463+ --- @param except string[] ?
464+ --- @return nil
465+ local function handle_close (args , except )
466+ if except then
467+ return utils .for_each (function (group )
468+ if not vim .tbl_contains (except , group .id ) then close_group (group .id ) end
469+ end , group_state .user_groups )
470+ end
471+
472+ if args then close_group (args ) end
473+ end
474+
475+ --- @alias bufferline.GroupCLIArgs { except : string[] ?}
476+
477+ local arguments = {
478+ except = function (value ) return vim .split (value , " ," ) end ,
479+ }
480+
457481--- Execute an action on a group of buffers
458- --- @param name string
482+ --- @alias group_actions " close" | " toggle"
483+ --- @param args string
459484--- @param action group_actions | fun ( b : bufferline.Buffer )
460- function M .action (name , action )
461- assert (name , " A name must be passed to execute a group action" )
462- if action == " close" then
463- command (name , function (b ) api .nvim_buf_delete (b .id , { force = true }) end )
464- ui .refresh ()
485+ function M .action (args , action )
486+ assert (args , " arguments must be passed to execute a group action" )
487+ local opts = utils .parse_args (args , arguments ) --- @type bufferline.GroupCLIArgs
465488
466- if name == PINNED_NAME then vim .g [PINNED_KEY ] = {} end
467- for buf , group_id in pairs (group_state .manual_groupings ) do
468- if group_id == name then group_state .manual_groupings [buf ] = nil end
469- end
489+ if action == " close" then
490+ handle_close (args , opts .except )
470491 elseif action == " toggle" then
471- M .toggle_hidden (nil , name )
472- ui .refresh ()
492+ M .toggle_hidden ({ name = args })
473493 elseif type (action ) == " function" then
474- command ( name , action )
494+ buf_exec ( args , action )
475495 end
496+ ui .refresh ()
476497end
477498
478499function M .toggle_pin ()
0 commit comments