[Solved] Trigger proper highlighting for files - seems impossible
-
I'm on Ubuntu, trying to edit /usr/bin/ecryptfs-setup-swap
Can anyone tell me how I can persuade Qt Creator to load this shell script file with the proper highlighting? I'm astonished at the massive fail in my first attempt to use the editor, and can't believe it's really that broken. It must be me, but I can't figure it out.
Opening the file notifies you that there's no highlighting been triggered, and helpfully invites you to visit a configuration pane (Tools>Options>Text Editor>Generic Highlighter) which can do nothing about it, which is frankly bizarre. I was expecting to be able to choose one of the highlighting schemes and deal with it manually, but this is not provided.
From trying many different things, I've come to the conclusion that it's actually impossible to associate the proper highlighting because of the series of counterintuitive interfaces and broken assumptions built into the highlighting UI, in particular; i) a fixed list of MIME types, ii) the assumption that file suffixes will indicate file type and iii) the absence of an association between MIME type and Kate highlighting config in the UI
On my system...
$ file --mime /usr/bin/ecryptfs-setup-swap
/usr/bin/ecryptfs-setup-swap: text/x-shellscript; charset=us-ascii...but Qt Creator only acknowledges a MIME type of application/x-shellscript not text/x-shellscript and it's impossible to edit its list of MIME types.
So in summary, the Bash highlighting rules seem to be downloaded and visible in the highlighting config directory, but there's no configuration either on a global or a per-editor-pane basis which seems to associate that highlighting logic with the file /usr/bin/ecryptfs-setup-swap
-
OK, instantly I post it I find a solution. It seems that the checkbox "Use fallback location" needs to be unchecked to get the downloaded Kate files in the configured /home/user/.config/Nokia/qtcreator/generic-highlighter to be considered.
When have "Use fallback location" selected, it doesn't mean that it will use the location as a fallback (when a match isn't found).
Instead, it's just a second box which you can type a path in, and the checkbox means "use this path instead". In my case, so long as this was checked, highlighting was non-functional.
-
I should provide a little more detail for others struggling with similar issues. The workaround I adopted was to add a "magic header" entry to the MIME type application/x-shellscript within the Tools>Options>Environment>MIME Types so that wherever...
#!/bin/sh
...appears in the first few characters of a file, then Qt Creator considers the file to be application/x-shellscript.
N.B. as detailed in the previous post, if you leave "Use fallback location" selected, then highlighting fails, and there's no way to manually associate a file with a highlighting scheme to get over these issues in automated loading.