Repository: spyder-ide/spyder

Issue:
Code style (pep8) toggle in source menu
## Issue

I often find myself switching the code style warnings on as off as I switch between files and I think it's about 6 clicks through the preferences to get at it.

I often write scripts for figures or data crunching that are one offs and the pep8 is just noise.

For code that I or some one might use again code style is nice to turn on.  Even at that I usually only turn it on in the clean up stage. 

## Solution?

Add a `Code Style Warnings (PEP8)` toggle in the source menu.

Edit: I just found the `# analysis:ignore ` comment.  A `# analysis:ignore_all ` might be handy too.


Discussion:
> Add a Code Style Warnings (PEP8) toggle in the source menu.

I like this idea, thanks for the suggestion.

> I just found the # analysis:ignore comment. A # analysis:ignore_all might be handy too.

That's provided by `pyflakes` (I think) so you should google a bit to see if there's a `# analysis:ignore_all` kind of comment.
I have started working on this.  I'll have a PR this week.

I have the option in the source menu and when I uncheck it the style warnings disappear, but when check it the warnings don't reappear until I change some code and it recomputes

The config dialog runs this code on apply if you change the style check to get around that:  

https://github.com/spyder-ide/spyder/blob/777015f806261338995cdaa2e8d51badd0d7ef19/spyder/plugins/editor.py#L2757

Any hints on how to get a checkable action like these to run that on a check action:

https://github.com/spyder-ide/spyder/blob/777015f806261338995cdaa2e8d51badd0d7ef19/spyder/plugins/editor.py#L1008
  
@rlaverde was working on this a couple of weeks ago. @rlaverde?
> was working on this a couple of weeks ago?

Yes, I generalize that logic for checkable preferences in  #5274.

>Any hints on how to get a checkable action like these to run that on a check action:

You could add that logic to the` _toggle_checkable_action()` method, although that will add some complexity to that function. https://github.com/spyder-ide/spyder/blob/master/spyder/plugins/editor.py#L1252

Resolving patch:
diff --git a/spyder/plugins/editor.py b/spyder/plugins/editor.py
--- a/spyder/plugins/editor.py
+++ b/spyder/plugins/editor.py
@@ -1020,11 +1020,16 @@ def get_plugin_actions(self):
                 _("Show selector for classes and functions."),
                 'show_class_func_dropdown', 'set_classfunc_dropdown_visible')
 
+        showcode_analysis_pep8_action = self._create_checkable_action(
+                _("Show code style warnings (pep8)"),
+                'code_analysis/pep8', 'set_pep8_enabled')
+
         self.checkable_actions = {
                 'blank_spaces': showblanks_action,
                 'scroll_past_end': scrollpastend_action,
                 'indent_guides': showindentguides_action,
-                'show_class_func_dropdown': show_classfunc_dropdown_action}
+                'show_class_func_dropdown': show_classfunc_dropdown_action,
+                'code_analysis/pep8': showcode_analysis_pep8_action}
 
         fixindentation_action = create_action(self, _("Fix indentation"),
                       tip=_("Replace tab characters by space characters"),
@@ -1148,6 +1153,7 @@ def get_plugin_actions(self):
                                scrollpastend_action,
                                showindentguides_action,
                                show_classfunc_dropdown_action,
+                               showcode_analysis_pep8_action,
                                trailingspaces_action,
                                fixindentation_action,
                                MENU_SEPARATOR,
@@ -1266,6 +1272,12 @@ def _toggle_checkable_action(self, checked, editorstack_method, conf_name):
                     editorstack.__getattribute__(editorstack_method)(checked)
                 except AttributeError as e:
                     debug_print("Error {}".format(str))
+                # Run code analysis when `set_pep8_enabled` is toggled
+                if editorstack_method == 'set_pep8_enabled':
+                    for finfo in editorstack.data:
+                        finfo.run_code_analysis(
+                                self.get_option('code_analysis/pyflakes'),
+                                checked)
         CONF.set('editor', conf_name, checked)
 
     #------ Focus tabwidget


Test patch: