6

I need to add a new language in Gedit. The problem is, it is included in Gedit menu of languages now, but its syntax is not highlighted and Gedit is not able to indentify the language just from the file suffix.

I've created both .lang file and a XML file describing MIME-TYPE.

LANG file - /usr/share/gtksourceview-3.0/language-specs/test.lang MIME-TYPE file - /usr/share/mime/packages/test.xml 

After creating them I've updated the mime database.

sudo update-mime-database /usr/share/mime 

Next attempts

1) I've tried even copying test.xml file to /usr/share/mime/applications folder instead of /usr/share/mime/packages, but it had no effect.

2) I've tried to put the mime type into the /etc/mime.types as

text/x-test test

and it had no effect too.


test.lang

<?xml version="1.0" encoding="UTF-8"?> <language id="test" _name="Test" version="1.0" _section="Source"> <metadata> <property name="mimetypes">text/x-test</property> <property name="globs">*.test</property> <property name="line-comment-start">//</property> <property name="block-comment-start">/*</property> <property name="block-comment-end">*/</property> </metadata> <styles> <style id="comment" _name="Comment" map-to="def:comment"/> <style id="keyword" _name="Keyword" map-to="def:keyword"/> </styles> <definitions> <context id="if0-comment" style-ref="comment"> <start>\%{preproc-start}if\b\s*0\b</start> <end>\%{preproc-start}(endif|else|elif)\b</end> <include> <context id="if-in-if0"> <start>\%{preproc-start}if(n?def)?\b</start> <end>\%{preproc-start}endif\b</end> <include> <context ref="if-in-if0"/> <context ref="def:in-comment"/> </include> </context> <context ref="def:in-comment"/> </include> </context> <context id="keywords" style-ref="keyword"> <keyword>hello</keyword> <keyword>hi</keyword> </context> <!--Main context--> <context id="test"> <include> <context ref="if0-comment"/> <context ref="keywords"/> </include> </context> </definitions> </language> 

test.xml

<?xml version="1.0" encoding="utf-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info" > <mime-type type="text/x-test"> <sub-class-of type="text/plain"/> <comment xml:lang="en">TEST language document</comment> <comment xml:lang="cs">Dokument v jazyce TEST</comment> <glob pattern="*.test"/> </mime-type> </mime-info> 
2
  • Your <definitions> block lacks the main <context id=test"> to start with. As per the docs - scroll down to <definitions>: Here we should define a main context, the one we enter at the beginning of the file[ ...] with an id equal to the id of the <language> element Commented Jul 2, 2015 at 17:30
  • @don_crissti I've added the main context, but the problem still lasts :-( Commented Jul 2, 2015 at 18:38

1 Answer 1

4

Finally I've figured it out. According to GTK lang reference version attribute in <language> tag should be 2.0. And it's really working.

So, the proper <language> tag is this:

<language id="test" _name="Test" version="2.0" _section="Source"> 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.