Strange error with python interface

20 views
Skip to first unread message

Marcin Szamotulski

unread,
Sep 20, 2012, 3:21:43 AM9/20/12
to Vim Use
Hello,

I stumbled upon a strange error which I cannot figure out why it
happens. Let us write a small vim script (attached to this email) and
save it somewhere on the HD:

python << EOF
import re
patstr = r"""
^(?:[^%]|\\%)*(?:
\\def|
\\providecommand\s*{|
\\(?:re)?newcommand\s*{|
\\(?:re)?newenvironment\s*{|
\\(?:re)?newtheorem\s*{|
\\definecolor\s*{)
([^{}]*)"""
print("'%s'" % patstr.strip())
pat = re.compile(patstr, re.VERBOSE)
EOF

The script just defines a python verbose regular expression, and prints
it. When I open this file with

vim -u NONE script.vim

everythings works fine and as expected. The output of the script is:

'^(?:[^%]|\\%)*(?:
\\def|
\\providecommand\s*{|
\\(?:re)?newcommand\s*{|
\\(?:re)?newenvironment\s*{|
\\(?:re)?newtheorem\s*{|
\\definecolor\s*{)
([^{}]*)'


, but when I open it with
vim script.vim
or
vim --noplugin script.vim

I got the following error:

'^(?:[^%]|\\%)*(?:\def|\providecommand\s*{|\(?:re)?newcommand\s*{|\(?:re)?newenvironment\s*{|\(?:re)?newtheorem\s*{|\definecolor\s*{)
([^{}]*)'
Error detected while processing /tmp/script.vim:
line 14:
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "/usr/lib64/python2.7/re.py", line 190, in compile
return _compile(pattern, flags)
File "/usr/lib64/python2.7/re.py", line 242, in _compile
raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis

Note that this time the new lines are not shown when the print()
statement is executed (why?).

So I started bisecting my vimrc file. Then I ended in the 0 line with
the 'finish' command and the behaviour presists, I also added 'finish'
at the very begining of my system vimrc file and the vimrc file. And
nothing changed (still got the sre_constants.error)

Any ideas?

Best regards,
Marcin
script.vim

Fermat618

unread,
Sep 20, 2012, 3:44:32 AM9/20/12
to vim...@googlegroups.com
I think you have found a bug.

The line started with backslash(\) is treated by vim as a continuation
line. This is a vim feature, not vi's. So when you use vim -u NONE, it
behaves like vi, but as long as you have a .vimrc, even nothing in it,
vim will change it's behaver to vim.

Christian Brabandt

unread,
Sep 20, 2012, 3:56:21 AM9/20/12
to vim...@googlegroups.com
Yes, use the -N switch for force non-compatible vi mode (see :h -N)

regards,
Christian

Marcin Szamotulski

unread,
Sep 20, 2012, 4:50:36 AM9/20/12
to vim...@googlegroups.com
Thanks, that's a good point. I moved the code to a python module which
is imported with python import statement.

Best,
Marcin

Reply all
Reply to author
Forward
0 new messages