Bug 396195 - Should use shebang to decide which language the file is
Summary: Should use shebang to decide which language the file is
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: All editors (show other bugs)
Version: 5.2.3
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-05 09:56 UTC by Salvo "LtWorf" Tomaselli
Modified: 2020-08-24 09:52 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.