[Python-modules-commits] [python-neovim] 01/04: Import python-neovim_0.1.11.orig.tar.gz
Víctor Cuadrado Juan
viccuad-guest at moszumanska.debian.org
Fri Dec 9 22:06:39 UTC 2016
This is an automated email from the git hooks/post-receive script.
viccuad-guest pushed a commit to branch master
in repository python-neovim.
commit 0010ca2f224a4f65818b806e93d2aee8aa73d182
Author: Víctor Cuadrado Juan <me at viccuad.me>
Date: Thu Nov 10 22:37:32 2016 +0100
Import python-neovim_0.1.11.orig.tar.gz
---
PKG-INFO | 2 +-
README.md | 2 +
neovim.egg-info/PKG-INFO | 2 +-
neovim.egg-info/requires.txt | 1 -
neovim/__init__.py | 17 +++++--
neovim/api/buffer.py | 85 ++++++++++++++---------------------
neovim/api/nvim.py | 72 ++++++++++++++---------------
neovim/api/tabpage.py | 13 ++++--
neovim/api/window.py | 29 +++++++-----
neovim/msgpack_rpc/event_loop/base.py | 4 +-
neovim/msgpack_rpc/event_loop/uv.py | 4 +-
neovim/msgpack_rpc/session.py | 6 +--
neovim/plugin/decorators.py | 6 +--
neovim/plugin/host.py | 14 +++---
neovim/plugin/script_host.py | 18 +++-----
neovim/util.py | 20 +++++++++
setup.py | 2 +-
test/test_buffer.py | 4 +-
test/test_tabpage.py | 9 ++++
test/test_window.py | 9 ++++
20 files changed, 179 insertions(+), 140 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index ebbee31..cd97ef9 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: neovim
-Version: 0.1.10
+Version: 0.1.11
Summary: Python client to neovim
Home-page: http://github.com/neovim/python-client
Author: Thiago de Arruda
diff --git a/README.md b/README.md
index 97f9dbc..555f78c 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,8 @@ connecting to and scripting Nvim processes through its msgpack-rpc API.
#### Installation
+Supports python 2.7, and 3.3 or later.
+
```sh
pip2 install neovim
pip3 install neovim
diff --git a/neovim.egg-info/PKG-INFO b/neovim.egg-info/PKG-INFO
index ebbee31..cd97ef9 100644
--- a/neovim.egg-info/PKG-INFO
+++ b/neovim.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: neovim
-Version: 0.1.10
+Version: 0.1.11
Summary: Python client to neovim
Home-page: http://github.com/neovim/python-client
Author: Thiago de Arruda
diff --git a/neovim.egg-info/requires.txt b/neovim.egg-info/requires.txt
index ade24eb..d96c04d 100644
--- a/neovim.egg-info/requires.txt
+++ b/neovim.egg-info/requires.txt
@@ -1,3 +1,2 @@
msgpack-python>=0.4.0
-trollius
greenlet
diff --git a/neovim/__init__.py b/neovim/__init__.py
index d84b968..35e5353 100644
--- a/neovim/__init__.py
+++ b/neovim/__init__.py
@@ -12,14 +12,18 @@ from .msgpack_rpc import (ErrorResponse, child_session, socket_session,
stdio_session, tcp_session)
from .plugin import (Host, autocmd, command, decode, encoding, function,
plugin, rpc_export, shutdown_hook)
+from .util import Version
__all__ = ('tcp_session', 'socket_session', 'stdio_session', 'child_session',
'start_host', 'autocmd', 'command', 'encoding', 'decode',
- 'function', 'plugin', 'rpc_export', 'Host', 'Nvim',
+ 'function', 'plugin', 'rpc_export', 'Host', 'Nvim', 'VERSION',
'shutdown_hook', 'attach', 'setup_logging', 'ErrorResponse')
+VERSION = Version(major=0, minor=1, patch=11, prerelease="dev")
+
+
def start_host(session=None):
"""Promote the current process into python plugin host for Nvim.
@@ -64,7 +68,14 @@ def start_host(session=None):
if not session:
session = stdio_session()
- host = Host(Nvim.from_session(session))
+ nvim = Nvim.from_session(session)
+
+ if nvim.version.api_level < 1:
+ sys.stderr.write("This version of the neovim python package "
+ "requires nvim 0.1.6 or later")
+ sys.exit(1)
+
+ host = Host(nvim)
host.start(plugins)
@@ -107,7 +118,7 @@ def setup_logging(name):
if 'NVIM_PYTHON_LOG_FILE' in os.environ:
prefix = os.environ['NVIM_PYTHON_LOG_FILE'].strip()
major_version = sys.version_info[0]
- logfile = '{0}_py{1}_{2}'.format(prefix, major_version, name)
+ logfile = '{}_py{}_{}'.format(prefix, major_version, name)
handler = logging.FileHandler(logfile, 'w')
handler.formatter = logging.Formatter(
'%(asctime)s [%(levelname)s @ '
diff --git a/neovim/api/buffer.py b/neovim/api/buffer.py
index 29de15b..4d71263 100644
--- a/neovim/api/buffer.py
+++ b/neovim/api/buffer.py
@@ -10,11 +10,21 @@ 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 = "buffer_"
+ _api_prefix = "nvim_buf_"
def __len__(self):
"""Return the number of lines contained in a Buffer."""
@@ -31,19 +41,13 @@ class Buffer(Remote):
the whole buffer.
"""
if not isinstance(idx, slice):
- return self._session.request('buffer_get_line', self, idx)
- include_end = False
- start = idx.start
- end = idx.stop
- if start is None:
- start = 0
- if end is None:
- end = -1
- include_end = True
- return self._session.request('buffer_get_line_slice', self, start, end,
- True, include_end)
+ i = adjust_index(idx)
+ return self.request('nvim_buf_get_lines', i, i + 1, True)[0]
+ start = adjust_index(idx.start, 0)
+ end = adjust_index(idx.stop, -1)
+ return self.request('nvim_buf_get_lines', start, end, False)
- def __setitem__(self, idx, lines):
+ def __setitem__(self, idx, item):
"""Replace a buffer line or slice by integer index.
Like with `__getitem__`, indexes may be negative.
@@ -52,23 +56,13 @@ class Buffer(Remote):
the whole buffer.
"""
if not isinstance(idx, slice):
- if lines is None:
- return self._session.request('buffer_del_line', self, idx)
- else:
- return self._session.request('buffer_set_line', self, idx,
- lines)
- if lines is None:
- lines = []
- include_end = False
- start = idx.start
- end = idx.stop
- if start is None:
- start = 0
- if end is None:
- end = -1
- include_end = True
- return self._session.request('buffer_set_line_slice', self, start, end,
- True, include_end, lines)
+ i = adjust_index(idx)
+ lines = [item] if item is not None else []
+ return self.request('nvim_buf_set_lines', i, i + 1, True, lines)
+ lines = item if item is not None else []
+ start = adjust_index(idx.start, 0)
+ end = adjust_index(idx.stop, -1)
+ return self.request('buffer_set_lines', start, end, False, lines)
def __iter__(self):
"""Iterate lines of a buffer.
@@ -87,30 +81,17 @@ class Buffer(Remote):
This is the same as __setitem__(idx, [])
"""
- if not isinstance(idx, slice):
- self.__setitem__(idx, None)
- else:
- self.__setitem__(idx, [])
-
- def get_line_slice(self, start, stop, start_incl, end_incl):
- """More flexible wrapper for retrieving slices."""
- return self._session.request('buffer_get_line_slice', self, start,
- stop, start_incl, end_incl)
-
- def set_line_slice(self, start, stop, start_incl, end_incl, lines):
- """More flexible wrapper for replacing slices."""
- return self._session.request('buffer_set_line_slice', self, start,
- stop, start_incl, end_incl, lines)
+ self.__setitem__(idx, None)
def append(self, lines, index=-1):
"""Append a string or list of lines to the buffer."""
if isinstance(lines, (basestring, bytes)):
lines = [lines]
- return self._session.request('buffer_insert', self, index, lines)
+ return self.request('nvim_buf_set_lines', index, index, True, lines)
def mark(self, name):
"""Return (row, col) tuple for a named mark."""
- return self.request('buffer_get_mark', name)
+ return self.request('nvim_buf_get_mark', name)
def range(self, start, end):
"""Return a `Range` object, which represents part of the Buffer."""
@@ -121,33 +102,33 @@ class Buffer(Remote):
"""Add a highlight to the buffer."""
if async is None:
async = (src_id != 0)
- return self.request('buffer_add_highlight', src_id, hl_group,
+ return self.request('nvim_buf_add_highlight', src_id, hl_group,
line, col_start, col_end, async=async)
def clear_highlight(self, src_id, line_start=0, line_end=-1, async=True):
"""Clear highlights from the buffer."""
- self.request('buffer_clear_highlight', src_id,
+ self.request('nvim_buf_clear_highlight', src_id,
line_start, line_end, async=async)
@property
def name(self):
"""Get the buffer name."""
- return self.request('buffer_get_name')
+ return self.request('nvim_buf_get_name')
@name.setter
def name(self, value):
"""Set the buffer name. BufFilePre/BufFilePost are triggered."""
- return self.request('buffer_set_name', value)
+ return self.request('nvim_buf_set_name', value)
@property
def valid(self):
"""Return True if the buffer still exists."""
- return self.request('buffer_is_valid')
+ return self.request('nvim_buf_is_valid')
@property
def number(self):
"""Get the buffer number."""
- return self.request('buffer_get_number')
+ return self.request('nvim_buf_get_number')
class Range(object):
diff --git a/neovim/api/nvim.py b/neovim/api/nvim.py
index e34c48d..ece8ad0 100644
--- a/neovim/api/nvim.py
+++ b/neovim/api/nvim.py
@@ -13,7 +13,7 @@ from .common import (Remote, RemoteApi, RemoteMap, RemoteSequence,
from .tabpage import Tabpage
from .window import Window
from ..compat import IS_PYTHON3
-from ..util import format_exc_skip
+from ..util import Version, format_exc_skip
__all__ = ('Nvim')
@@ -74,14 +74,16 @@ class Nvim(object):
self._session = session
self.channel_id = channel_id
self.metadata = metadata
+ version = metadata.get("version", {"api_level": 0})
+ self.version = Version(**version)
self.types = types
- self.api = RemoteApi(self, 'vim_')
- self.vars = RemoteMap(self, 'vim_get_var', 'vim_set_var')
+ self.api = RemoteApi(self, 'nvim_')
+ self.vars = RemoteMap(self, 'nvim_get_var', 'nvim_set_var')
self.vvars = RemoteMap(self, 'vim_get_vvar', None)
- self.options = RemoteMap(self, 'vim_get_option', 'vim_set_option')
+ self.options = RemoteMap(self, 'nvim_get_option', 'nvim_set_option')
self.buffers = Buffers(self)
- self.windows = RemoteSequence(self, 'vim_get_windows')
- self.tabpages = RemoteSequence(self, 'vim_get_tabpages')
+ self.windows = RemoteSequence(self, 'nvim_list_wins')
+ self.tabpages = RemoteSequence(self, 'nvim_list_tabpages')
self.current = Current(self)
self.session = CompatibilitySession(self)
self.funcs = Funcs(self)
@@ -116,8 +118,8 @@ class Nvim(object):
is equivalent to
- vim.request('vim_err_write', 'ERROR\n', async=True)
- vim.request('buffer_get_mark', vim.current.buffer, '.')
+ vim.request('nvim_err_write', 'ERROR\n', async=True)
+ vim.request('nvim_buf_get_mark', vim.current.buffer, '.')
Normally a blocking request will be sent. If the `async` flag is
@@ -157,7 +159,7 @@ class Nvim(object):
result = request_cb(name, args)
except Exception:
msg = ("error caught in request handler '{} {}'\n{}\n\n"
- .format(name, args, format_exc_skip(1, 5)))
+ .format(name, args, format_exc_skip(1)))
self._err_cb(msg)
raise
return walk(self._to_nvim, result)
@@ -169,7 +171,7 @@ class Nvim(object):
notification_cb(name, args)
except Exception:
msg = ("error caught in notification handler '{} {}'\n{}\n\n"
- .format(name, args, format_exc_skip(1, 5)))
+ .format(name, args, format_exc_skip(1)))
self._err_cb(msg)
raise
@@ -205,38 +207,38 @@ class Nvim(object):
def subscribe(self, event):
"""Subscribe to a Nvim event."""
- return self.request('vim_subscribe', event)
+ return self.request('nvim_subscribe', event)
def unsubscribe(self, event):
"""Unsubscribe to a Nvim event."""
- return self.request('vim_unsubscribe', event)
+ return self.request('nvim_unsubscribe', event)
def command(self, string, **kwargs):
"""Execute a single ex command."""
- return self.request('vim_command', string, **kwargs)
+ return self.request('nvim_command', string, **kwargs)
def command_output(self, string):
"""Execute a single ex command and return the output."""
- return self.request('vim_command_output', string)
+ return self.request('nvim_command_output', string)
def eval(self, string, **kwargs):
"""Evaluate a vimscript expression."""
- return self.request('vim_eval', string, **kwargs)
+ return self.request('nvim_eval', string, **kwargs)
def call(self, name, *args, **kwargs):
"""Call a vimscript function."""
- return self.request('vim_call_function', name, args, **kwargs)
+ return self.request('nvim_call_function', name, args, **kwargs)
def strwidth(self, string):
"""Return the number of display cells `string` occupies.
Tab is counted as one cell.
"""
- return self.request('vim_strwidth', string)
+ return self.request('nvim_strwidth', string)
def list_runtime_paths(self):
"""Return a list of paths contained in the 'runtimepath' option."""
- return self.request('vim_list_runtime_paths')
+ return self.request('nvim_list_runtime_paths')
def foreach_rtp(self, cb):
"""Invoke `cb` for each path in 'runtimepath'.
@@ -246,7 +248,7 @@ class Nvim(object):
are no longer paths. If stopped in case callable returned non-None,
vim.foreach_rtp function returns the value returned by callable.
"""
- for path in self.request('vim_list_runtime_paths'):
+ for path in self.request('nvim_list_runtime_paths'):
try:
if cb(path) is not None:
break
@@ -256,7 +258,7 @@ class Nvim(object):
def chdir(self, dir_path):
"""Run os.chdir, then all appropriate vim stuff."""
os_chdir(dir_path)
- return self.request('vim_change_directory', dir_path)
+ return self.request('nvim_set_current_dir', dir_path)
def feedkeys(self, keys, options='', escape_csi=True):
"""Push `keys` to Nvim user input buffer.
@@ -267,7 +269,7 @@ class Nvim(object):
- 't': Handle keys as if typed; otherwise they are handled as if coming
from a mapping. This matters for undo, opening folds, etc.
"""
- return self.request('vim_feedkeys', keys, options, escape_csi)
+ return self.request('nvim_feedkeys', keys, options, escape_csi)
def input(self, bytes):
"""Push `bytes` to Nvim low level input buffer.
@@ -277,7 +279,7 @@ class Nvim(object):
written(which can be less than what was requested if the buffer is
full).
"""
- return self.request('vim_input', bytes)
+ return self.request('nvim_input', bytes)
def replace_termcodes(self, string, from_part=False, do_lt=True,
special=True):
@@ -298,11 +300,11 @@ class Nvim(object):
def out_write(self, msg):
"""Print `msg` as a normal message."""
- return self.request('vim_out_write', msg)
+ return self.request('nvim_out_write', msg)
def err_write(self, msg, **kwargs):
"""Print `msg` as an error message."""
- return self.request('vim_err_write', msg, **kwargs)
+ return self.request('nvim_err_write', msg, **kwargs)
def quit(self, quit_command='qa!'):
"""Send a quit command to Nvim.
@@ -339,8 +341,8 @@ class Nvim(object):
fn(*args, **kwargs)
except Exception as err:
msg = ("error caught while executing async callback:\n"
- "{0!r}\n{1}\n \nthe call was requested at\n{2}"
- .format(err, format_exc_skip(1, 5), call_point))
+ "{!r}\n{}\n \nthe call was requested at\n{}"
+ .format(err, format_exc_skip(1), call_point))
self._err_cb(msg)
raise
self._session.threadsafe_call(handler)
@@ -359,7 +361,7 @@ class Buffers(object):
def __init__(self, nvim):
"""Initialize a Buffers object with Nvim object `nvim`."""
- self._fetch_buffers = nvim.api.get_buffers
+ self._fetch_buffers = nvim.api.list_bufs
def __len__(self):
"""Return the count of buffers."""
@@ -399,35 +401,35 @@ class Current(object):
@property
def line(self):
- return self._session.request('vim_get_current_line')
+ return self._session.request('nvim_get_current_line')
@line.setter
def line(self, line):
- return self._session.request('vim_set_current_line', line)
+ return self._session.request('nvim_set_current_line', line)
@property
def buffer(self):
- return self._session.request('vim_get_current_buffer')
+ return self._session.request('nvim_get_current_buf')
@buffer.setter
def buffer(self, buffer):
- return self._session.request('vim_set_current_buffer', buffer)
+ return self._session.request('nvim_set_current_buf', buffer)
@property
def window(self):
- return self._session.request('vim_get_current_window')
+ return self._session.request('nvim_get_current_win')
@window.setter
def window(self, window):
- return self._session.request('vim_set_current_window', window)
+ return self._session.request('nvim_set_current_win', window)
@property
def tabpage(self):
- return self._session.request('vim_get_current_tabpage')
+ return self._session.request('nvim_get_current_tabpage')
@tabpage.setter
def tabpage(self, tabpage):
- return self._session.request('vim_set_current_tabpage', tabpage)
+ return self._session.request('nvim_set_current_tabpage', tabpage)
class Funcs(object):
diff --git a/neovim/api/tabpage.py b/neovim/api/tabpage.py
index 7742ba3..90ed8ff 100644
--- a/neovim/api/tabpage.py
+++ b/neovim/api/tabpage.py
@@ -8,7 +8,7 @@ __all__ = ('Tabpage')
class Tabpage(Remote):
"""A remote Nvim tabpage."""
- _api_prefix = "tabpage_"
+ _api_prefix = "nvim_tabpage_"
def __init__(self, *args):
"""Initialize from session and code_data immutable object.
@@ -17,14 +17,19 @@ class Tabpage(Remote):
msgpack-rpc calls. It must be immutable for Buffer equality to work.
"""
super(Tabpage, self).__init__(*args)
- self.windows = RemoteSequence(self, 'tabpage_get_windows')
+ self.windows = RemoteSequence(self, 'nvim_tabpage_list_wins')
@property
def window(self):
"""Get the `Window` currently focused on the tabpage."""
- return self.request('tabpage_get_window')
+ return self.request('nvim_tabpage_get_win')
@property
def valid(self):
"""Return True if the tabpage still exists."""
- return self.request('tabpage_is_valid')
+ return self.request('nvim_tabpage_is_valid')
+
+ @property
+ def number(self):
+ """Get the tabpage number."""
+ return self.request('nvim_tabpage_get_number')
diff --git a/neovim/api/window.py b/neovim/api/window.py
index b02ebe9..d9a34eb 100644
--- a/neovim/api/window.py
+++ b/neovim/api/window.py
@@ -9,59 +9,64 @@ class Window(Remote):
"""A remote Nvim window."""
- _api_prefix = "window_"
+ _api_prefix = "nvim_win_"
@property
def buffer(self):
"""Get the `Buffer` currently being displayed by the window."""
- return self.request('window_get_buffer')
+ return self.request('nvim_win_get_buf')
@property
def cursor(self):
"""Get the (row, col) tuple with the current cursor position."""
- return self.request('window_get_cursor')
+ return self.request('nvim_win_get_cursor')
@cursor.setter
def cursor(self, pos):
"""Set the (row, col) tuple as the new cursor position."""
- return self.request('window_set_cursor', pos)
+ return self.request('nvim_win_set_cursor', pos)
@property
def height(self):
"""Get the window height in rows."""
- return self.request('window_get_height')
+ return self.request('nvim_win_get_height')
@height.setter
def height(self, height):
"""Set the window height in rows."""
- return self.request('window_set_height', height)
+ return self.request('nvim_win_set_height', height)
@property
def width(self):
"""Get the window width in rows."""
- return self.request('window_get_width')
+ return self.request('nvim_win_get_width')
@width.setter
def width(self, width):
"""Set the window height in rows."""
- return self.request('window_set_width', width)
+ return self.request('nvim_win_set_width', width)
@property
def row(self):
"""0-indexed, on-screen window position(row) in display cells."""
- return self.request('window_get_position')[0]
+ return self.request('nvim_win_get_position')[0]
@property
def col(self):
"""0-indexed, on-screen window position(col) in display cells."""
- return self.request('window_get_position')[1]
+ return self.request('nvim_win_get_position')[1]
@property
def tabpage(self):
"""Get the `Tabpage` that contains the window."""
- return self.request('window_get_tabpage')
+ return self.request('nvim_win_get_tabpage')
@property
def valid(self):
"""Return True if the window still exists."""
- return self.request('window_is_valid')
+ return self.request('nvim_win_is_valid')
+
+ @property
+ def number(self):
+ """Get the window number."""
+ return self.request('nvim_win_get_number')
diff --git a/neovim/msgpack_rpc/event_loop/base.py b/neovim/msgpack_rpc/event_loop/base.py
index a05299e..2f27bd4 100644
--- a/neovim/msgpack_rpc/event_loop/base.py
+++ b/neovim/msgpack_rpc/event_loop/base.py
@@ -85,7 +85,7 @@ class BaseEventLoop(object):
self._on_data = None
self._error = None
self._init()
- getattr(self, '_connect_{0}'.format(transport_type))(*args)
+ getattr(self, '_connect_{}'.format(transport_type))(*args)
self._start_reading()
def connect_tcp(self, address, port):
@@ -149,7 +149,7 @@ class BaseEventLoop(object):
debug('Stopped event loop')
def _on_signal(self, signum):
- msg = 'Received {0}'.format(self._signames[signum])
+ msg = 'Received {}'.format(self._signames[signum])
debug(msg)
if signum == signal.SIGINT and self._transport_type == 'stdio':
# When the transport is stdio, we are probably running as a Nvim
diff --git a/neovim/msgpack_rpc/event_loop/uv.py b/neovim/msgpack_rpc/event_loop/uv.py
index 73daab4..449d28e 100644
--- a/neovim/msgpack_rpc/event_loop/uv.py
+++ b/neovim/msgpack_rpc/event_loop/uv.py
@@ -21,7 +21,7 @@ class UvEventLoop(BaseEventLoop):
def _on_connect(self, stream, error):
self.stop()
if error:
- msg = 'Cannot connect to {0}: {1}'.format(
+ msg = 'Cannot connect to {}: {}'.format(
self._connect_address, pyuv.errno.strerror(error))
self._connection_error = IOError(msg)
return
@@ -49,7 +49,7 @@ class UvEventLoop(BaseEventLoop):
def _connect_tcp(self, address, port):
stream = pyuv.TCP(self._loop)
- self._connect_address = '{0}:{1}'.format(address, port)
+ self._connect_address = '{}:{}'.format(address, port)
stream.connect((address, port), self._on_connect)
def _connect_socket(self, path):
diff --git a/neovim/msgpack_rpc/session.py b/neovim/msgpack_rpc/session.py
index e2a4994..de87c97 100644
--- a/neovim/msgpack_rpc/session.py
+++ b/neovim/msgpack_rpc/session.py
@@ -82,7 +82,7 @@ class Session(object):
return
if kwargs:
- raise ValueError("request got unsupported keyword argument(s): {0}"
+ raise ValueError("request got unsupported keyword argument(s): {}"
.format(', '.join(kwargs.keys())))
if self._is_running:
@@ -122,13 +122,13 @@ class Session(object):
gr.switch()
if self._setup_exception:
- error('Setup error: {0}'.format(self._setup_exception))
+ error('Setup error: {}'.format(self._setup_exception))
raise self._setup_exception
# Process all pending requests and notifications
while self._pending_messages:
msg = self._pending_messages.popleft()
- getattr(self, '_on_{0}'.format(msg[0]))(*msg[1:])
+ getattr(self, '_on_{}'.format(msg[0]))(*msg[1:])
self._async_session.run(self._on_request, self._on_notification)
self._is_running = False
self._request_cb = None
diff --git a/neovim/plugin/decorators.py b/neovim/plugin/decorators.py
index acbf0be..defceb3 100644
--- a/neovim/plugin/decorators.py
+++ b/neovim/plugin/decorators.py
@@ -46,7 +46,7 @@ def command(name, nargs=0, complete=None, range=None, count=None, bang=False,
register=False, sync=False, eval=None):
"""Tag a function or plugin method as a Nvim command handler."""
def dec(f):
- f._nvim_rpc_method_name = 'command:{0}'.format(name)
+ f._nvim_rpc_method_name = 'command:{}'.format(name)
f._nvim_rpc_sync = sync
f._nvim_bind = True
f._nvim_prefix_plugin_path = True
@@ -86,7 +86,7 @@ def command(name, nargs=0, complete=None, range=None, count=None, bang=False,
def autocmd(name, pattern='*', sync=False, eval=None):
"""Tag a function or plugin method as a Nvim autocommand handler."""
def dec(f):
- f._nvim_rpc_method_name = 'autocmd:{0}:{1}'.format(name, pattern)
+ f._nvim_rpc_method_name = 'autocmd:{}:{}'.format(name, pattern)
f._nvim_rpc_sync = sync
f._nvim_bind = True
f._nvim_prefix_plugin_path = True
@@ -111,7 +111,7 @@ def autocmd(name, pattern='*', sync=False, eval=None):
def function(name, range=False, sync=False, eval=None):
"""Tag a function or plugin method as a Nvim function handler."""
def dec(f):
- f._nvim_rpc_method_name = 'function:{0}'.format(name)
+ f._nvim_rpc_method_name = 'function:{}'.format(name)
f._nvim_rpc_sync = sync
f._nvim_bind = True
f._nvim_prefix_plugin_path = True
diff --git a/neovim/plugin/host.py b/neovim/plugin/host.py
index 6769ef6..d1b7ab5 100644
--- a/neovim/plugin/host.py
+++ b/neovim/plugin/host.py
@@ -71,11 +71,11 @@ class Host(object):
except Exception:
if sync:
msg = ("error caught in request handler '{} {}':\n{}"
- .format(name, args, format_exc_skip(1, 5)))
+ .format(name, args, format_exc_skip(1)))
raise ErrorResponse(msg)
else:
msg = ("error caught in async handler '{} {}'\n{}\n"
- .format(name, args, format_exc_skip(1, 5)))
+ .format(name, args, format_exc_skip(1)))
self._on_async_err(msg + "\n")
def _on_request(self, name, args):
@@ -120,7 +120,7 @@ class Host(object):
for path in plugins:
err = None
if path in self._loaded:
- error('{0} is already loaded'.format(path))
+ error('{} is already loaded'.format(path))
continue
try:
if path == "script_host.py":
@@ -133,7 +133,7 @@ class Host(object):
self._discover_classes(module, handlers, path)
self._discover_functions(module, handlers, path)
if not handlers:
- error('{0} exports no handlers'.format(path))
+ error('{} exports no handlers'.format(path))
continue
self._loaded[path] = {'handlers': handlers, 'module': module}
except Exception as e:
@@ -179,7 +179,7 @@ class Host(object):
method = fn._nvim_rpc_method_name
if fn._nvim_prefix_plugin_path:
- method = '{0}:{1}'.format(plugin_path, method)
+ method = '{}:{}'.format(plugin_path, method)
fn_wrapped = functools.partial(self._wrap_function, fn,
sync, decode, nvim_bind, method)
@@ -187,12 +187,12 @@ class Host(object):
# register in the rpc handler dict
if sync:
if method in self._request_handlers:
- raise Exception(('Request handler for "{0}" is ' +
+ raise Exception(('Request handler for "{}" is ' +
'already registered').format(method))
self._request_handlers[method] = fn_wrapped
else:
if method in self._notification_handlers:
- raise Exception(('Notification handler for "{0}" is ' +
+ raise Exception(('Notification handler for "{}" is ' +
'already registered').format(method))
self._notification_handlers[method] = fn_wrapped
if hasattr(fn, '_nvim_rpc_spec'):
diff --git a/neovim/plugin/script_host.py b/neovim/plugin/script_host.py
index c6139ab..1a015fe 100644
--- a/neovim/plugin/script_host.py
+++ b/neovim/plugin/script_host.py
@@ -96,7 +96,6 @@ class ScriptHost(object):
self._set_current_range(start, stop)
nvim = self.nvim
start -= 1
- stop -= 1
fname = '_vim_pydo'
# define the function
@@ -104,15 +103,14 @@ class ScriptHost(object):
exec(function_def, self.module.__dict__)
# get the function
function = self.module.__dict__[fname]
- while start <= stop:
+ while start < stop:
# Process batches of 5000 to avoid the overhead of making multiple
# API calls for every line. Assuming an average line length of 100
# bytes, approximately 488 kilobytes will be transferred per batch,
# which can be done very quickly in a single API call.
sstart = start
sstop = min(start + 5000, stop)
- lines = nvim.current.buffer.get_line_slice(sstart, sstop, True,
- True)
+ lines = nvim.current.buffer.api.get_lines(sstart, sstop, True)
exception = None
newlines = []
@@ -123,9 +121,8 @@ class ScriptHost(object):
# Update earlier lines, and skip to the next
if newlines:
end = sstart + len(newlines) - 1
- nvim.current.buffer.set_line_slice(sstart, end,
- True, True,
- newlines)
+ nvim.current.buffer.api.set_lines(sstart, end,
+ True, newlines)
sstart += len(newlines) + 1
newlines = []
pass
@@ -138,11 +135,10 @@ class ScriptHost(object):
break
linenr += 1
- start = sstop + 1
+ start = sstop
if newlines:
- end = sstart + len(newlines) - 1
- nvim.current.buffer.set_line_slice(sstart, end, True, True,
- newlines)
+ end = sstart + len(newlines)
+ nvim.current.buffer.api.set_lines(sstart, end, True, newlines)
if exception:
raise exception
# delete the function
diff --git a/neovim/util.py b/neovim/util.py
index cd4e009..798656d 100644
--- a/neovim/util.py
+++ b/neovim/util.py
@@ -10,3 +10,23 @@ def format_exc_skip(skip, limit=None):
for i in range(skip):
tb = tb.tb_next
return ('\n'.join(format_exception(type, val, tb, limit))).rstrip()
+
+
+# Taken from SimpleNamespace in python 3
+class Version:
+
+ """Helper class for version info."""
+
+ def __init__(self, **kwargs):
+ """Create the Version object."""
+ self.__dict__.update(kwargs)
+
+ def __repr__(self):
+ """Return str representation of the Version."""
+ keys = sorted(self.__dict__)
+ items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys)
+ return "{}({})".format(type(self).__name__, ", ".join(items))
+
+ def __eq__(self, other):
+ """Check if version is same as other."""
+ return self.__dict__ == other.__dict__
diff --git a/setup.py b/setup.py
index fab84e3..36ecedb 100644
--- a/setup.py
+++ b/setup.py
@@ -19,7 +19,7 @@ if platform.python_implementation() != 'PyPy':
install_requires.append('greenlet')
setup(name='neovim',
- version='0.1.10',
+ version='0.1.11',
description='Python client to neovim',
url='http://github.com/neovim/python-client',
download_url='https://github.com/neovim/python-client/archive/0.1.10.tar.gz',
diff --git a/test/test_buffer.py b/test/test_buffer.py
index a99a9ce..9bb91b5 100644
--- a/test/test_buffer.py
+++ b/test/test_buffer.py
@@ -83,8 +83,8 @@ def test_api():
vim.current.buffer.api.set_var('myvar', 'thetext')
eq(vim.current.buffer.api.get_var('myvar'), 'thetext')
eq(vim.eval('b:myvar'), 'thetext')
- vim.current.buffer.api.set_line_slice(0,-1,True,True,['alpha', 'beta'])
- eq(vim.current.buffer.api.get_line_slice(0,-1,True,True), ['alpha', 'beta'])
+ vim.current.buffer.api.set_lines(0,-1,True,['alpha', 'beta'])
+ eq(vim.current.buffer.api.get_lines(0,-1,True), ['alpha', 'beta'])
eq(vim.current.buffer[:], ['alpha', 'beta'])
diff --git a/test/test_tabpage.py b/test/test_tabpage.py
index 1ada376..82bea07 100644
--- a/test/test_tabpage.py
+++ b/test/test_tabpage.py
@@ -28,3 +28,12 @@ def test_valid():
ok(tabpage.valid)
vim.command('tabclose')
ok(not tabpage.valid)
+
+
+ at 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)
diff --git a/test/test_window.py b/test/test_window.py
index 605a96e..d2cd955 100644
--- a/test/test_window.py
+++ b/test/test_window.py
@@ -94,3 +94,12 @@ def test_valid():
ok(window.valid)
vim.command('q')
ok(not window.valid)
+
+
+ at 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)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-neovim.git
More information about the Python-modules-commits
mailing list