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

fix: make buffer command compatible with Windows paths (#1350) #1351

Merged
merged 1 commit into from Feb 11, 2024
Merged

Conversation

bwpge
Copy link
Contributor

@bwpge bwpge commented Feb 11, 2024

This is an incredibly boring PR. It adds a space to the b[uffer] command so that buffer names that use absolute Windows paths can be used without causing errors. This is in line with usage described in :h :buffer and :h {bufname}.

I've manually tested this change on Windows and WSL with the following types of buffers to ensure no regressions as best I can:

  • No name buffers
  • Buffer names with no spaces
  • Buffer names with spaces in the path but not filename
  • Buffer names with spaces in the filename but not path
  • Buffer names with spaces in both path and filename

All cases result in the correct behavior: a warning is issued and the unsaved buffer is focused, without causing errors. Unfortunately I don't have a macOS machine handy to test but I imagine paths and buffer names behave the same or nearly the same as on WSL.

PS: The current implementation of swapping to a buffer by name may be problematic for buffer names that are numbers (see: :h :buffer). This is outside the scope of this PR, but for reference this comes from the utils.get_opened_buffers function:

---Gets a lookup of all open buffers keyed by path with additional information
---@return table opened_buffers { [buffer_name] = { modified = bool } }
M.get_opened_buffers = function()
local opened_buffers = {}
for _, buffer in ipairs(vim.api.nvim_list_bufs()) do
if vim.fn.buflisted(buffer) ~= 0 then
local buffer_name = vim.api.nvim_buf_get_name(buffer)
if buffer_name == nil or buffer_name == "" then
buffer_name = "[No Name]#" .. buffer
end
opened_buffers[buffer_name] = {
["modified"] = vim.api.nvim_buf_get_option(buffer, "modified"),
["loaded"] = vim.api.nvim_buf_is_loaded(buffer),
}
end
end
return opened_buffers
end

Copy link
Contributor

@cseickel cseickel left a comment

Choose a reason for hiding this comment

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

This is an incredibly boring PR.

I love boring. Boring is good. Thanks for the fix!

@cseickel cseickel merged commit f3941c5 into nvim-neo-tree:main Feb 11, 2024
4 checks passed
@bwpge
Copy link
Contributor Author

bwpge commented Feb 11, 2024

Happy to help, and sorry for goofing up the commit message style (thought I was supposed to add my issue number in parens).

Thanks for the quick merge!

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.

None yet

2 participants