Open stefanseefeld opened 7 years ago
No, sorry, there's no way to make Spyder understand that a file is actually a Python script.
What if we add a menu entry that lets users select a given syntax for a file, as many other editors do? I mean, something like this (taken from Sublime):
Why not add a (configurable) mechanism by which spyder would detect a file's type (i.e., syntax) ? I've taken my example above from emacs, but there are obviously many more editors that do something similar. In any case, I agree that a mechanism to manually specify the syntax (including override any auto-detection) would be very useful.
there are obviously many more editors that do something similar.
The Emacs syntax is not a bad one, but I was not aware that other editors have a similar approach. Could you mention some other examples?
I know from experience that vi
also detects the above syntax.
Many editors have mechanisms to define new file types, or at least let uses associate filename extensions with file types (and thus editor modes), including eclipse, atom, etc.
I'm not sure how many editors (other than emacs and vi) detect file types based on content.
We could use the pygments lexer detector?
The languages configuration (that we're planing to introduce in spyder4) could have a field "first line", that will be a regex to detect the file based in the first line (like vscode do)
first_line = r"^#!/.*\\bpython[0-9.-]*\\b"
Is there a way to help spyder understand that a file (script) is in fact a python script, even if it doesn't use the usual '.py' extension and neither has the '#!' shebang magic ? For emacs I'm embedding a
# -*- python -*-
line, but that obviously isn't recognized by spyder. Is there any other mechanism I could use ?