MacRabbit

LanguagesXML

LanguageSugars need a Languages.xml file in their root Sugar folder. This file defines the rules used to detect what syntax should be used for any given document.

Here is a simple example file using the markup language Textile as an example:

<?xml version="1.0" encoding="UTF-8"?>
<settings>

    <
language id="com.yourdomain.textile">
        <!-- 
Define what syntax this language should use;
              use 
the name of the syntax you define in Syntaxes -->
        <
root-zone>language-root.textile</root-zone>

        <!-- 
Human readable name for the language -->
        <
name>Textile</name>

        <!-- 
Ways to detect the language (see next section) -->
        <
detectors>
            <
extension>textile</extension>
        </
detectors>
        
        <!-- 
Only necessary if you support multiple extensions -->
        <default-
extension>textile</default-extension>
    </
language>
    
</
settings

You can include more than one <language> definition within a single Languages.xml file. See the bundled Ruby.sugar for an example (it defines support for both normal Ruby and ERB template files).

Detectors

Although most of the elements in Languages.xml should be self-explanatory, you can use several different types of detectors to inform Espresso which files belong to your syntax.

Extension detector

This detector defines a single extension that activates the language. You can include as many <extension> elements within the <detectors> element as you need.

<extension>html</extension

Filename detector

This detector defines an entire filename that activates the language. This is useful for special files like .htaccess, Makefile, etc. There is an optional attribute that allows you to make it case sensitive (default is case insensitive).

<filename casesensitive="true">Makefile</filename

Content matching detector

This detector actually inspects the contents of the file. The optional lines attribute specifies how many lines of the file have to be loaded to inspect the content. The value of this tag is a regular expression, so you are not limited to fixed values.

<match-content lines="2"><![CDATA[(?i)<!DOCTYPE html]]></match-content

Combo detector

Finally, you may only wish to apply a language when a combination of detectors have a positive result. This is possible with the <combo> tag. For example:

<combo>
    <
extension>php</extension>
    <
match-content lines="2"><![CDATA[(?i)<!DOCTYPE html]]></match-content>
</
combo