Skip to content

Commit

Permalink
feat: Support name_formatter for unnamed buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
mskelton committed Aug 26, 2023
1 parent 417b303 commit c05a5d3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lua/bufferline/models.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local lazy = require("bufferline.lazy")
local utils = lazy.require("bufferline.utils") ---@module "bufferline.utils"
local log = lazy.require("bufferline.utils.log") ---@module "bufferline.utils.log"
local constants = lazy.require("bufferline.constants") ---@module "bufferline.constants"
local config = lazy.require("bufferline.config") ---@module "bufferline.config"

local M = {}

Expand Down Expand Up @@ -173,13 +174,16 @@ function Buffer:new(buf)
type = buf.buftype,
})
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

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

buf.name = name

setmetatable(buf, self)
Expand Down

0 comments on commit c05a5d3

Please sign in to comment.