Ive downloaded a set of wiki source files, which end in .mediawiki. The editor that gives me the interface I like best is gedit with document type “MediaWiki”.
However I have to change the document type with every single new file ! After I reopen the same file, the document type is set like I selected it, fortunately. But I have several dozens of files and I’m not going to change the document type with every single one of them…
Is there a way to have gedit permanently “remember” all files ending in .mediawiki are of type “MediaWiki” ?
Thanks in advance for any hint/suggestion.
EDIT: I forgot to add (if that helps) I’m using Xfce as my desktop environment.
It’s okay. I’ve seen from the “Default applications” dialogue there’s a text/markdown document type but the thing is it’s also tied to gedit. If there’s a way to create a new MIME type, e.g. x-application/mediawiki, would gedit switch to the adequate syntax colouring scheme?
EDIT: Tried that. Failed
The custom MIME type is indeed registered and shows up with xdg-mime query filetype and as expected gedit opens when summoned with xdg-open <mediawiki file>. But syntax colouring always defaults to text/plain… *sighs*
Here’s the descriptor I added to .local/share/mime/packages:
Well, I closed my session (after making sure I’d set up my local MIME database correctly, which I did in the end) aaaaand… no luck. Still doesn’t work and gedit, just like mousepad would default to `text/plain
Here’s a sample contents from the database I downloaded (it’s from SDL2):
= SDL_LogMessage =
Log a message with the specified category and priority.
== Syntax ==
<syntaxhighlight lang='c'>
void SDL_LogMessage(int category,
SDL_LogPriority priority,
SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
</syntaxhighlight>
== Function Parameters ==
{|
|'''category'''
|the category of the message
|-
|'''priority'''
|the priority of the message
|-
|'''fmt'''
|a printf() style message format string
|-
|'''...'''
|additional parameters matching % tokens in the '''fmt''' string, if any
|}
== Version ==
This function is available since SDL 2.0.0.
== Related Functions ==
:[[SDL_Log]]
:[[SDL_LogCritical]]
:[[SDL_LogDebug]]
:[[SDL_LogError]]
:[[SDL_LogInfo]]
:[[SDL_LogMessageV]]
:[[SDL_LogVerbose]]
:[[SDL_LogWarn]]
----
[[CategoryAPI]], [[CategoryLog]]
However, after opening that same file with Gedit (fresh install) and setting it to MediaWiki… closing it out, reloading it also comes back:
It does indeed. However it doesn’t switch to Mediawiki colour mode/syntax when opening files it hasn’t seen yet, which is the burden I’d like to avoid. I have no idea why gedit (as well as mousepad, by the looks of it) makes the association on a per-file basis instead of per-extension. That’s beyond me.
EDIT: From that comment on Ubuntu Stack Exchange, both editors are would be based on gtksourceview, so I’ll try fiddling with its language descriptor files and see what happens…
EDIT: contrary to what I (and said comment) expressed gedit is not based upon the system package gtksourceview but uses its own spin, namely libgedit-gtksourceview-300… Investigating further indeed…
So I copied that file to .local/share/libgedit-gtksourceview-300/language-specs and added the following two lines to the <metadata> tag (first tag in the file):
Then I closed gedit and opened a mediawiki file that I never opened yet and *bam* syntax colouring was set to “MediaWiki”!
Problem solved
BTW I also symlinked that language file to .local/share/gtksourceview-3.0/language-specs/ and .local/share/gtksourceview-4/language-specs/, since these are the ones that are installed on my system. Now any editor based on either of these three libraries will (hopefully) change to the appropriate syntax.
Also note that creating a new MIME type may be optional, since the language “globs” the “mediawiki” extension besides the dedicated MIME type. I won’t test without though…