spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.28k stars 1.61k forks source link

Add a mechanism by which Spyder would detect a file's type #4643

Open stefanseefeld opened 7 years ago

stefanseefeld commented 7 years ago

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 ?

ccordoba12 commented 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):

seleccion_001

stefanseefeld commented 7 years ago

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.

ccordoba12 commented 7 years ago

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?

stefanseefeld commented 7 years ago

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.

goanpeca commented 7 years ago

We could use the pygments lexer detector?

rlaverde commented 7 years ago

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"