mirror of
https://github.com/amix/vimrc
synced 2025-02-28 14:12:51 +08:00
125 lines
4.1 KiB
Diff
125 lines
4.1 KiB
Diff
diff --git a/README.rst b/README.rst
|
|
index 5f8467f..acff657 100644
|
|
--- a/README.rst
|
|
+++ b/README.rst
|
|
@@ -8,11 +8,13 @@ accessing a local before it is bound, and also gives warnings for things like
|
|
unused imports.
|
|
|
|
pyflakes-vim uses the output from PyFlakes to highlight errors in your code.
|
|
+To locate errors quickly, use quickfix_ commands:
|
|
|
|
Make sure to check vim.org_ for the latest updates.
|
|
|
|
.. _pyflakes.vim: http://www.vim.org/scripts/script.php?script_id=2441
|
|
.. _vim.org: http://www.vim.org/scripts/script.php?script_id=2441
|
|
+.. _quickfix: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#quickfix
|
|
|
|
Quick Installation
|
|
------------------
|
|
@@ -57,12 +59,10 @@ Hacking
|
|
TODO
|
|
----
|
|
* signs_ support (show warning and error icons to left of the buffer area)
|
|
- * quickfix_ support (allow jumping forward and back through the error list)
|
|
* configuration variables
|
|
* parse or intercept useful output from the warnings module
|
|
|
|
.. _signs: http://www.vim.org/htmldoc/sign.html
|
|
-.. _quickfix: http://vimdoc.sourceforge.net/htmldoc/quickfix.html
|
|
|
|
Changelog
|
|
---------
|
|
diff --git a/pyflakes.vim b/pyflakes.vim
|
|
index 8aa508b..d6699bc 100644
|
|
--- a/pyflakes.vim
|
|
+++ b/pyflakes.vim
|
|
@@ -159,6 +159,42 @@ if !exists("*s:WideMsg")
|
|
endfun
|
|
endif
|
|
|
|
+if !exists("*s:GetQuickFixStackCount")
|
|
+ function s:GetQuickFixStackCount()
|
|
+ let l:stack_count = 0
|
|
+ try
|
|
+ silent colder 9
|
|
+ catch /E380:/
|
|
+ endtry
|
|
+
|
|
+ try
|
|
+ for i in range(9)
|
|
+ silent cnewer
|
|
+ let l:stack_count = l:stack_count + 1
|
|
+ endfor
|
|
+ catch /E381:/
|
|
+ return l:stack_count
|
|
+ endtry
|
|
+ endfunction
|
|
+endif
|
|
+
|
|
+if !exists("*s:ActivatePyflakesQuickFixWindow")
|
|
+ function s:ActivatePyflakesQuickFixWindow()
|
|
+ try
|
|
+ silent colder 9 " go to the bottom of quickfix stack
|
|
+ catch /E380:/
|
|
+ endtry
|
|
+
|
|
+ if s:pyflakes_qf > 0
|
|
+ try
|
|
+ exe "silent cnewer " . s:pyflakes_qf
|
|
+ catch /E381:/
|
|
+ echoerr "Could not activate Pyflakes Quickfix Window."
|
|
+ endtry
|
|
+ endif
|
|
+ endfunction
|
|
+endif
|
|
+
|
|
if !exists("*s:RunPyflakes")
|
|
function s:RunPyflakes()
|
|
highlight link PyFlakes SpellBad
|
|
@@ -174,12 +210,23 @@ if !exists("*s:RunPyflakes")
|
|
|
|
let b:matched = []
|
|
let b:matchedlines = {}
|
|
+
|
|
+ let b:qf_list = []
|
|
+ let b:qf_window_count = -1
|
|
+
|
|
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,8 +236,21 @@ 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)")
|
|
EOF
|
|
+ if exists("s:pyflakes_qf")
|
|
+ " if pyflakes quickfix window is already created, reuse it
|
|
+ call s:ActivatePyflakesQuickFixWindow()
|
|
+ call setqflist(b:qf_list, 'r')
|
|
+ else
|
|
+ " one pyflakes quickfix window for all buffer
|
|
+ call setqflist(b:qf_list, '')
|
|
+ let s:pyflakes_qf = s:GetQuickFixStackCount()
|
|
+ endif
|
|
let b:cleared = 0
|
|
endfunction
|
|
end
|