From 6b48dc61c1844a08a4a76bdb69edd8418139e1c4 Mon Sep 17 00:00:00 2001 From: Phui Hock Date: Tue, 6 Jul 2010 18:53:55 +0800 Subject: [PATCH 1/2] Do not decode source code encoding line and the lines preceed it, if found. --- pyflakes.vim | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pyflakes.vim b/pyflakes.vim index 4739c2f..8aa508b 100644 --- a/pyflakes.vim +++ b/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: From eaeb6d121beb1dfa027879bd571212f5882c082a Mon Sep 17 00:00:00 2001 From: Phui Hock Date: Thu, 8 Jul 2010 16:39:30 +0800 Subject: [PATCH 2/2] Add quickfix support --- pyflakes.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pyflakes.vim b/pyflakes.vim index 8aa508b..6d20732 100644 --- a/pyflakes.vim +++ b/pyflakes.vim @@ -174,12 +174,21 @@ if !exists("*s:RunPyflakes") let b:matched = [] let b:matchedlines = {} + + let b:qf_list = [] python << EOF for w in check(vim.current.buffer): vim.command('let s:matchDict = {}') vim.command("let s:matchDict['lineNum'] = " + str(w.lineno)) vim.command("let s:matchDict['message'] = '%s'" % vim_quote(w.message % w.message_args)) vim.command("let b:matchedlines[" + str(w.lineno) + "] = s:matchDict") + + vim.command("let l:qf_item = {}") + vim.command("let l:qf_item.bufnr = bufnr('%')") + vim.command("let l:qf_item.filename = expand('%')") + vim.command("let l:qf_item.lnum = %s" % str(w.lineno)) + vim.command("let l:qf_item.text = '%s'" % vim_quote(w.message % w.message_args)) + vim.command("let l:qf_item.type = 'E'") if w.col is None or isinstance(w, SyntaxError): # without column information, just highlight the whole line @@ -189,7 +198,13 @@ for w in check(vim.current.buffer): # with a column number, highlight the first keyword there vim.command(r"let s:mID = matchadd('PyFlakes', '^\%" + str(w.lineno) + r"l\_.\{-}\zs\k\+\k\@!\%>" + str(w.col) + r"c')") + vim.command("let l:qf_item.vcol = 1") + vim.command("let l:qf_item.col = %s" % str(w.col + 1)) + vim.command("call add(b:matched, s:matchDict)") + vim.command("call add(b:qf_list, l:qf_item)") + +vim.command("call setqflist(b:qf_list, 'r')") EOF let b:cleared = 0 endfunction