Skip to content

Commit

Permalink
Add number attribute to Window and Tabpage objects
Browse files Browse the repository at this point in the history
The legacy if_pyth interface exposed a number attribute which was
equivalent to the winnr() and tabpagenr() values for the window and
tabpage, respectively.

Neovim 0.1.6 added the necessary API functions to support exposing this
information.

Closes #87
  • Loading branch information
jamessan committed Oct 28, 2016
1 parent 4dbfbd1 commit ce840cb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions neovim/api/tabpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ def window(self):
def valid(self):
"""Return True if the tabpage still exists."""
return self.request('tabpage_is_valid')

@property
def number(self):
"""Get the tabpage number."""
return self.request('nvim_tabpage_get_number')
5 changes: 5 additions & 0 deletions neovim/api/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ def tabpage(self):
def valid(self):
"""Return True if the window still exists."""
return self.request('window_is_valid')

@property
def number(self):
"""Get the window number."""
return self.request('nvim_win_get_number')
9 changes: 9 additions & 0 deletions test/test_tabpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ def test_valid():
ok(tabpage.valid)
vim.command('tabclose')
ok(not tabpage.valid)


@with_setup(setup=cleanup)
def test_number():
curnum = vim.current.tabpage.number
vim.command('tabnew')
eq(vim.current.tabpage.number, curnum + 1)
vim.command('tabnew')
eq(vim.current.tabpage.number, curnum + 2)
9 changes: 9 additions & 0 deletions test/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,12 @@ def test_valid():
ok(window.valid)
vim.command('q')
ok(not window.valid)


@with_setup(setup=cleanup)
def test_number():
curnum = vim.current.window.number
vim.command('bot split')
eq(vim.current.window.number, curnum + 1)
vim.command('bot split')
eq(vim.current.window.number, curnum + 2)

0 comments on commit ce840cb

Please sign in to comment.