j-morano / buffer_manager.nvim

A simple plugin to easily manage Neovim buffers.
MIT License
232 stars 12 forks source link

Feature Request: Give the user a custom function to format the file name #31

Closed mycf closed 5 months ago

j-morano commented 5 months ago

Hello. Thanks for the feedback. I just added the option format_function. Please let me know if it works for you.

mycf commented 5 months ago

Hello. Thanks for the feedback. I just added the option format_function. Please let me know if it works for you.你好。感谢您的反馈。我刚刚添加了选项format_function。请告诉我它是否适合您。

Thank you for your effort!

work well with custom hl

image
niamleeson commented 5 months ago

@mycf could you share the format_function you used here?

mycf commented 5 months ago

@mycf could you share the format_function you used here?

@niamleeson The hope can help you

      format_function = function(file)
        if not file then
          return
        end
        -- for java jar class
        if vim.startswith(file, "jdt:/") then
          local package, name = file:match("/([^/]+)/([^/]+.class)?=")
          return string.format("%s %s", name, package)
        end

        local filename = file:match(".+/([^/]-)$")

        local directory = file:match("(.+)/[^/]-$")
        return string.format("%s %s", filename, directory)
      end,

for hl you can read buffer like the following in config function, not like me( violently added here) https://github.com/j-morano/buffer_manager.nvim/blob/7714964bd0e01656cd4090874a0f270e27fb5491/lua/buffer_manager/ui.lua#L326

  for index, content in pairs(contents) do
    vim.api.nvim_buf_add_highlight(
      Buffer_manager_bufh,
      -1,
      "TelescopeMatching",
      index - 1,
      0,
      #vim.split(content, " ")[1]
    )
    vim.api.nvim_buf_add_highlight(
      Buffer_manager_bufh,
      -1,
      "TelescopeResultsComment",
      index - 1,
      #vim.split(content, " ")[1],
      -1
    )
  end
niamleeson commented 5 months ago

Thank you!