Skip to content

Conversation

cwqt
Copy link

@cwqt cwqt commented Mar 18, 2022

Adds is_first & is_last properties onto the buffer parameter. Useful for knowing if a tab is the first or last in the set of buffers.

Also exposes all the buffers as an argument, e.g.

{
  text: function(buffer, buffers) 
    if(buffer.is_first) return "first"
    if(buffer.is_last) return "last"
    return buffer.index .. "/" .. #buffers
  end
}

I've been using it in my config for a bit now https://gitlab.com/cxss/dotfiles/-/blob/main/nvim/lua/core/bufferline.lua#L52

Comment on lines +344 to +345
buffer.is_first = i == 1
buffer.is_last = i == #_G.cokeline.visible_buffers
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's no need to set these in every iteration of the loop, just set them once before the loop

_G.cokeline.visible_buffers[1].is_first = true
_G.cokeline.visible_buffers[#_G.cokeline.visible_buffers].is_first = true
for ...

@@ -57,7 +57,7 @@ end
Component.render = function(self, buffer)
local evaluate = function(field)
return (type(field) == "string" and field)
or (type(field) == "function" and field(buffer))
or (type(field) == "function" and field(buffer, _G.cokeline.valid_buffers))
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the benefit of exposing all the valid buffers to the users?

@willothy
Copy link
Owner

Feel free to ping me if this is still needed, but since it doesn't seem necessary to expose all of the buffers and we already have #69 merged from a while ago, I'm going to close this.

@willothy willothy closed this Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants