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 issue #25 #60

Closed
wants to merge 4 commits into from
Closed

Fix issue #25 #60

wants to merge 4 commits into from

Conversation

enthudave
Copy link
Contributor

It remembers the alternate and current file, if ranger 's closed without a file it revisits these buffers.

@enthudave
Copy link
Contributor Author

I'm sorry about the mess i made in this PR, still getting the hang of git and messed up with the
branches somehow

@francoiscabrol
Copy link
Owner

Thank you for your fix! it looks good.

@enthudave
Copy link
Contributor Author

I'm not so sure it looks good , but it's the only way I see to accomplish this.
Unfortunately :keepalt seems to be unable to help here and I'm not aware of something similar that would work.

@francoiscabrol
Copy link
Owner

francoiscabrol commented May 11, 2018

Yes it's a workaround. but I don't see any other way to fix this issue...
I see still one error: if I open a file in vim, then I open ranger, I close ranger, then I run 'b#', then I get the error Buffer 2 does not exist.
In this case there is no other buffer opened so it should just do nothing... it's not a big issue.
In the case an other file is opened in addition to the current file, it works as expected. So the main issue is solved.

@enthudave
Copy link
Contributor Author

mmm, i just tried this and get don't get this error but get a new [No Name] buffer,
which is also not what one would want. I'll take a further look.

@francoiscabrol
Copy link
Owner

I have maybe an idea I will try this weekend. Thanks again for your help

@enthudave
Copy link
Contributor Author

good , cause I don't, it seems a matter of convincing vim there is no alternate buffer,
otherwise it will try to open the terminal (or rather the bufnr it used to have) which it can't.
One has the same issue when opening a file in vim and then running :terminal,
Buffer 2 does not exist is reported, when using :b# after:

  • closing the terminal buffer with :BClose!
  • closing the terminal buffer with :bdelete!
    So it's, I believe, a Neovim issue..

@francoiscabrol francoiscabrol mentioned this pull request May 16, 2018
@francoiscabrol
Copy link
Owner

You will see that I have opened the PR #61 that re-implement the neovim part without Bclose and add comments for every lines. Removing Bclose should make the whole thing easier to reason about since we will not execute its external code anymore. I re-used your idea of switching between the buffers, thanks a lot!

@francoiscabrol
Copy link
Owner

Since I don't know if I will merge #61, I think this fix is a step in the good direction. I plan to merge it tomorrow.

@enthudave
Copy link
Contributor Author

enthudave commented Jun 1, 2018

don't merge this just yet, take another look at my tab-feature branch,
been up till late working on it,
bclose dependency is removed,
optional tab-feature added,
improvements to netrw replacement,
no more windows closing that shouldn't close

edit: there's still something wrong, it's too late now,
I'll continue tomorrow

@enthudave
Copy link
Contributor Author

I think I'm done, have a look at my fork's tab-feature branch, I'm still gonna do some more testing later,
but it seems pretty stable

@enthudave
Copy link
Contributor Author

I learned something today, I couldn't believe we had to do the buffer visiting thing, and was right.
We can use the registers,
to see the alternate name
run :echo @#
to set it
run :let @#='<name-of-buffer>'

@francoiscabrol
Copy link
Owner

francoiscabrol commented Jun 4, 2018

about using the registers it's awesome! Are you going to update this PR?

@enthudave
Copy link
Contributor Author

enthudave commented Jun 4, 2018

I've spent many hours the last two days making improvements, testing, believing it was solid, only to find that by fixing one thing I had actually broken another or more, now finally I believe it really is solid.
There are still a bunch of debugging messages in there (tab-feature branch). I think it would be easiest for both of us if you could have a look at that, test it as much as you need and if you want to go ahead I'll remove the debug messages and send a PR. I think it would be more complicated, and a quite a bit more work for me if I have to adjust this PR as there are big changes to be made.
In testing I've paid attention to having a sensible alternate set in any scenario I could think off.
The option of using a tab for Ranger's window has been implemented and brought significant added complexity to the alternate file logic and bdelete-ing logic.
I've also paid attention to not having any windows closed as a result from using bdelete for the Ranger terminal.
And finally to wether or not the terminal buffer is always deleted (and not any other file).

edit: just to mention the removal of the BClose dependency as you wanted, hence the bdelete
second edit: I also noticed a possible simplification in my alternate file logic but haven't come around to writing and testing that, it's about using a window variable to set it like I already do if User edit's a directory...

@enthudave
Copy link
Contributor Author

I have done some more work on it. I had not paid enough attention to what happens when not choosing a file.
I'm wondering what you think should become the alternate file after 'editing a directory',
In the current implementation I've chosen to do what vim-dirvish does for that, make that directory buffer the alternate

@francoiscabrol
Copy link
Owner

so that mean it will re-open ranger when you switch back to the alternate buffer? I think it should go back to the last edited file... if there is no file the register @# should be empty I guess. Same behaviour if you try to switch to the alternate buffer right after opening a single file with vim ./filepath

@enthudave
Copy link
Contributor Author

enthudave commented Jun 14, 2018

Ok that's cool I'll get at it soon. Right now it still does indeed end up back in ranger because I saw fit to follow the behaviour of vim-dirvish, because the user did actually open a (directory)buffer him/herself, therefore it should count as a buffer. But as you say an argument can also be made for not counting it since ranger is quite different in its usage than the netrw or vim-dirvish approach.

@enthudave
Copy link
Contributor Author

I've made the change as you wish and removed all the debug messages.
I believe it's quite solid, I also believe there's at least one thing that warrants a further look in the future, it's explained in the comments I've put in... Maybe you know how to do what I describe there (lines 140-144), or someone else and they can give a tip here or even a PR. Otherwise I'll revisit the issue if and when I know how to do so.
I'll send a PR

@francoiscabrol
Copy link
Owner

I didn't re-work on this since long time and I don't remember why I didn't merge this PR 3 months ago! so if no objection I'll merge it since it's solving the open issue.

@enthudave
Copy link
Contributor Author

If you want to pull the work I've done so far you should merge PR #65 not this one,
it's not complete though, we were still discussing how to know in which order buffers were opened so we could always set the alternate file correctly. Please refer to my last comment there, I haven't continued because I was waiting for your decision and I was not in a hurry because I've been working on my music production hobby.

@francoiscabrol
Copy link
Owner

Ok so I close this PR and look at #65.

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