From 7ef866e1f4f4dfbf7e60ae12c9677c7148bc5fce Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Mon, 17 Feb 2014 07:36:48 +0100 Subject: [PATCH] Fix line numbers in python error warnings and make all.snippets work for lua too. Fixes #211. --- UltiSnips/all.snippets | 23 ++++--------------- .../UltiSnips/text_objects/_python_code.py | 5 ++-- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/UltiSnips/all.snippets b/UltiSnips/all.snippets index abb083c..1e17427 100644 --- a/UltiSnips/all.snippets +++ b/UltiSnips/all.snippets @@ -19,11 +19,10 @@ def _parse_comments(s): try: while True: # get the flags and text of a comment part - flags,text = next(i).split(':', 1) + flags, text = next(i).split(':', 1) if len(flags) == 0: - if len(text) == 1: - rv.append((text,text,text, "")) + rv.append((text, text, text, "")) # parse 3-part comment, but ignore those with O flag elif flags[0] == 's' and 'O' not in flags: ctriple = [] @@ -43,38 +42,26 @@ def _parse_comments(s): ctriple.append(indent) rv.append(ctriple) - elif flags[0] == 'b': if len(text) == 1: rv.insert(0, (text,text,text, "")) - except StopIteration: return rv def _get_comment_format(): """ Returns a 4-element tuple representing the comment format for the current file. """ - - ft = vim.eval("&filetype") - # check if the comment dict has the format for the current file - if ft in _commentDict: - return _commentDict[ft] - - # otherwise parse vim's comments and add it for later use - commentformat = _parse_comments(vim.eval("&comments"))[0] - _commentDict[ft] = commentformat - - return commentformat + return _parse_comments(vim.eval("&comments"))[0] def make_box(twidth, bwidth=None): b, m, e, i = _get_comment_format() bwidth_inner = bwidth - 3 - max(len(b), len(i + e)) if bwidth else twidth + 2 - sline = b + m + bwidth_inner * m + 2 * m + sline = b + m + bwidth_inner * m[0] + 2 * m[0] nspaces = (bwidth_inner - twidth) // 2 mlines = i + m + " " + " " * nspaces mlinee = " " + " "*(bwidth_inner - twidth - nspaces) + m - eline = i + 2 * m + bwidth_inner * m + m + e + eline = i + m + bwidth_inner * m[0] + 2 * m[0] + e return sline, mlines, mlinee, eline def foldmarker(): diff --git a/pythonx/UltiSnips/text_objects/_python_code.py b/pythonx/UltiSnips/text_objects/_python_code.py index 0055c24..c9c3e66 100644 --- a/pythonx/UltiSnips/text_objects/_python_code.py +++ b/pythonx/UltiSnips/text_objects/_python_code.py @@ -175,7 +175,7 @@ class PythonCode(NoneditableTextObject): snippet = snippet._parent # pylint:disable=protected-access self._snip = SnippetUtil(token.indent, mode, text) - self._code = "\n".join(( + self._codes = (( "import re, os, vim, string, random", "\n".join(snippet.globals.get("!p", [])).replace("\r\n", "\n"), token.code.replace("\\`", "`") @@ -195,7 +195,8 @@ class PythonCode(NoneditableTextObject): }) self._snip._reset(ct) # pylint:disable=protected-access - exec(self._code, self._locals) # pylint:disable=exec-used + for code in self._codes: + exec(code, self._locals) # pylint:disable=exec-used rv = as_unicode( self._snip.rv if self._snip._rv_changed # pylint:disable=protected-access