Skip to content

Conversation

bfredl
Copy link
Member

@bfredl bfredl commented Mar 4, 2019

Problem: nvim_buf_set_lines() sometimes messes up the cursor in curwin, if the buffer is displayed in no window. This is because switch_to_win_for_buf() reuses curwin if no window is found.

Problem: nvim_create_buf(false, \* scratch *\ true) doesn't work, because switch_to_win_for_buf doesn't handle buffer options correctly.

Problem: switch_to_win_for_buf seems to do the same thing as aucmd_prepbuf but with issues and glitches.

Solution: always use aucmd_prepbuf() and delete switch_to_win_for_buf(). The only downside to the former might cause two extra frame layout calculations. We could avoid that by making aucmd_win a float. It shares the property that it can't be the only window, anyway, so that might eliminate some ad-hoc checks.

@justinmk
Copy link
Member

justinmk commented Mar 4, 2019

related: #8723 , #7756, #8690

@phodge had the right idea #7756 (comment) :

modify switch_to_win_for_buf() so that it won't switch windows if the current window already points to the requested buffer.

@bfredl
Copy link
Member Author

bfredl commented Mar 4, 2019

@justinmk That doesn't say anything about the situation when the buffer is displayed in no window, which was the problem here.

switch_buffer(save_curbuf, buf);
}
}

static inline void restore_win_for_buf(win_T *save_curwin,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restore_win_for_buf can be deleted \o/

@marvim marvim added the WIP label Mar 4, 2019
@phodge
Copy link
Contributor

phodge commented Mar 4, 2019

The right idea is to completely eradicated the *curbuf global and have functions accept a *buf argument if they want to work with a buffer. Things will never be sane while the neovim is switching buffers under the hood all the time.

This PR still looks like an improvement though, so I wholeheartedly approve. 👍

@bfredl
Copy link
Member Author

bfredl commented Mar 4, 2019

@phodge True that. Having one mechanism for switching is at least less unsane than having multiple such mechanisms...

@bfredl bfredl changed the title [WIP] buffer: use aucmd_prepbuf() instead of switch_to_win_for_buf() api/buffer: use aucmd_prepbuf() to manipulate invisible buffer, fix some issues Mar 5, 2019
@bfredl bfredl merged commit e386e51 into neovim:master Mar 5, 2019
@justinmk justinmk removed the WIP label Mar 5, 2019
@justinmk justinmk changed the title api/buffer: use aucmd_prepbuf() to manipulate invisible buffer, fix some issues API/buffer: use aucmd_prepbuf() to manipulate invisible buffer, fix some issues Mar 5, 2019
@justinmk justinmk added the api libnvim, Nvim RPC API label Mar 5, 2019
@gsf
Copy link

gsf commented Mar 7, 2019

Great to see this! Testing it out and it's a real improvement in my nvim experience. Thanks!

@phodge Is there an issue for tracking work or at least gathering ideas toward removal of the *curbuf global?

hashinclude added a commit to hashinclude/neovim that referenced this pull request May 1, 2019
Code for this was removed in neovim#9674. Re-added it.
justinmk pushed a commit that referenced this pull request May 7, 2019
janlazo added a commit to janlazo/neovim that referenced this pull request Jul 18, 2025
…ndow is opened

neovim#9674 removed switch_to_win_for_buf().
This vim-patch removed the last relevant usage of find_win_for_buf()
Vim uses switch_to_win_for_buf() only for if_py_both.
janlazo added a commit to janlazo/neovim that referenced this pull request Jul 18, 2025
…ndow is opened

neovim#9674 removed switch_to_win_for_buf().
This vim-patch removed the last relevant usage of find_win_for_buf()
Vim uses switch_to_win_for_buf() only for if_py_both.
janlazo added a commit to janlazo/neovim that referenced this pull request Jul 19, 2025
neovim#9674 removed switch_to_win_for_buf().
This vim-patch removed the last relevant usage of find_win_for_buf()
Vim uses switch_to_win_for_buf() only for if_py_both.
janlazo added a commit to janlazo/neovim that referenced this pull request Jul 20, 2025
neovim#9674 removed switch_to_win_for_buf().
This vim-patch removed the last relevant usage of find_win_for_buf()
Vim uses switch_to_win_for_buf() only for if_py_both.
janlazo added a commit to janlazo/neovim that referenced this pull request Jul 20, 2025
neovim#9674 removed switch_to_win_for_buf().
This vim-patch removed the last relevant usage of find_win_for_buf()
Vim uses switch_to_win_for_buf() only for if_py_both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api libnvim, Nvim RPC API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants