Repository: spyder-ide/spyder

Issue:
"Show blank spaces" refuses to work on files without officially "supported" extensions
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

The "Show blank spaces" toggle refuse to work on files with "unsupported" extensions (dotfiles, plain text, lektor, etc), even in the latest ``master``. There appears to be absolutely no logical reason for this, nor does any other editor or IDE refuse to do this, so this is presumably a bug and should be fixed. Presumably Spyder is unnessesarily checking if a file is one of the "supported" extensions before allowing blank spaces to be shown, which of course it shouldn't, but I'd have to look into it further to figure out where or why.



## Versions

* Spyder version: 4.0.0.dev0 324ca58c9
* Python version: 3.6.6
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 8.1

### Dependencies

```
pygments >=2.0    :  2.2.0 (OK)
sphinx >=0.6.6    :  1.7.6 (OK)
pyls >=0.19.0     :  0.19.0 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
pandas >=0.13.1   :  None (NOK)
numpy >=1.7       :  None (NOK)
sympy >=0.7.3     :  None (NOK)
cython >=0.21     :  None (NOK)
qtconsole >=4.2.0 :  4.4.0 (OK)
IPython >=4.0     :  6.5.0 (OK)
matplotlib >=2.0.0:  None (NOK)
pylint >=0.25     :  2.1.1 (OK)
```



Discussion:

Resolving patch:
diff --git a/spyder/plugins/editor/utils/languages.py b/spyder/plugins/editor/utils/languages.py
--- a/spyder/plugins/editor/utils/languages.py
+++ b/spyder/plugins/editor/utils/languages.py
@@ -9,21 +9,23 @@
 """
 
 ALL_LANGUAGES = {
-                 'Python': ('py', 'pyw', 'python', 'ipy'),
-                 'Cython': ('pyx', 'pxi', 'pxd'),
-                 'Enaml': ('enaml',),
-                 'Fortran77': ('f', 'for', 'f77'),
-                 'Fortran': ('f90', 'f95', 'f2k', 'f03', 'f08'),
-                 'Idl': ('pro',),
-                 'Diff': ('diff', 'patch', 'rej'),
-                 'GetText': ('po', 'pot'),
-                 'Nsis': ('nsi', 'nsh'),
-                 'Html': ('htm', 'html'),
-                 'Cpp': ('c', 'cc', 'cpp', 'cxx', 'h', 'hh', 'hpp', 'hxx'),
-                 'OpenCL': ('cl',),
-                 'Yaml': ('yaml', 'yml'),
-                 "Markdown": ('md', 'mdw'),
-                 }
+    'Python': ('py', 'pyw', 'python', 'ipy'),
+    'Cython': ('pyx', 'pxi', 'pxd'),
+    'Enaml': ('enaml',),
+    'Fortran77': ('f', 'for', 'f77'),
+    'Fortran': ('f90', 'f95', 'f2k', 'f03', 'f08'),
+    'Idl': ('pro',),
+    'Diff': ('diff', 'patch', 'rej'),
+    'GetText': ('po', 'pot'),
+    'Nsis': ('nsi', 'nsh'),
+    'Html': ('htm', 'html'),
+    'Cpp': ('c', 'cc', 'cpp', 'cxx', 'h', 'hh', 'hpp', 'hxx'),
+    'OpenCL': ('cl',),
+    'Yaml': ('yaml', 'yml'),
+    'Markdown': ('md', 'mdw'),
+    # Every other language
+    'None': ('', ),
+}
 
 PYTHON_LIKE_LANGUAGES = ('Python', 'Cython', 'Enaml')
 
diff --git a/spyder/plugins/editor/widgets/codeeditor.py b/spyder/plugins/editor/widgets/codeeditor.py
--- a/spyder/plugins/editor/widgets/codeeditor.py
+++ b/spyder/plugins/editor/widgets/codeeditor.py
@@ -207,21 +207,24 @@ def get_file_language(filename, text=None):
 class CodeEditor(TextEditBaseWidget):
     """Source Code Editor Widget based exclusively on Qt"""
 
-    LANGUAGES = {'Python': (sh.PythonSH, '#', PythonCFM),
-                 'Cython': (sh.CythonSH, '#', PythonCFM),
-                 'Fortran77': (sh.Fortran77SH, 'c', None),
-                 'Fortran': (sh.FortranSH, '!', None),
-                 'Idl': (sh.IdlSH, ';', None),
-                 'Diff': (sh.DiffSH, '', None),
-                 'GetText': (sh.GetTextSH, '#', None),
-                 'Nsis': (sh.NsisSH, '#', None),
-                 'Html': (sh.HtmlSH, '', None),
-                 'Yaml': (sh.YamlSH, '#', None),
-                 'Cpp': (sh.CppSH, '//', None),
-                 'OpenCL': (sh.OpenCLSH, '//', None),
-                 'Enaml': (sh.EnamlSH, '#', PythonCFM),
-                 'Markdown': (sh.MarkdownSH, '#', None),
-                }
+    LANGUAGES = {
+        'Python': (sh.PythonSH, '#', PythonCFM),
+        'Cython': (sh.CythonSH, '#', PythonCFM),
+        'Fortran77': (sh.Fortran77SH, 'c', None),
+        'Fortran': (sh.FortranSH, '!', None),
+        'Idl': (sh.IdlSH, ';', None),
+        'Diff': (sh.DiffSH, '', None),
+        'GetText': (sh.GetTextSH, '#', None),
+        'Nsis': (sh.NsisSH, '#', None),
+        'Html': (sh.HtmlSH, '', None),
+        'Yaml': (sh.YamlSH, '#', None),
+        'Cpp': (sh.CppSH, '//', None),
+        'OpenCL': (sh.OpenCLSH, '//', None),
+        'Enaml': (sh.EnamlSH, '#', PythonCFM),
+        'Markdown': (sh.MarkdownSH, '#', None),
+        # Every other language
+        'None': (sh.TextSH, '', None),
+    }
 
     TAB_ALWAYS_INDENTS = ('py', 'pyw', 'python', 'c', 'cpp', 'cl', 'h')
 
@@ -1552,8 +1555,9 @@ def set_highlight_current_cell(self, enable):
     def set_language(self, language, filename=None):
         self.tab_indents = language in self.TAB_ALWAYS_INDENTS
         self.comment_string = ''
-        sh_class = sh.TextSH
         self.language = 'Text'
+        sh_class = sh.TextSH
+        language = 'None' if language is None else language
         if language is not None:
             for (key, value) in ALL_LANGUAGES.items():
                 if language.lower() in value:
@@ -1569,11 +1573,13 @@ def set_language(self, language, filename=None):
                     else:
                         self.classfunc_match = CFMatch()
                     break
+
         if filename is not None and not self.supported_language:
             sh_class = sh.guess_pygments_highlighter(filename)
             self.support_language = sh_class is not sh.TextSH
             if self.support_language:
                 self.language = sh_class._lexer.name
+
         self._set_highlighter(sh_class)
         self.completion_widget.set_language(self.language)
 
diff --git a/spyder/utils/syntaxhighlighters.py b/spyder/utils/syntaxhighlighters.py
--- a/spyder/utils/syntaxhighlighters.py
+++ b/spyder/utils/syntaxhighlighters.py
@@ -358,9 +358,12 @@ def rehighlight(self):
 
 
 class TextSH(BaseSH):
-    """Simple Text Syntax Highlighter Class (only highlight spaces)"""
+    """Simple Text Syntax Highlighter Class (only highlight spaces)."""
+
     def highlight_block(self, text):
         """Implement highlight, only highlight spaces."""
+        text = to_text_string(text)
+        self.setFormat(0, qstring_length(text), self.formats["normal"])
         self.highlight_extras(text)
 
 


Test patch: