Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groups #938

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions doc/bufferline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ The available configuration are:
right_mouse_command = "bdelete! %d", -- can be a string | function | false, see "Mouse actions"
left_mouse_command = "buffer %d", -- can be a string | function, | false see "Mouse actions"
middle_mouse_command = nil, -- can be a string | function, | false see "Mouse actions"
indicator = {
indicator = { -- marker for the current active tab
icon = '▎', -- this should be omitted if indicator style is not 'icon'
style = 'icon' | 'underline' | 'none',
},
Expand Down Expand Up @@ -157,7 +157,7 @@ The available configuration are:
-- can also be a table containing 2 custom separators
-- [focused and unfocused]. eg: { '|', '|' }
separator_style = "slant" | "slope" | "thick" | "thin" | { 'any', 'any' },
enforce_regular_tabs = false | true,
enforce_regular_tabs = false | true, -- Whether to enforce all tabs having uniform width or variable width
always_show_bufferline = true | false,
auto_toggle_bufferline = true | false,
hover = {
Expand Down Expand Up @@ -353,11 +353,17 @@ In order to group buffers specify a list of groups in your config e.g.
groups = {
options = {
toggle_hidden_on_enter = true -- when you re-enter a hidden group this options re-opens that group so the buffer is visible
-- position separator at the end/start/both sides for buffers
separator_position = "both", -- start | end | both
separator_style = "thin" -- thin | thick | {leftIcon,rightIcon}
},
items = {
{
name = "Tests", -- Mandatory
highlight = {underline = true, sp = "blue"}, -- Optional
-- Additional Highlights can be configured by setting the hl groups
-- BufferLineTestLabel, BufferLineTest, BufferLineTestSelected, BufferLineTestVisible

priority = 2, -- determines where it will appear relative to other groups (Optional)
icon = "", -- Optional
matcher = function(buf) -- Mandatory
Expand Down Expand Up @@ -595,7 +601,7 @@ for left or right aligned sidebar windows such as `NvimTree`, `NERDTree` or
{
filetype = "NvimTree",
text = "File Explorer",
highlight = "Directory",
highlight = "Directory", -- Highlight group applied for the Explorer
separator = true -- use a "true" to enable the default, or set your own character
}
}
Expand Down
36 changes: 36 additions & 0 deletions doc/tags
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole file should not be committed I believe this is something generated locally IIRC

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
NOT bufferline.txt /*NOT*
NOTE: bufferline.txt /*NOTE:*
bufferline bufferline.txt /*bufferline*
bufferline-colorscheme-development bufferline.txt /*bufferline-colorscheme-development*
bufferline-commands bufferline.txt /*bufferline-commands*
bufferline-configuration bufferline.txt /*bufferline-configuration*
bufferline-contents bufferline.txt /*bufferline-contents*
bufferline-custom-areas bufferline.txt /*bufferline-custom-areas*
bufferline-diagnostics bufferline.txt /*bufferline-diagnostics*
bufferline-filtering bufferline.txt /*bufferline-filtering*
bufferline-functions bufferline.txt /*bufferline-functions*
bufferline-group-commands bufferline.txt /*bufferline-group-commands*
bufferline-groups bufferline.txt /*bufferline-groups*
bufferline-highlights bufferline.txt /*bufferline-highlights*
bufferline-hover-events bufferline.txt /*bufferline-hover-events*
bufferline-introduction bufferline.txt /*bufferline-introduction*
bufferline-issues bufferline.txt /*bufferline-issues*
bufferline-mappings bufferline.txt /*bufferline-mappings*
bufferline-mouse-actions bufferline.txt /*bufferline-mouse-actions*
bufferline-numbers bufferline.txt /*bufferline-numbers*
bufferline-offset bufferline.txt /*bufferline-offset*
bufferline-ordering-groups bufferline.txt /*bufferline-ordering-groups*
bufferline-pick bufferline.txt /*bufferline-pick*
bufferline-pinning bufferline.txt /*bufferline-pinning*
bufferline-regular-tabs bufferline.txt /*bufferline-regular-tabs*
bufferline-sorting bufferline.txt /*bufferline-sorting*
bufferline-style-presets bufferline.txt /*bufferline-style-presets*
bufferline-styling bufferline.txt /*bufferline-styling*
bufferline-tabpages bufferline.txt /*bufferline-tabpages*
bufferline-usage bufferline.txt /*bufferline-usage*
bufferline-working-with-elements bufferline.txt /*bufferline-working-with-elements*
bufferline.nvim bufferline.txt /*bufferline.nvim*
optional bufferline.txt /*optional*
strongly bufferline.txt /*strongly*
vertical bufferline.txt /*vertical*
your bufferline.txt /*your*
27 changes: 27 additions & 0 deletions lua/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ local tabpages = lazy.require("bufferline.tabpages") ---@module "bufferline.tabp
local highlights = lazy.require("bufferline.highlights") ---@module "bufferline.highlights"
local hover = lazy.require("bufferline.hover") ---@module "bufferline.hover"

local get_tabline_text_and_highlights = require("bufferline.pr").get_tabline_text_and_highlights

-- @v:lua@ in the tabline only supports global functions, so this is
-- the only way to add click handlers without autoloaded vimscript functions
_G.___bufferline_private = _G.___bufferline_private or {} -- to guard against reloads
Expand Down Expand Up @@ -50,6 +52,8 @@ local M = {
}
-----------------------------------------------------------------------------//

local capture_next_render = false

--- @return string, bufferline.Segment[][]
local function bufferline()
local is_tabline = config:is_tabline()
Expand Down Expand Up @@ -83,6 +87,13 @@ local function bufferline()
left_offset_size = tabline.left_offset_size,
right_offset_size = tabline.right_offset_size,
})

-- :BufferLineDebug -> prints the rendered tabline from the BufferLineDebug command
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this command should be added at all tbh, fine to use something like this whilst debugging but not looking to have this sort of functionality exposed especially using global state like it appears to

if capture_next_render then
print("Current Tabline and Highlights:\n" .. vim.inspect(get_tabline_text_and_highlights(tabline.str)))
capture_next_render = false
end

return tabline.str, tabline.segments
end

Expand Down Expand Up @@ -179,6 +190,22 @@ local function setup_commands()
nargs = 1,
complete = groups.complete,
})
--- New commands
--- 1. Print the current rendered tabline so users can easily find which Highlight group to change
command("BufferLineDebug", function()
debug_tabline = true
ui.refresh()
end, { nargs = 0 })
-- 2. Remove Command to remove a single buffer from a Group instead of only allowing buffer naming to control groups
-- Moves the buf from the group to the ungrouped group
command("BufferLineRemove", function(opts)
local args = vim.split(opts.args, " ")
local buffer_id, group_id = tonumber(args[1]), args[2]
if buffer_id and group_id then
groups.remove_buf_from_group(buffer_id, group_id)
ui.refresh()
end
end, { nargs = "+", complete = function(ArgLead, CmdLine, CursorPos) return {} end })
end

local function setup_diagnostic_handler(preferences)
Expand Down
2 changes: 1 addition & 1 deletion lua/bufferline/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function M.cycle(direction)
if direction > 0 then vim.cmd("bnext") end
if direction < 0 then vim.cmd("bprev") end
end
local index = M.get_current_element_index(state)
local index = M.get_current_element_index(state) or groups.toggled_index()
if not index then return end
local length = #state.components
local next_index = index + direction
Expand Down
5 changes: 4 additions & 1 deletion lua/bufferline/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,10 @@ local function get_defaults()
diagnostics_update_in_insert = true,
diagnostics_update_on_event = true,
offsets = {},
groups = { items = {}, options = { toggle_hidden_on_enter = true } },
groups = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing defaults like this would require some conversation and convincing.

items = {},
options = { toggle_hidden_on_enter = true, separator_position = "both", separator_style = "thin" },
},
hover = { enabled = false, reveal = {}, delay = 200 },
debug = { logging = false },
}
Expand Down
Loading