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

feat: Support name_formatter for unnamed buffers #806

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

mskelton
Copy link
Contributor

This adds a new config option unnamed_title to support changing the name of unnamed buffers from [No Name] to anything the user wants (e.g. Untitled).

@akinsho
Copy link
Owner

akinsho commented Aug 25, 2023

@mskelton I think you can accomplish this by using the name_formatter field you can just specify a function and if the path of the buffer passed in is an empty string then use whatever name you want

@mskelton
Copy link
Contributor Author

name_formatter is not called for unnamed buffers.

  local name = "[No Name]"
  if buf.path and #buf.path > 0 then
    name = fn.fnamemodify(buf.path, ":t")
    name = is_directory and name .. "/" or name
    if buf.name_formatter and type(buf.name_formatter) == "function" then
      name = buf.name_formatter({ name = name, path = buf.path, bufnr = buf.id }) or name
    end
  end

@akinsho
Copy link
Owner

akinsho commented Aug 26, 2023

@mskelton I think the solution then IMO would be adapting the logic to work with no name buffers as well so there's one versatile solution rather than two

@mskelton mskelton changed the title Allow changing unnamed buffer titles feat: Support name_formatter for unnamed buffers Aug 26, 2023
@mskelton
Copy link
Contributor Author

@akinsho I changed to allow name_formatter to work with unnamed buffers.

Copy link
Owner

@akinsho akinsho left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏾 thanks for making the changes

@akinsho akinsho merged commit 9961d87 into akinsho:main Aug 29, 2023
sstallion pushed a commit to sstallion/bufferline.nvim that referenced this pull request Jul 3, 2024
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.

2 participants