I've attempted to create a new .lang
file for getting Gedit to recognize the Julia programming language. I have read the tutorial, the reference document and the wiki page Gedit/NewLanguage, and I believe the file to be correct. However, upon restarting gedit after copying the new julia.lang
file to /usr/share/gtksourceview-3.0/language-specs/
, a .jl file is indeed recognized and the syntax highlighting menu is set to julia, but no actual highlighting occurs.
Thinking that I might have done something wrong, I tried instead using an existent language file, for a similar language (Matlab), and only changed the header metadata into:
<language id="julia" _name="Julia" version="2.0" _section="Scientific">
<metadata>
<property name="mimetypes">text/x-julia;application/x-julia</property>
<property name="globs">*.jl</property>
<property name="line-comment-start">#</property>
</metadata>
Everything else was kept exactly as-is, and I saved the file as julia.lang
. Still, when reopening gedit the same issue occurs. What's more, if I select the Matlab entry from the syntax highlighting menu, the formatting is made correctly (according to Matlab rules), even though both matlab.lang
and julia.lang
have exactly the same syntax definitions!
What could I be doing wrong? This guy seemed to have the same problem, but it was never revealed in that thread how he solved it (if he ever did). Any ideas?
Update: my mistake was indeed not changing the context id as pointed out by @carandraug in his answer. I did, however, have other issues which I'll note here in case they're of help to anyone:
- I reused the "shell-like-comment" definition from
def.lang
for Julia's single-line comments, but that was getting me a lot of errors. It turns out when a reference context is used, theid
attribute cannot be set. Changing from<context id="comment" ref="def:shell-like-comment" />
to<context ref="def:shell-like-comment" />
made the errors go away. I think the reference document (and the tutorial as well) should mention this caveat. I've edited the wiki page to point this out. - Before I figured the problem with the comments context, I commented out its definition, but then I started getting a "style 'def:string' not defined" error. When I uncommented the definition, this error disappeared. I'm not sure what caused it in the first place (considering that indeed a
<style id="string">
was defined indef.lang
). Any clarifications about this are welcome in the comments :-)
A final suggestion to anyone developing new language highlight definitions for gedit: don't forget to run gedit from the command line and look at the console output!
I do not know why your original
julia.lang
file is not working since you're not showing the source, but the one you based onmatlab.lang
will not work because there's no context inside<definitions>
with the sameid
you mentioned for<language>
.Basically, you're saying the
id
of this language isjulia
, but there is no context with thatid
being defined. So find<context id="matlab"
(line 149 of the current HEAD), and change it tojulia
.A lang file is usually organized as a bunch of individual contexts for the language features being highlighted, which are then grouped in the end into a main block with the same
id
as the language, and references to the other contexts.