Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""API for working with Nvim windows."""
from .common import Remote
__all__ = ('Window')
class Window(Remote):
"""A remote Nvim window."""
_api_prefix = "nvim_win_"
@property
def buffer(self):
"""Get the `Buffer` currently being displayed by the window."""
return self.request('nvim_win_get_buf')
@property
def cursor(self):
"""Get the (row, col) tuple with the current cursor position."""
return self.request('nvim_win_get_cursor')
@cursor.setter
def _to_nvim(self, obj):
if isinstance(obj, Remote):
return ExtType(*obj.code_data)
return obj
if IS_PYTHON3:
basestring = str
def adjust_index(idx, default=None):
"""Convert from python indexing convention to nvim indexing convention."""
if idx is None:
return default
elif idx < 0:
return idx - 1
else:
return idx
class Buffer(Remote):
"""A remote Nvim buffer."""
_api_prefix = "nvim_buf_"
def __len__(self):
"""Return the number of lines contained in a Buffer."""
return self.request('nvim_buf_line_count')
def __getitem__(self, idx):
"""Get a buffer line or slice by integer index.
Indexes may be negative to specify positions from the end of the
buffer. For example, -1 is the last line, -2 is the line before that
and so on.
"""API for working with Nvim tabpages."""
from .common import Remote, RemoteSequence
__all__ = ('Tabpage')
class Tabpage(Remote):
"""A remote Nvim tabpage."""
_api_prefix = "nvim_tabpage_"
def __init__(self, *args):
"""Initialize from session and code_data immutable object.
The `code_data` contains serialization information required for
msgpack-rpc calls. It must be immutable for Buffer equality to work.
"""
super(Tabpage, self).__init__(*args)
self.windows = RemoteSequence(self, 'nvim_tabpage_list_wins')
@property
def window(self):
"""Get the `Window` currently focused on the tabpage."""