Skip to content

Instantly share code, notes, and snippets.

@cpelley
Last active December 22, 2015 14:09
Show Gist options
  • Save cpelley/6484171 to your computer and use it in GitHub Desktop.
Save cpelley/6484171 to your computer and use it in GitHub Desktop.
Pyflakes monkey-patch to give appropriately formatted syntax error for vim
#!/usr/bin/env python
import sys
import pyflakes.reporter as reporter
from pyflakes.scripts.pyflakes import main
# Monkey patch syntax error method for suitability with vim
def vimhappy_syntaxError(self, filename, msg, lineno, offset, text):
line = text.splitlines()[-1]
if offset is not None:
offset = offset - (len(text) - len(line))
self._stderr.write(reporter.u('%s:%d:%d: %s\n') % (filename, lineno,
offset+1, msg))
reporter.Reporter.syntaxError = vimhappy_syntaxError
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment