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
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.langfor Julia's single-line comments, but that was getting me a lot of errors. It turns out when a reference context is used, the
idattribute 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 in
def.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!