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 mksession to set localdir correctly when there are multiple tabs #3152

Closed
wants to merge 2 commits into from

Conversation

ychin
Copy link
Contributor

@ychin ychin commented Jul 4, 2018

This patch fixes an issue in mksession where local directories don't get properly saved out if there are multiple tabs. A simple repro is as follows:

edit some_file.txt
tabedit some_file2.txt
tabfirst
lcd ~/.vim
mksession ~/session.vim
qa

Then in another Vim instance:

source ~/session.vim
tablast
assert_true(!haslocaldir(), 'should not have localdir')

The assert will fire. The issue is that mksession makes new tabs using tabedit after populating the current tab's windows first. The issue is tabedit will propagate local options to the new tab, including the localdir. Instead, the fix is to pre-populate all the tabs first (similar to how the script pre-populates the window splits in ses_win_rec()).

In testing this I also found a couple bugs that I fixed:

  1. The session Vim script doesn't clear all the other tabs on load. This is inconsistent to how it uses silent only to clear all the other windows first. To fix this, add silent tabonly to make sure everything is cleared on load. This also makes sure the last command in the script to re-select the active tab via tabnext will work properly.
  • (I do realize this has a small chance of breaking people who got used to the old inconsistent behavior. I don't know how big that population is)
  1. If the first window of first tab is a blank window, then mksession will generate a script that deletes that window, since s:wipebuf is actually the buffer for the blank window when restoring. Fix this by making sure s:wipebuf is actually not used anywhere before calling bwipe on it. See Empty first tab lost when using sessions #1282 for an existing issue calling this out.

ychin added 2 commits July 4, 2018 00:28
Change the generated scripts to first create all the tabs (similar to
how window splits work) before populating each tab. This prevents local
options (including localdir) from spilling over to other tabs when using
':tabedit'.

Also fix mksession not setting "tabonly". It would first clear the
current tab by using "only" but leave the other tabs along. This makes
tabs more consistent with how window splits are cleared.

Fix blank window removed by mksession (due to s:wipebuf) if it's the
first window in first tab. See vim#1282.

Add tests to test the above cases.
@brammool brammool closed this in 26d4b89 Jul 4, 2018
@ychin
Copy link
Contributor Author

ychin commented Jul 4, 2018

I just saw from that the unit tests are failing on Windows from my change (https://ci.appveyor.com/project/chrisbra/vim/build/5845/job/5iyg6ol949fwddte). It's due to a minor difference in how lcd works on Unix systems and Windows. I'll submit a new PR to make sure it passes on Windows.

@ychin ychin deleted the mksession-tab-lcd branch July 4, 2018 21:00
@ychin
Copy link
Contributor Author

ychin commented Jul 4, 2018

Oh wait you already fixed that in 81e2ac7, nevermind!

@brammool
Copy link
Contributor

brammool commented Jul 4, 2018 via email

janlazo added a commit to janlazo/neovim that referenced this pull request Dec 18, 2020
… used

Problem:    The generated sessions file does not restore tabs properly if :lcd
            was used in one of them.
Solution:   Create the tab pages before setting the directory. (Yee Cheng
            Chin, closes vim/vim#3152)
vim/vim@26d4b89
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 19, 2020
… used

Problem:    The generated sessions file does not restore tabs properly if :lcd
            was used in one of them.
Solution:   Create the tab pages before setting the directory. (Yee Cheng
            Chin, closes vim/vim#3152)
vim/vim@26d4b89
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 20, 2020
… used

Problem:    The generated sessions file does not restore tabs properly if :lcd
            was used in one of them.
Solution:   Create the tab pages before setting the directory. (Yee Cheng
            Chin, closes vim/vim#3152)
vim/vim@26d4b89
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 20, 2020
… used

Problem:    The generated sessions file does not restore tabs properly if :lcd
            was used in one of them.
Solution:   Create the tab pages before setting the directory. (Yee Cheng
            Chin, closes vim/vim#3152)
vim/vim@26d4b89

Neovim always uses Unix paths for buffers, restored by ":mksession".
Buffers with tab-local CWD are now restored with Unix paths on Windows.
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 20, 2020
… used

Problem:    The generated sessions file does not restore tabs properly if :lcd
            was used in one of them.
Solution:   Create the tab pages before setting the directory. (Yee Cheng
            Chin, closes vim/vim#3152)
vim/vim@26d4b89

Neovim always uses Unix paths for buffers, restored by ":mksession".
Buffers with tab-local CWD are now restored with Unix paths on Windows.
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 20, 2020
… used

Problem:    The generated sessions file does not restore tabs properly if :lcd
            was used in one of them.
Solution:   Create the tab pages before setting the directory. (Yee Cheng
            Chin, closes vim/vim#3152)
vim/vim@26d4b89

Neovim always uses Unix paths for buffers, restored by ":mksession".
Buffers with tab-local CWD are now restored with Unix paths on Windows.
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 21, 2020
… used

Problem:    The generated sessions file does not restore tabs properly if :lcd
            was used in one of them.
Solution:   Create the tab pages before setting the directory. (Yee Cheng
            Chin, closes vim/vim#3152)
vim/vim@26d4b89

Neovim always uses Unix paths for buffers, restored by ":mksession".
Buffers with tab-local CWD are now restored with Unix paths on Windows.
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 21, 2020
… used

Problem:    The generated sessions file does not restore tabs properly if :lcd
            was used in one of them.
Solution:   Create the tab pages before setting the directory. (Yee Cheng
            Chin, closes vim/vim#3152)
vim/vim@26d4b89
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 30, 2020
… used

Problem:    The generated sessions file does not restore tabs properly if :lcd
            was used in one of them.
Solution:   Create the tab pages before setting the directory. (Yee Cheng
            Chin, closes vim/vim#3152)
vim/vim@26d4b89
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