Bug 396195

Summary: Should use shebang to decide which language the file is
Product: [Applications] kdevelop Reporter: Salvo "LtWorf" Tomaselli <tiposchi>
Component: All editorsAssignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: normal CC: mail, mail
Priority: NOR    
Version First Reported In: 5.2.3   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Salvo "LtWorf" Tomaselli 2018-07-05 09:56:54 UTC
For bash or python files, that do not end in ".py" or ".sh", kdevelop doesn't know what they are, even if they begin with a thing like: #!/usr/bin/env python3


So, they should be autodetected instead.

Also, if I manually set something, it should be stored in the project file and remembered for the next time, instead of me needing to do it every single time I edit the file.
Comment 1 Sven Brauch 2018-07-05 10:19:11 UTC
Can you not set a proper mime type for the files in your system's mime database?
Comment 2 Salvo "LtWorf" Tomaselli 2018-07-05 12:11:41 UTC
$ file /tmp/pythonscript
/tmp/pythonscript: Python script, ASCII text executable
$ file --mime /tmp/pythonscript
/tmp/pythonscript: text/x-python; charset=us-ascii


What is there to set?
Comment 3 Francis Herne 2018-07-05 14:41:18 UTC
I did some brief testing on my Arch system with KDev* master, using a file named `no_suffix` having the contents
```
#!/usr/bin/env python3
print("Hello, world!")
```

Mime tools detect it:

$ file --mime no_suffix
no_suffix: text/x-python; charset=us-ascii

$ kmimetypefinder5 no_suffix
text/x-python3

KWrite *doesn't* detect it - the default ksyntaxhighlighting and indentation are 'None' and 'Normal' respectively. Both of these work fine if explicitly enabled.

Using KDevelop, it *does* get assigned to and recognised by kdev-python - there are tooltips, semantic highlighting etc. - but the ktexteditor highlighting/indenter still aren't used by default.

KDevelop uses either the default text-file icon or a '[?]' icon in the Projects/Filesystem toolviews, open-files menu etc., not the Python icon.
Comment 4 Francis Herne 2018-07-06 16:43:40 UTC
Changing the shebang to `... python or `... python2` fixes the ksyntaxhighlighting detection in KWrite (but not KDevelop).

With `...python3`, the detected mimetype is 'text/x-python3'; ksyntaxhighlighting doesn't understand `<sub-class-of type='text/x-python'/>` in the mime database and it's not listed explicitly in python.xml

I don't yet understand why KDevelop behaves differently.
Comment 5 Francis Herne 2020-08-24 09:52:45 UTC
This has been fixed at some point. KDevelop and other KTextEditor-based applications now detect such files.