Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lua/buffer_manager/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ local function get_mark_by_name(name, specific_marks)
else
if config.short_file_names then
ref_name = utils.get_short_file_name(mark.filename, current_short_fns)
current_short_fns[ref_name] = true
current_short_fns[ref_name:gsub('^%d+|', '')] = true
elseif config.format_function then
ref_name = config.format_function(mark.filename)
else
Expand Down Expand Up @@ -299,6 +299,7 @@ end

function M.toggle_quick_menu()
log.trace("toggle_quick_menu()")
config = buffer_manager.get_config() -- update configuration
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I am not sure this is needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@j-morano
That is related with what I mentioned at Problem 1.
I agree with you that line(302) don't need If normal situation, because the same code exists at line(14).

But the configuration what I set doesn't apply whenever I call toggle_quick_menu(),
although the result of require('buffer_manager').get_config() in command mode is the same with what I configured.

For debugging, I wrote some print() code at line(302) like print(config.short_file_names). The result was false before I modified this line(302)

Does it works in your environment? If it does, I think It will be changed as
if vim.fn.has('win32') then config = buffer_manager.get_config() end
I am Windows 10 / nvim 0.9.5 / loading buffer_manager at startup

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm warming up this discussion because I found a similar solution (see my fork) when trying to figure out why the width and height of the popup cannot be changed via the config.

I have little knowledge about lua but as far as I understand, the local config set in the top of the ui.lua file and used throughout it seems to be set before running any setup (at least when using lazy). So it always has the default values not matter what I set in the configuration. When getting the config in the function calls everything works as expected. So I think this and similar called in the other functions are very much needed. Or there is some more elegant solution one with lua experience can think of.

Also I'm using MacOS and Linux. So it is no Windows problem.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

okay. Investigated a bit more and found that it was a configuration issue on my side. I called require("buffer_manager.ui") before running the setup. So I guess it is kind of expected. Still not the behaviour I would personally expect. It would certainly be cleaner if the config would be retrieved inside the function.

if Buffer_manager_win_id ~= nil and vim.api.nvim_win_is_valid(Buffer_manager_win_id) then
if vim.api.nvim_buf_get_changedtick(vim.fn.bufnr()) > 0 then
M.on_menu_save()
Expand Down Expand Up @@ -346,7 +347,7 @@ function M.toggle_quick_menu()
if not string_starts(display_filename, "term://") then
if config.short_file_names then
display_filename = utils.get_short_file_name(display_filename, current_short_fns)
current_short_fns[display_filename] = true
current_short_fns[display_filename:gsub('^%d+|', '')] = true
elseif config.format_function then
display_filename = config.format_function(display_filename)
else
Expand Down
21 changes: 15 additions & 6 deletions lua/buffer_manager/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ end


function M.get_short_file_name(file, current_short_fns)
local has_win = vim.fn.has('win32') == 1
if has_win then
file = file:gsub('\\','/')
end
local short_name = nil
-- Get normalized file path
file = M.normalize_path(file)
Expand All @@ -41,29 +45,34 @@ function M.get_short_file_name(file, current_short_fns)
-- insert firts char only
table.insert(folders, folder)
end
-- folders : table which is constitute of file path every '/'
-- why does this function call files with multiple times?
-- File to string
file = tostring(file)
-- Count the number of slashes in the relative file path
local slash_count = 0
for _ in string.gmatch(file, "/") do
for _ in string.gmatch(file, "/") do -- he makes 'folders', but why do this?
slash_count = slash_count + 1
end
if slash_count == 0 then
short_name = M.get_file_name(file)
else
-- Return the file name preceded by the number of slashes
short_name = slash_count .. "|" .. M.get_file_name(file)
short_name = slash_count .. "|" .. M.get_file_name(file) -- get file name only regardless of path
end
-- Check if the file name is already in the list of short file names
-- If so, return the short file name with one number in front of it
local i = 1
while key_in_table(short_name, current_short_fns) do
local i = #folders-1
local filename = short_name
local dirname = ''
while key_in_table(short_name:gsub('^%d+|', ''), current_short_fns) do
local folder = folders[i]
if folder == nil then
folder = i
end
short_name = short_name.." ("..folder..")"
i = i + 1
dirname = folder .. '/' .. dirname
short_name = filename .. ' (' .. dirname .. ')'
i = i - 1
end
return short_name
end
Expand Down