-
Notifications
You must be signed in to change notification settings - Fork 17
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
[FEATURE] Close buffers for files deleted in ranger #15
[FEATURE] Close buffers for files deleted in ranger #15
Conversation
Hey @Rolv-Apneseth, thanks for the PR! I also want to apologise for not getting around to having a look at this PR till now. The logic looks sound. My only comment is that if we can put this feature under an option with the default set as disabled. Thanks. |
No problem. Sure yeah I can have a look at doing that. Also, just to let you know, I turned my fork into a separate plugin, making sure to credit you of course |
Is something like that what you had in mind? |
lua/ranger-nvim.lua
Outdated
-- after running ranger. This should close any buffers for files which were | ||
-- deleted using ranger. | ||
if opts.close_deleted_files then | ||
close_empty_buffers(buffers_for_existing_files) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we only need the buffers for existing files if the option is on, we can merge merge the two if statements to make the code more concise.
if opts.close_deleted_files then
local buffers = get_buffers_for_existing_files()
close_empty_buffers(buffers)
end
Then we can get rid of lines 226-231.
Can you also please fix the indentation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the reason that line is before is to get just the buffers which have valid files before running ranger
, then after ranger
has closed, looping through those and seeing if they no longer have valid files. I don't think having it in one place would work, would it?
Sorry about the indentation, didn't catch that
In relation to #11
Finally took the time to make a serious attempt at this. Seems to work from my testing but let me know what you think when you have the time.
Unfortunately there's nothing convenient from
ranger
like thatchoosefiles
flag which would list deleted files so I took a different approach. Instead I'm storing the listed buffers that point to existing files before opening ranger, then going through that list afterwards and closing buffers for files which no longer exist.