Skip to content

Commit

Permalink
[Fixes j-morano#31] Added option to use custom function for formattin…
Browse files Browse the repository at this point in the history
…g filenames.
  • Loading branch information
José Morano committed May 3, 2024
1 parent 9cd0e34 commit 7714964
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ require("buffer_manager").setup({ })
* `highlight`: highlight for the window. Format: `from1:to1,from2:to2`. E.g. `Normal:MyCustomNormal`. (See `:help winhighlight`.)
* `win_extra_options`: extra options for the menu window. E.g. `{ relativenumber = true }`. (See `:help option-list`.)
* `borderchars`: border characters for the menu window.
* `format_function`: support for custom function to format buffer names. The function should receive a string and return a string. This option is incompatible with `short_file_names`. To use it, `short_file_names` must be set to `false`. By default, the function is `nil`, which means no special formatting is applied.


In addition, you can specify a custom color for the modified buffers, by setting the highlight group `BufferManagerModified` to the desired color. For example:
Expand All @@ -129,6 +130,7 @@ vim.api.nvim_set_hl(0, "BufferManagerModified", { fg = "#0000af" })
highlight = "",
win_extra_options = {},
borderchars = { "", "", "", "", "", "", "", "" },
format_function = nil,
}
```

Expand Down
1 change: 1 addition & 0 deletions lua/buffer_manager/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function M.setup(config)
highlight = "",
win_extra_options = {},
borderchars = { "", "", "", "", "", "", "", "" },
format_function = nil,
}

local complete_config = merge_tables(default_config, config)
Expand Down
4 changes: 4 additions & 0 deletions lua/buffer_manager/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ local function get_mark_by_name(name, specific_marks)
if config.short_file_names then
ref_name = utils.get_short_file_name(mark.filename, current_short_fns)
current_short_fns[ref_name] = true
elseif config.format_function then
ref_name = config.format_function(mark.filename)
else
ref_name = utils.normalize_path(mark.filename)
end
Expand Down Expand Up @@ -305,6 +307,8 @@ function M.toggle_quick_menu()
if config.short_file_names then
display_filename = utils.get_short_file_name(display_filename, current_short_fns)
current_short_fns[display_filename] = true
elseif config.format_function then
display_filename = config.format_function(display_filename)
else
display_filename = utils.normalize_path(display_filename)
end
Expand Down

0 comments on commit 7714964

Please sign in to comment.