Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Do not decode source code encoding line and the lines preceed it, if …

…found.
  • Loading branch information...
commit 1dffdbe91034f7a2bb6a16efe43d9bd9a466d11a 1 parent 17f225f
@phuihock phuihock authored committed
Showing with 15 additions and 1 deletion.
  1. +15 −1 pyflakes.vim
View
16 pyflakes.vim
@@ -43,6 +43,7 @@ sys.path.insert(0, scriptdir)
from pyflakes import checker, ast, messages
from operator import attrgetter
+import re
class SyntaxError(messages.Message):
message = 'could not compile: %s'
@@ -55,7 +56,20 @@ class blackhole(object):
def check(buffer):
filename = buffer.name
- contents = '\n'.join(buffer[:]) + '\n'
+ contents = buffer[:]
+
+ # shebang usually found at the top of the file, followed by source code encoding marker.
+ # assume everything else that follows is encoded in the encoding.
+ encoding_found = False
+ for n, line in enumerate(contents):
+ if not encoding_found:
+ if re.match(r'^# -\*- coding: .+? -*-', line):
+ encoding_found = True
+ else:
+ # skip all preceeding lines
+ contents = [''] * n + contents[n:]
+ break
+ contents = '\n'.join(contents) + '\n'
vimenc = vim.eval('&encoding')
if vimenc:
Please sign in to comment.
Something went wrong with that request. Please try again.