diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap
index f8f4d1e..a23bcf6 100644
--- a/Default (Linux).sublime-keymap
+++ b/Default (Linux).sublime-keymap
@@ -1,4 +1,5 @@
[
{ "keys": ["ctrl+alt+8"], "command": "flake8_lint" },
- { "keys": ["ctrl+alt+9"], "command": "flake8_next_error" }
+ { "keys": ["ctrl+alt+9"], "command": "flake8_next_error" },
+ { "keys": ["ctrl+alt+0"], "command": "flake8_disable" }
]
diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap
index ccab7eb..348ec54 100644
--- a/Default (OSX).sublime-keymap
+++ b/Default (OSX).sublime-keymap
@@ -1,4 +1,5 @@
[
{ "keys": ["ctrl+super+8"], "command": "flake8_lint" },
- { "keys": ["ctrl+super+9"], "command": "flake8_next_error" }
+ { "keys": ["ctrl+super+9"], "command": "flake8_next_error" },
+ { "keys": ["ctrl+super+0"], "command": "flake8_disable" }
]
diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap
index e3bc6ea..317b0b0 100644
--- a/Default (Windows).sublime-keymap
+++ b/Default (Windows).sublime-keymap
@@ -1,4 +1,5 @@
[
{ "keys": ["ctrl+alt+shift+8"], "command": "flake8_lint" },
- { "keys": ["ctrl+alt+shift+9"], "command": "flake8_next_error" }
+ { "keys": ["ctrl+alt+shift+9"], "command": "flake8_next_error" },
+ { "keys": ["ctrl+alt+shift+0"], "command": "flake8_disable" }
]
diff --git a/Default.sublime-commands b/Default.sublime-commands
index cdce5ee..847d14e 100644
--- a/Default.sublime-commands
+++ b/Default.sublime-commands
@@ -1,4 +1,5 @@
[
{ "caption": "User: Python Flake8 Lint", "command": "flake8_lint" },
- { "caption": "User: Jump to next Flake8 Lint error", "command": "flake8_next_error" }
+ { "caption": "User: Jump to next Flake8 Lint error", "command": "flake8_next_error" },
+ { "caption": "User: Disable Python Flake8 Lint for this file", "command": "flake8_disable"}
]
diff --git a/Flake8Lint.py b/Flake8Lint.py
index f5b5a5e..fd1d306 100644
--- a/Flake8Lint.py
+++ b/Flake8Lint.py
@@ -51,6 +51,7 @@
'ignore', 'select', 'ignore_files', 'pep8_max_line_length'
)
+DISABLED_VIEWS = set()
ERRORS_IN_VIEWS = {}
PLUGIN_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -1064,6 +1065,9 @@ def on_file_load(view=None, retry=False):
@staticmethod
def cleanup(view):
"""Clear regions and statusbar."""
+ # cleanup errors in cache
+ ERRORS_IN_VIEWS.pop(view.id(), None)
+
# we need to always clear regions. three situations here:
# - we need to clear regions with fixed previous errors
# - is user will turn off 'highlight' in settings and then run lint
@@ -1079,6 +1083,11 @@ def do_lint(view, quiet=False):
"""Do view lint."""
log("run flake8 lint")
+ if view.id() in DISABLED_VIEWS:
+ log("skip lint because view linting is disabled")
+ Flake8Lint.cleanup(view)
+ return
+
# check if view is scratch
if view.is_scratch():
log("skip lint because view is scratch")
@@ -1206,6 +1215,15 @@ def async_lint(view, view_settings, quiet=False):
LintReport(view, errors_list, view_settings, quiet=quiet)
+class Flake8DisableCommand(sublime_plugin.TextCommand):
+ """Disable current view linting."""
+
+ def run(self, edit):
+ """Disable current view linting."""
+ DISABLED_VIEWS.add(self.view.id())
+ Flake8Lint.cleanup(self.view)
+
+
class Flake8NextErrorCommand(sublime_plugin.TextCommand):
"""Jump to next lint error command."""
@@ -1213,6 +1231,12 @@ def run(self, edit):
"""Jump to next lint error."""
log("jump to next lint error")
+ if self.view.id() in DISABLED_VIEWS:
+ log("view lint is disabled")
+ if not sublime.ok_cancel_dialog("Enable lint for this view?"):
+ return
+ DISABLED_VIEWS.remove(self.view.id())
+
view_errors = ERRORS_IN_VIEWS.get(self.view.id())
if not view_errors:
log("no view errors found")
@@ -1248,6 +1272,12 @@ class Flake8LintCommand(sublime_plugin.TextCommand):
def run(self, edit):
"""Run flake8 lint."""
+ if self.view.id() in DISABLED_VIEWS:
+ log("view lint is disabled")
+ if not sublime.ok_cancel_dialog("Enable lint for this view?"):
+ return
+ DISABLED_VIEWS.remove(self.view.id())
+
Flake8Lint.do_lint(self.view)
diff --git a/README.md b/README.md
index 695e72f..9b6e959 100644
--- a/README.md
+++ b/README.md
@@ -241,3 +241,11 @@ Use these keys (by default) to jump to next lint error:
* OS X: Ctrl+Super+9
* Linux: Ctrl+Alt+9
* Windows: Ctrl+Alt+Shift+9
+
+Use these keys (by default) to disable current file linting:
+
+* OS X: Ctrl+Super+0
+* Linux: Ctrl+Alt+0
+* Windows: Ctrl+Alt+Shift+0
+
+[![Commands list](https://habrastorage.org/files/1b3/fe1/32f/1b3fe132f6f24516a59474486b56a224.png)](https://habrastorage.org/files/1b3/fe1/32f/1b3fe132f6f24516a59474486b56a224.png)