# Installing Edit Modes

The easiest way to install a new mode locally is to use the Editing dialog found under Utilities - Global Options. At the bottom of this dialog is an "Add Mode" button. Clicking this button shows a dialog to add a mode to jEdit. Simply fill in the blanks and the mode file will be put in the proper place and the catalog file will be updated appropriately. Modes added this way can be removed by selecting the mode in the Editing dialog, then clicking the "Delete Mode" button. This button will only appear for modes that exist in the user settings directory. Core modes, that is, those modes distributed with jEdit cannot be deleted this way. The details of adding a mode by hand are below.

jEdit looks for edit modes in two locations; the `modes` subdirectory of the jEdit settings directory, and the `modes` subdirectory of the jEdit install directory. The location of the settings directory is system-specific; see .

Each mode directory contains a `catalog` file. All edit modes contained in that directory must be listed in the catalog, otherwise they will not be available to jEdit.

Catalogs, like modes themselves, are written in XML. They consist of a single `MODES` tag, with a number of `MODE` tags inside. Each mode tag associates a mode name with an XML file, and specifies the file name and first line pattern for the mode. A sample mode catalog looks as follows:

    <?xml version="1.0"?>
    <!DOCTYPE CATALOG SYSTEM "catalog.dtd">

    <MODES>
        <MODE NAME="shellscript" FILE="shellscript.xml"
            FILE_NAME_GLOB="*.sh"
            FIRST_LINE_GLOB="#!/*sh*" />
    </MODES>

In the above example, a mode named shellscript is defined, and is used for files whose names end with `.sh`, or whose first line starts with #!/ and contains sh.

The `MODE` tag supports the following attributes:

- `NAME` - the name of the edit mode, as it will appear in the Buffer Options dialog box, the status bar, and so on.

- `FILE` - the name of the XML file containing the mode definition.

- `FILE_NAME_GLOB` - files whose names match this glob pattern will be opened in this edit mode. This can also specify full paths, if the glob pattern contains a path separator character. `FILE_NAME_GLOB` can be specified in the `modes/catalog` file, or the mode file itself. See the `FILE_NAME_GLOB` for `apacheconf.xml` in `modes/catalog` for an example of full path filename globbing.

- `FIRST_LINE_GLOB` - files whose first line matches this glob pattern will be opened in this edit mode.

Glob pattern syntax is described in .

If an edit mode in the user-specific catalog has the same name as an edit mode in the system catalog, the version in the user-specific catalog will override the system default.

When a buffer is opened, jEdit must choose an edit mode for that buffer. It checks conditions in this order to decide which edit mode to use:

1. the filename is an exact match for the `FILE_NAME_GLOB`.

2. the filename matches the `FILE_NAME_GLOB` and the first line of the file matches the `FIRST_LINE_GLOB`

3. the filename matches the `FILE_NAME_GLOB`

4. the first line of the file matches the `FIRST_LINE_GLOB`