@rpc_export('<STR_LIT>', sync=True)<EOL><INDENT>def python_do_range(self, start, stop, code):<DEDENT>
self._set_current_range(start, stop)<EOL>nvim = self.nvim<EOL>start -= <NUM_LIT:1><EOL>fname = '<STR_LIT>'<EOL>function_def = '<STR_LIT>' % (fname, code,)<EOL>exec(function_def, self.module.__dict__)<EOL>function = self.module.__dict__[fname]<EOL>while start < stop:<EOL><INDENT>sstart = start<EOL>sstop = min(start + <NUM_LIT>, stop)<EOL>lines = nvim.current.buffer.api.get_lines(sstart, sstop, True)<EOL>exception = None<EOL>newlines = []<EOL>linenr = sstart + <NUM_LIT:1><EOL>for i, line in enumerate(lines):<EOL><INDENT>result = function(line, linenr)<EOL>if result is None:<EOL><INDENT>if newlines:<EOL><INDENT>end = sstart + len(newlines) - <NUM_LIT:1><EOL>nvim.current.buffer.api.set_lines(sstart, end,<EOL>True, newlines)<EOL><DEDENT>sstart += len(newlines) + <NUM_LIT:1><EOL>newlines = []<EOL>pass<EOL><DEDENT>elif isinstance(result, basestring):<EOL><INDENT>newlines.append(result)<EOL><DEDENT>else:<EOL><INDENT>exception = TypeError('<STR_LIT>'<EOL>+ '<STR_LIT>'<EOL>% result.__class__.__name__)<EOL>break<EOL><DEDENT>linenr += <NUM_LIT:1><EOL><DEDENT>start = sstop<EOL>if newlines:<EOL><INDENT>end = sstart + len(newlines)<EOL>nvim.current.buffer.api.set_lines(sstart, end, True, newlines)<EOL><DEDENT>if exception:<EOL><INDENT>raise exception<EOL><DEDENT><DEDENT>del self.module.__dict__[fname]<EOL>
Handle the `pydo` ex command.