Fix line numbers in python error warnings and make all.snippets work for lua too. Fixes #211.

This commit is contained in:
Holger Rapp 2014-02-17 07:36:48 +01:00
parent e7868dd4fb
commit 7ef866e1f4
2 changed files with 8 additions and 20 deletions

View File

@ -22,7 +22,6 @@ def _parse_comments(s):
flags, text = next(i).split(':', 1) flags, text = next(i).split(':', 1)
if len(flags) == 0: 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 # parse 3-part comment, but ignore those with O flag
elif flags[0] == 's' and 'O' not in flags: elif flags[0] == 's' and 'O' not in flags:
@ -43,38 +42,26 @@ def _parse_comments(s):
ctriple.append(indent) ctriple.append(indent)
rv.append(ctriple) rv.append(ctriple)
elif flags[0] == 'b': elif flags[0] == 'b':
if len(text) == 1: if len(text) == 1:
rv.insert(0, (text,text,text, "")) rv.insert(0, (text,text,text, ""))
except StopIteration: except StopIteration:
return rv return rv
def _get_comment_format(): def _get_comment_format():
""" Returns a 4-element tuple representing the comment format for """ Returns a 4-element tuple representing the comment format for
the current file. """ the current file. """
return _parse_comments(vim.eval("&comments"))[0]
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
def make_box(twidth, bwidth=None): def make_box(twidth, bwidth=None):
b, m, e, i = _get_comment_format() b, m, e, i = _get_comment_format()
bwidth_inner = bwidth - 3 - max(len(b), len(i + e)) if bwidth else twidth + 2 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 nspaces = (bwidth_inner - twidth) // 2
mlines = i + m + " " + " " * nspaces mlines = i + m + " " + " " * nspaces
mlinee = " " + " "*(bwidth_inner - twidth - nspaces) + m 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 return sline, mlines, mlinee, eline
def foldmarker(): def foldmarker():

View File

@ -175,7 +175,7 @@ class PythonCode(NoneditableTextObject):
snippet = snippet._parent # pylint:disable=protected-access snippet = snippet._parent # pylint:disable=protected-access
self._snip = SnippetUtil(token.indent, mode, text) self._snip = SnippetUtil(token.indent, mode, text)
self._code = "\n".join(( self._codes = ((
"import re, os, vim, string, random", "import re, os, vim, string, random",
"\n".join(snippet.globals.get("!p", [])).replace("\r\n", "\n"), "\n".join(snippet.globals.get("!p", [])).replace("\r\n", "\n"),
token.code.replace("\\`", "`") token.code.replace("\\`", "`")
@ -195,7 +195,8 @@ class PythonCode(NoneditableTextObject):
}) })
self._snip._reset(ct) # pylint:disable=protected-access 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( rv = as_unicode(
self._snip.rv if self._snip._rv_changed # pylint:disable=protected-access self._snip.rv if self._snip._rv_changed # pylint:disable=protected-access