On 4/12/25 5:16 PM, David C. Rankin via tde-users wrote:
katepart/syntax isn't as brilliant as we would
like. Most of the time
is keys off the file extension and MIME types rather than parsing and
looking for the command interpreter.
If you go to kate Settings->Editor->highlighting, you can use the
drop down to select the highlighting you want and make sure the
extension you are using is listing and the MIME type is correct
x-shellscript.
You can create custom entries in the extension box. For example,
Archlinux PKGBUILD files should be shown as bash scripts and highlighted
accordingly. I've added "PKGBUILD*" to catch the name with any text
following it (like if I add a "PKBBUILD-ver-1")
But beyond that, I don't believe the syntax used is saved as part of
the metadata that contains info like the active line being edited, etc..
Thanks David. You provided some information to think about.
File extensions seems an odd way to determine content, at least in the
Linux world where file type detection notoriously is not based on
extensions. Regardless, your example indicates the word "extension" is
nominally misleading and any kind of file type string can be used.
I rarely use an "sh" file extension in my shell scripts. From years of
observation, using the "sh" extension is unlikely to be used with many
distro system shell scripts.
I looked in my Kate metainfos file. The highlighting information is
saved in that file. Once I "instruct" Kate to use the correct file type
highlighting, that information is saved.
The Kate Handbook touches upon the topic but provides no in depth
details. I agree with you there is no meaningful detection algorithm. I
found information online about KDE 5 Kate and looks like those
developers have addressed the issue with some detection mechanisms. This
all seems odd when the file command provides such information.
Curiously there is some kind of detection taking place in TDE Kate. I
opened a shell script and Kate correctly selected Bash highlighting. I
changed the declaration to /bin/perl. Nothing happened but when I saved
the file Kate changed the highlighting to perl. Curiouser and curiouser
is when I did likewise to /bin/python, Kate retained the perl
highlighting. Returning the declaration to /bin/bash and saving saw Kate
return the highlighting to Bash.
The existence of the metainfos files might be a clue from years ago the
original developers did not have a useful or dependable detection
scheme. This is alluded to in the KDE 5 documentation mentioned above.
Confusing me is my original point. Some of the files I open are obvious
shell scripts with /bin/bash|sh in the declaration. If the existing TDE,
nee old KDE, detection scheme uses mimetypes, something like the file
command, then how does this detection fail with obvious shell scripts?