Closed Susensio closed 9 months ago
Thanks for the issue!
This seems to work as expected. The reason is that this is not a "not save buffer" but rather a "not existing path". When you use MiniFiles.open()
, its value should be a valid path that actually exist. If it doesn't exist, then it is not really clear what explorer should show.
If it is actually an existing file but in modified buffer, then 'mini.files' works as expected.
Maybe a fallback would be nice. But I agree with you, it is not clear what to show. The cwd? The parent directory (if exists)?
I usually edit new files in existing directories, so showing the parent works better for me.
This is what I came up with. It shows the nearest parent directory.
local get_parent = vim.fs.dirname
local exists = function(path) return vim.loop.fs_stat(path) ~= nil end
local path = vim.api.nvim_buf_get_name(0)
while not exists(path) do
path = get_parent(path)
end
MiniFiles.open(path)
Contributing guidelines
Module(s)
mini.files
Description
I have a keymap set to
MiniFiles.open(vim.api.nvim_buf_get_name(0))
as stated on the docs. https://github.com/echasnovski/mini.nvim/blob/964fab7fecd14f66a69a96162f8aa816480690fd/doc/mini-files.txt#L633-L634 It does not work if current buffer is a recently created file and not saved.Neovim version
0.9.4
Steps to reproduce
:e test.txt
:lua MiniFiles.open(vim.api.nvim_buf_get_name(0))
Expected behavior
I would expect MiniFiles to handle unsaved buffers gracefully.
Actual behavior
Error is shown, and no popup is shown