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

[FEATURE] Close buffers for files deleted in ranger #15

Conversation

Rolv-Apneseth
Copy link

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 that choosefiles 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.

@kelly-lin
Copy link
Owner

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.

@Rolv-Apneseth
Copy link
Author

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

@Rolv-Apneseth
Copy link
Author

Rolv-Apneseth commented Feb 9, 2024

Is something like that what you had in mind?

-- 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)
Copy link
Owner

@kelly-lin kelly-lin Feb 9, 2024

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?

Copy link
Author

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

@Rolv-Apneseth Rolv-Apneseth deleted the close_buffer_when_deleting_file branch April 5, 2024 20:05
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.

2 participants