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

Inconsistent behavior around vim.api.nvim_tabpage_set_var and vim.api.nvim_tabpage_get_var #27765

Closed
synic opened this issue Mar 7, 2024 · 2 comments
Labels
closed:question issues that are closed as usage questions

Comments

@synic
Copy link
Sponsor

synic commented Mar 7, 2024

Problem

This is kind of hard to explain, but setting variables using vim.api.nvim_tabpage_set_var doesn't always bind them to the tab itself, rather, it binds them to the tab page number, and vim.api.nvim_tabpage_get_var doesn't always return the variable that's bound to the tab, sometimes it returns a variable that was bound to the tab page number with vim.api.nvim_tabpage_set_var.

The result is that the variable isn't really bound in a predictable way, and if you move or otherwise rearrange tabs, the variables will no longer be bound to the correct tab.

Steps to reproduce

  1. Type nvim --clean
  2. Open 3 tabs by typing :tabnew and enter three times.
  3. Make sure you are on the last tab by typing 3gt.
  4. Type :lua vim.api.nvim_tabpage_set_var(vim.fn.tabpagenr(), "foo", "foo")
  5. Type :echo t:foo, observe that it echos foo
  6. Type :lua print(vim.api.nvim_tabpage_get_var(vim.fn.tabpagenr(), "foo")), observe that it prints foo
  7. Type :tabmove 0 to move this tab to the first tab in the list.
  8. Type :echo t:foo, observe that it echos foo
  9. Type :lua print(vim.api.nvim_tabpage_get_var(vim.fn.tabpagenr(), "foo")), it is an error!
  10. Type 3gt to go to the last tab in the list
  11. Type :echo t:foo, it is an error (expected)
  12. Type :lua print(vim.api.nvim_tabpage_get_var(vim.fn.tabpagenr(), "foo")), it prints foo!

It's like vim.api.nvim_tabpage_get_var and vim.api.nvim_tabpage_set_var use an intermediary storage place and it is NOT properly synced when tabs are rearranged.

Expected behavior

The variable should be bound to the tab, not the tab page number, and vim.api.nvim_tabpage_get_var and vim.api.nvim_tabpage_set_var should synchronize with tab rearrangements correctly.

Neovim version (nvim -v)

v0.10.0-dev-2173+g6cbfe4545-Homebrew

Vim (not Nvim) behaves the same?

This is Neovim only

Operating system/version

MacOS 14.3.1

Terminal name/version

Iterm 3.4.23

$TERM environment variable

xterm-256color

Installation

Homebrew

@synic synic added the bug issues reporting wrong behavior label Mar 7, 2024
@github-actions github-actions bot added the api libnvim, Nvim RPC API label Mar 7, 2024
@zeertzjq
Copy link
Member

zeertzjq commented Mar 7, 2024

nvim_tabpage_set_var and nvim_tabpage_get_var do not take tabpage numbers as argument. They take tabpage handles. You need to use nvim_list_tabpages to map tabpage numbers to tabpage handles.

@zeertzjq zeertzjq closed this as not planned Won't fix, can't repro, duplicate, stale Mar 7, 2024
@zeertzjq zeertzjq added closed:question issues that are closed as usage questions and removed bug issues reporting wrong behavior api libnvim, Nvim RPC API labels Mar 7, 2024
@synic
Copy link
Sponsor Author

synic commented Mar 7, 2024

ah, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:question issues that are closed as usage questions
Projects
None yet
Development

No branches or pull requests

2 participants