Skip to content
This repository
Browse code

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

…found.
  • Loading branch information...
commit 1dffdbe91034f7a2bb6a16efe43d9bd9a466d11a 1 parent 17f225f
Phui Hock authored July 06, 2010 kevinw committed July 07, 2010

Showing 1 changed file with 15 additions and 1 deletion. Show diff stats Hide diff stats

  1. 16  pyflakes.vim
16  pyflakes.vim
@@ -43,6 +43,7 @@ sys.path.insert(0, scriptdir)
43 43
 
44 44
 from pyflakes import checker, ast, messages
45 45
 from operator import attrgetter
  46
+import re
46 47
 
47 48
 class SyntaxError(messages.Message):
48 49
     message = 'could not compile: %s'
@@ -55,7 +56,20 @@ class blackhole(object):
55 56
 
56 57
 def check(buffer):
57 58
     filename = buffer.name
58  
-    contents = '\n'.join(buffer[:]) + '\n'
  59
+    contents = buffer[:]
  60
+
  61
+    # shebang usually found at the top of the file, followed by source code encoding marker.
  62
+    # assume everything else that follows is encoded in the encoding.
  63
+    encoding_found = False
  64
+    for n, line in enumerate(contents):
  65
+        if not encoding_found:
  66
+            if re.match(r'^# -\*- coding: .+? -*-', line):
  67
+                encoding_found = True
  68
+        else:
  69
+            # skip all preceeding lines 
  70
+            contents = [''] * n + contents[n:]
  71
+            break
  72
+    contents = '\n'.join(contents) + '\n'
59 73
 
60 74
     vimenc = vim.eval('&encoding')
61 75
     if vimenc:

0 notes on commit 1dffdbe

Please sign in to comment.
Something went wrong with that request. Please try again.