Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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">
    <property name="mimetypes">text/x-julia;application/x-julia</property>
    <property name="globs">*.jl</property>
    <property name="line-comment-start">#</property>

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:

  1. 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, the id 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.
  2. 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!

share|improve this question
1) I think it makes sense the way it. If you have a <context ref="">, then it's a reference you should not give it an ID. If for some reason you need to, then have a <context id=""> with an <include>. 2) there's a difference between context and style. If you are doing <context ref="" style="">, it assumes the first is a reference for another <context>, while the second is a reference to something defined on <styles>. A final suggestion would be tun run the script that is in the directory with the lang files. – carandraug May 15 '13 at 21:04
up vote 2 down vote accepted

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 on matlab.lang will not work because there's no context inside <definitions> with the same id you mentioned for <language>.

Basically, you're saying the id of this language is julia, but there is no context with that id being defined. So find <context id="matlab" (line 149 of the current HEAD), and change it to julia.

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.

share|improve this answer
Sorry, indeed that was the problem with the Matlab-derived version. I just noticed that by running gedit from the command line and googling the error message that came up, and found this. Changing the context works indeed, but now I have to back to my work computer to try the full definition I had devised earlier and see why it doesn't work. I'll keep you posted :) – waldyrious May 15 '13 at 11:57
Update: now got the original definition to work. Updated my question with the details. The initial problem (as described in the question) was indeed solved as you suggested, so I'll accept your answer. Thanks! – waldyrious May 15 '13 at 14:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.