PyFlakes
authorKevin Watters <[email protected]>
Fri, 17 Oct 2008 20:21:06 +0000 (17 16:21 -0400)
committerKevin Watters <[email protected]>
Fri, 17 Oct 2008 20:21:06 +0000 (17 16:21 -0400)
after/ftplugin/python/pyflakes.vim [new file with mode: 0644]

diff --git a/after/ftplugin/python/pyflakes.vim b/after/ftplugin/python/pyflakes.vim
new file mode 100644 (file)
index 0000000..ba6dac0
--- /dev/null
@@ -0,0 +1,64 @@
+" pyflakes.vim
+"
+" thanks to matlib.vim for ideas/code on interactive linting
+
+if exists("b:did_pyflakes_plugin")
+    finish
+end
+
+let b:did_pyflakes_plugin = 1
+
+let s:cpo_sav = &cpo
+set cpo-=C
+
+if !exists("*s:RunPyflakes")
+    function s:RunPyflakes()
+        highlight PyFlakes term=underline gui=undercurl guisp=Orange
+
+        if exists("b:cleared")
+            if b:cleared == 0
+                silent call s:ClearPyflakes()
+                let b:cleared = 1
+            endif
+        else
+            let b:cleared = 1
+        endif
+        
+        let b:matched = []
+
+
+        let b:cleared = 0
+    end
+end
+
+if !exists("*s:GetPyflakesMessage")
+    function s:GetPyflakesMessage()
+        let s:cursorPos = getpos(".")
+        for s:pyflakesMatch in b:matched
+        " If we're on a line with a match then show the message
+            if s:pyflakesMatch['lineNum'] == s:cursorPos[1]
+                " The two lines commented below cause a message to be shown
+                " only when the cursor is actually over the offending item in
+                " the line.
+                "\ && s:cursorPos[2] > s:pyflakesMatch['colStart'] 
+                "\ && s:cursorPos[2] < s:pyflakesMatch['colEnd']
+                echo s:pyflakesMatch['message']
+            endif
+        endfor
+    endfunction
+endif
+
+if !exists('*s:ClearPyflakes')
+    function s:ClearPyflakes()
+        let s:matches = getmatches()
+        for s:matchId in s:matches
+            if s:matchId['group'] == 'PyFlakes'
+                call matchdelete(s:matchId['id'])
+            end
+        endfor
+        let b:matched = []
+        let b:cleared = 1
+    endfunction
+endif
+
+let &cpo = s:cpo_sav