back

Syntax Colors for Languages

Scribes uses GtkSourceView to provide syntax color for source code. In turn, GtkSourceView uses MIME type information to determine source code type, and descriptions in language files to color source code. This tutorial discusses how to add syntax color for languages in GtkSourceView.

MIME Type Information

GtkSourceView uses MIME type information to determine the type, or language, of a text file. MIME type information is stored in an XML file. The following is an example of a MIME type file, x-pyrex.xml, for Pyrex source code.

<?xml version="1.0" encoding="UTF-8"?>
	<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
		<mime-type type="text/x-pyrex">
			<sub-class-of type="text/plain"/>
			<comment>Pyrex Source Code</comment>
			<glob pattern="*.pxd"/>
			<glob pattern="*.pyx"/>
		</mime-type>
	</mime-info>
Place MIME type files at the following location.
${prefix}/share/mime/packages/
Finally, run the following command as root to update the MIME type database.
update-mime-database ${prefix}/share/mime/
${prefix} may be /usr, /usr/local, /opt depending on your system.

GtkSourceView Language File

A language file is an XML document that describes how to color source code. GtkSourceView language files are found at the following location.

${prefix}/share/gtksourceview-1.0/language-specs/
${prefix} may be /usr, /usr/local or /opt depending on your system. You can learn how to write language files by studying the ones found at the aforementioned location. After writing a language file, place it at the following location.
~/.gnome2/gtksourceview-1.0/language-specs/
At this point, Scribes should be able to show syntax colors for the new language.

One More Thing

After thorough testing, submit the new language file to the GtkSourceView bug reporting system for review and inclusion into the library. Submit your MIME type file to freedesktop.org for review and inclusion into the Shared MIME Information Specification library.

References:

  1. freedesktop.org MIME specification ( link )
  2. GtkSourceView Project ( link )
  3. GtkSourceView Wiki ( link )

back